Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APM-specific Jest configuration #67858

Merged
merged 2 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions x-pack/dev-tools/jest/create_jest_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

export function createJestConfig({ kibanaDirectory, xPackKibanaDirectory }) {
export function createJestConfig({ kibanaDirectory, rootDir, xPackKibanaDirectory }) {
const fileMockPath = `${kibanaDirectory}/src/dev/jest/mocks/file_mock.js`;
return {
rootDir: xPackKibanaDirectory,
rootDir,
roots: ['<rootDir>/plugins', '<rootDir>/legacy/plugins', '<rootDir>/legacy/server'],
moduleFileExtensions: ['js', 'json', 'ts', 'tsx'],
moduleNameMapper: {
Expand Down Expand Up @@ -44,15 +44,15 @@ export function createJestConfig({ kibanaDirectory, xPackKibanaDirectory }) {
'!**/plugins/apm/e2e/**',
],
coveragePathIgnorePatterns: ['.*\\.d\\.ts'],
coverageDirectory: '<rootDir>/../target/kibana-coverage/jest',
coverageDirectory: `${kibanaDirectory}/target/kibana-coverage/jest`,
coverageReporters: !!process.env.CODE_COVERAGE ? ['json'] : ['html'],
setupFiles: [
`${kibanaDirectory}/src/dev/jest/setup/babel_polyfill.js`,
`<rootDir>/dev-tools/jest/setup/polyfills.js`,
`<rootDir>/dev-tools/jest/setup/enzyme.js`,
`${xPackKibanaDirectory}/dev-tools/jest/setup/polyfills.js`,
`${xPackKibanaDirectory}/dev-tools/jest/setup/enzyme.js`,
],
setupFilesAfterEnv: [
`<rootDir>/dev-tools/jest/setup/setup_test.js`,
`${xPackKibanaDirectory}/dev-tools/jest/setup/setup_test.js`,
`${kibanaDirectory}/src/dev/jest/setup/mocks.js`,
`${kibanaDirectory}/src/dev/jest/setup/react_testing_library.js`,
],
Expand Down
1 change: 1 addition & 0 deletions x-pack/dev-tools/jest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function runJest() {
const config = JSON.stringify(
createJestConfig({
kibanaDirectory: resolve(__dirname, '../../..'),
rootDir: resolve(__dirname, '../..'),
xPackKibanaDirectory: resolve(__dirname, '../..'),
})
);
Expand Down
28 changes: 9 additions & 19 deletions x-pack/plugins/apm/dev_docs/vscode_setup.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### Visual Studio Code
# Visual Studio Code

When using [Visual Studio Code](https://code.visualstudio.com/) with APM it's best to set up a [multi-root workspace](https://code.visualstudio.com/docs/editor/multi-root-workspaces) and add the `x-pack/plugins/apm` directory, the `x-pack` directory, and the root of the Kibana repository to the workspace. This makes it so you can navigate and search within APM and use the wider workspace roots when you need to widen your search.

#### Using the Jest extension
## Using the Jest extension

The [vscode-jest extension](https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest) is a good way to run your Jest tests inside the editor.

Expand All @@ -22,31 +22,21 @@ If you have a workspace configured as described above you should have:
"jest.disabledWorkspaceFolders": ["kibana", "x-pack"]
```

in your Workspace settings, and:

```json
"jest.pathToJest": "node scripts/jest.js --testPathPattern=plugins/apm",
"jest.rootPath": "../../.."
```

in the settings for the APM folder.

#### Jest debugging
## Jest debugging

To make the [VSCode debugger](https://vscode.readthedocs.io/en/latest/editor/debugging/) work with Jest (you can set breakpoints in the code and tests and use the VSCode debugger) you'll need the [Node Debug extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.node-debug2) installed and can set up a launch configuration like:

```json
{
"type": "node",
"name": "APM Jest",
"name": "vscode-jest-tests",
"request": "launch",
"args": ["--runInBand", "--testPathPattern=plugins/apm"],
"cwd": "${workspaceFolder}/../../..",
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/../../../scripts/jest.js",
"runtimeVersion": "10.15.2"
"program": "${workspaceFolder}/../../../node_modules/jest/bin/jest"
}
```

Expand Down
44 changes: 44 additions & 0 deletions x-pack/plugins/apm/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// This is an APM-specific Jest configuration which overrides the x-pack
// configuration. It's intended for use in development and does not run in CI,
// which runs the entire x-pack suite. Run `npx jest`.

require('../../../src/setup_node_env');

const { createJestConfig } = require('../../dev-tools/jest/create_jest_config');
const { resolve } = require('path');

const rootDir = resolve(__dirname, '.');
const xPackKibanaDirectory = resolve(__dirname, '../..');
const kibanaDirectory = resolve(__dirname, '../../..');

const jestConfig = createJestConfig({
kibanaDirectory,
rootDir,
xPackKibanaDirectory,
});

module.exports = {
...jestConfig,
reporters: ['default'],
roots: [`${rootDir}/common`, `${rootDir}/public`, `${rootDir}/server`],
collectCoverage: true,
collectCoverageFrom: [
'**/*.{js,jsx,ts,tsx}',
'!**/{__test__,__snapshots__,__examples__,integration_tests,tests}/**',
'!**/*.test.{js,ts,tsx}',
'!**/dev_docs/**',
'!**/e2e/**',
'!**/scripts/**',
'!**/target/**',
'!**/typings/**',
'!**/mocks/**',
],
coverageDirectory: `${rootDir}/target/coverage/jest`,
coverageReporters: ['html'],
};
14 changes: 11 additions & 3 deletions x-pack/plugins/apm/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,26 @@ _Starts Kibana (:5701), APM Server (:8201) and Elasticsearch (:9201). Ingests sa

### Unit testing

Note: Run the following commands from `kibana/x-pack`.
Note: Run the following commands from `kibana/x-pack/plugins/apm`.

#### Run unit tests

```
node scripts/jest.js plugins/apm --watch
npx jest --watch
```

#### Update snapshots

```
node scripts/jest.js plugins/apm --updateSnapshot
npx jest --updateSnapshot
```

#### Coverage

HTML coverage report can be found in target/coverage/jest after tests have run.

```
open target/coverage/jest/index.html
```

### Functional tests
Expand Down