Skip to content

Commit f9fd733

Browse files
author
Tyler Smalley
authored
Jest multi-project configuration (#77894) (#84826)
Signed-off-by: Tyler Smalley <[email protected]> # Conflicts: # src/dev/code_coverage/ingest_coverage/integration_tests/team_assignment.test.js # src/plugins/console/jest.config.js # x-pack/plugins/canvas/scripts/jest.js
1 parent efeb071 commit f9fd733

File tree

176 files changed

+2921
-7680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+2921
-7680
lines changed

docs/developer/contributing/development-unit-tests.asciidoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ yarn test:mocha
2020
== Jest
2121
Jest tests are stored in the same directory as source code files with the `.test.{js,mjs,ts,tsx}` suffix.
2222

23-
*Running Jest Unit Tests*
23+
Each plugin and package contains it's own `jest.config.js` file to define its root, and any overrides
24+
to the jest-preset provided by `@kbn/test`. When working on a single plugin or package, you will find
25+
it's more efficient to supply the Jest configuration file when running.
2426

2527
["source","shell"]
2628
-----------
27-
yarn test:jest
29+
yarn jest --config src/plugins/discover/jest.config.js
2830
-----------
2931

3032
[discrete]

src/dev/jest/config.integration.js renamed to jest.config.integration.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717
* under the License.
1818
*/
1919

20-
import preset from '@kbn/test/jest-preset';
21-
import config from './config';
20+
const preset = require('@kbn/test/jest-preset');
2221

23-
export default {
24-
...config,
25-
testMatch: [
26-
'**/integration_tests/**/*.test.js',
27-
'**/integration_tests/**/*.test.ts',
28-
'**/integration_tests/**/*.test.tsx',
29-
],
22+
module.exports = {
23+
preset: '@kbn/test',
24+
rootDir: '.',
25+
roots: ['<rootDir>/src', '<rootDir>/packages'],
26+
testMatch: ['**/integration_tests**/*.test.{js,mjs,ts,tsx}'],
27+
testRunner: 'jasmine2',
3028
testPathIgnorePatterns: preset.testPathIgnorePatterns.filter(
3129
(pattern) => !pattern.includes('integration_tests')
3230
),

jest.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
module.exports = {
21+
rootDir: '.',
22+
projects: [...require('./jest.config.oss').projects, ...require('./x-pack/jest.config').projects],
23+
};

jest.config.oss.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
module.exports = {
21+
rootDir: '.',
22+
projects: [
23+
'<rootDir>/packages/*/jest.config.js',
24+
'<rootDir>/src/*/jest.config.js',
25+
'<rootDir>/src/legacy/*/jest.config.js',
26+
'<rootDir>/src/plugins/*/jest.config.js',
27+
'<rootDir>/test/*/jest.config.js',
28+
],
29+
reporters: ['default', '<rootDir>/packages/kbn-test/target/jest/junit_reporter'],
30+
};

packages/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ A package can also follow the pattern of having `.test.js` files as siblings of
6060
A package using the `.test.js` naming convention will have those tests automatically picked up by Jest and run by the unit test runner, currently mapped to the Kibana `test` script in the root `package.json`.
6161

6262
* `yarn test` or `yarn grunt test` runs all unit tests.
63-
* `node scripts/jest` runs all Jest tests in Kibana.
63+
* `yarn jest` runs all Jest tests in Kibana.
6464

6565
----
6666
Each package can also specify its own `test` script in the package's `package.json`, for cases where you'd prefer to run the tests from the local package directory.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
module.exports = {
21+
preset: '@kbn/test',
22+
rootDir: '../..',
23+
roots: ['<rootDir>/packages/kbn-apm-config-loader'],
24+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
module.exports = {
21+
preset: '@kbn/test',
22+
rootDir: '../..',
23+
roots: ['<rootDir>/packages/kbn-babel-code-parser'],
24+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
module.exports = {
21+
preset: '@kbn/test',
22+
rootDir: '../..',
23+
roots: ['<rootDir>/packages/kbn-config-schema'],
24+
};

packages/kbn-config/jest.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
module.exports = {
21+
preset: '@kbn/test',
22+
rootDir: '../..',
23+
roots: ['<rootDir>/packages/kbn-config'],
24+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
module.exports = {
21+
preset: '@kbn/test',
22+
rootDir: '../..',
23+
roots: ['<rootDir>/packages/kbn-dev-utils'],
24+
};

0 commit comments

Comments
 (0)