[jest] update config files to get coverage per plugin (#111299)

* [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 <lukeelmers@gmail.com>

* Update src/plugins/telemetry_management_section/jest.config.js

Co-authored-by: Luke Elmers <lukeelmers@gmail.com>

* [kibana_legacy] fix path

Co-authored-by: Luke Elmers <lukeelmers@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Dzmitry Lemechko 2021-09-09 08:14:56 +02:00 committed by GitHub
parent c4c653606a
commit b324ca3115
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
128 changed files with 527 additions and 2 deletions

View file

@ -32,6 +32,7 @@ plugins/
plugin.ts
common
index.ts
jest.config.js
```
### kibana.json
@ -209,6 +210,29 @@ considerations related to how plugins integrate with core APIs and APIs exposed
`common/index.ts` is the entry-point into code that can be used both server-side or client side.
### jest.config.js
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.
```js
module.exports = {
// Default Jest settings, defined in kbn-test package
preset: '@kbn/test',
// The root of the directory containing package.json
rootDir: '../../..',
// The directory which Jest should use to search for files in
roots: ['<rootDir>/src/plugins/demo'],
// The directory where Jest should output plugin coverage details, e.g. html report
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/demo',
// A list of reporter names that Jest uses when writing coverage reports, default: ["json"]
// "text" is available in console and is good for quick check
// "html" helps to dig into specific files and fix coverage
coverageReporters: ['text', 'html'],
// An array of regexp pattern strings that matched files to include/exclude for code coverage
collectCoverageFrom: ['<rootDir>/src/plugins/demo/{common,public,server}/**/*.{ts,tsx}'],
};
```
## How plugin's interact with each other, and Core
The lifecycle-specific contracts exposed by core services are always passed as the first argument to the equivalent lifecycle function in a plugin.