Skip to content

Commit 8dd4f49

Browse files
dmlemeshkolukeelmerskibanamachine
authored
[jest] update config files to get coverage per plugin (#111299) (#111674)
* [jest] update config files to get coverage per plugin * [docs] add details about plugin coverage collection * fix path for newsfeed jest config * fix lint error * update documentation * fix lint errors again * update doc * fix another lint error * Update src/plugins/telemetry_management_section/jest.config.js Co-authored-by: Luke Elmers <[email protected]> * Update src/plugins/telemetry_management_section/jest.config.js Co-authored-by: Luke Elmers <[email protected]> * [kibana_legacy] fix path Co-authored-by: Luke Elmers <[email protected]> Co-authored-by: Kibana Machine <[email protected]> # Conflicts: # packages/kbn-ui-framework/README.md # src/plugins/legacy_export/jest.config.js
1 parent a3792d6 commit 8dd4f49

File tree

128 files changed

+525
-2
lines changed

Some content is hidden

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

128 files changed

+525
-2
lines changed

dev_docs/key_concepts/anatomy_of_a_plugin.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ plugins/
3232
plugin.ts
3333
common
3434
index.ts
35+
jest.config.js
3536
```
3637

3738
### kibana.json
@@ -209,6 +210,29 @@ considerations related to how plugins integrate with core APIs and APIs exposed
209210

210211
`common/index.ts` is the entry-point into code that can be used both server-side or client side.
211212

213+
### jest.config.js
214+
215+
If you are adding unit tests (which we recommend), you will need to add a `jest.config.js` file. Here is an example file that you would use if adding a plugin into the `examples` directory.
216+
217+
```js
218+
module.exports = {
219+
// Default Jest settings, defined in kbn-test package
220+
preset: '@kbn/test',
221+
// The root of the directory containing package.json
222+
rootDir: '../../..',
223+
// The directory which Jest should use to search for files in
224+
roots: ['<rootDir>/src/plugins/demo'],
225+
// The directory where Jest should output plugin coverage details, e.g. html report
226+
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/demo',
227+
// A list of reporter names that Jest uses when writing coverage reports, default: ["json"]
228+
// "text" is available in console and is good for quick check
229+
// "html" helps to dig into specific files and fix coverage
230+
coverageReporters: ['text', 'html'],
231+
// An array of regexp pattern strings that matched files to include/exclude for code coverage
232+
collectCoverageFrom: ['<rootDir>/src/plugins/demo/{common,public,server}/**/*.{ts,tsx}'],
233+
};
234+
```
235+
212236
## How plugin's interact with each other, and Core
213237

214238
The lifecycle-specific contracts exposed by core services are always passed as the first argument to the equivalent lifecycle function in a plugin.

dev_docs/tutorials/testing_plugins.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,17 @@ describe('Case migrations v7.7.0 -> v7.8.0', () => {
928928
});
929929
```
930930
931+
You can generate code coverage report for a single plugin.
932+
933+
```bash
934+
yarn jest --coverage --config src/plugins/console/jest.config.js
935+
```
936+
937+
Html report should be available in `target/kibana-coverage/jest/src/plugins/console` path
938+
939+
We run code coverage daily on CI and ["Kibana Stats cluster"](https://kibana-stats.elastic.dev/s/code-coverage/app/home)
940+
can be used to view statistics. The report combines code coverage for all jest tests within Kibana repository.
941+
931942
#### Integration testing
932943
With more complicated migrations, the behavior of the migration may be dependent on values from other plugins which may
933944
be difficult or even impossible to test with unit tests. You need to actually bootstrap Kibana, load the plugins, and

docs/developer/contributing/development-tests.asciidoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ kibana/src/plugins/dashboard/server$ yarn test:jest --coverage
5656
yarn jest --coverage --verbose --config /home/tyler/elastic/kibana/src/plugins/dashboard/jest.config.js server
5757
----
5858

59+
You can generate code coverage report for a single plugin.
60+
61+
[source,bash]
62+
----
63+
yarn jest --coverage --config src/plugins/console/jest.config.js
64+
----
65+
66+
Html report is available in target/kibana-coverage/jest/path/to/plugin
5967

6068
[discrete]
6169
=== Running browser automation tests

packages/kbn-ui-framework/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ You can run `node scripts/jest --watch` to watch for changes and run the tests a
1919
You can run `node scripts/jest --coverage` to generate a code coverage report to see how
2020
fully-tested the code is.
2121

22+
You can run `node scripts/jest --config path/to/plugin/jest.config.js --coverage` to generate
23+
a code coverage report for a single plugin.
24+
2225
See the documentation in [`scripts/jest.js`](../scripts/jest.js) for more options.
2326

2427
## Creating components

src/plugins/advanced_settings/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ module.exports = {
1010
preset: '@kbn/test',
1111
rootDir: '../../..',
1212
roots: ['<rootDir>/src/plugins/advanced_settings'],
13+
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/advanced_settings',
14+
coverageReporters: ['text', 'html'],
15+
collectCoverageFrom: ['<rootDir>/src/plugins/advanced_settings/{public,server}/**/*.{ts,tsx}'],
1316
};

src/plugins/bfetch/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ module.exports = {
1010
preset: '@kbn/test',
1111
rootDir: '../../..',
1212
roots: ['<rootDir>/src/plugins/bfetch'],
13+
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/bfetch',
14+
coverageReporters: ['text', 'html'],
15+
collectCoverageFrom: ['<rootDir>/src/plugins/bfetch/{common,public,server}/**/*.{ts,tsx}'],
1316
};

src/plugins/chart_expressions/expression_tagcloud/jest.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ module.exports = {
1010
preset: '@kbn/test',
1111
rootDir: '../../../../',
1212
roots: ['<rootDir>/src/plugins/chart_expressions/expression_tagcloud'],
13+
coverageDirectory:
14+
'<rootDir>/target/kibana-coverage/jest/src/plugins/chart_expressions/expression_tagcloud',
15+
coverageReporters: ['text', 'html'],
16+
collectCoverageFrom: [
17+
'<rootDir>/src/plugins/chart_expressions/expression_tagcloud/{common,public,server}/**/*.{ts,tsx}',
18+
],
1319
};

src/plugins/charts/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ module.exports = {
1010
preset: '@kbn/test',
1111
rootDir: '../../..',
1212
roots: ['<rootDir>/src/plugins/charts'],
13+
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/charts',
14+
coverageReporters: ['text', 'html'],
15+
collectCoverageFrom: ['<rootDir>/src/plugins/charts/{common,public,server}/**/*.{ts,tsx}'],
1316
};

src/plugins/console/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ module.exports = {
1111
rootDir: '../../..',
1212
roots: ['<rootDir>/src/plugins/console'],
1313
testRunner: 'jasmine2',
14+
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/console',
15+
coverageReporters: ['text', 'html'],
16+
collectCoverageFrom: ['<rootDir>/src/plugins/console/{common,public,server}/**/*.{js,ts,tsx}'],
1417
};

src/plugins/dashboard/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ module.exports = {
1111
rootDir: '../../..',
1212
roots: ['<rootDir>/src/plugins/dashboard'],
1313
testRunner: 'jasmine2',
14+
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/dashboard',
15+
coverageReporters: ['text', 'html'],
16+
collectCoverageFrom: ['<rootDir>/src/plugins/dashboard/{common,public,server}/**/*.{ts,tsx}'],
1417
};

0 commit comments

Comments
 (0)