kibana/x-pack/plugins/apm/dev_docs/vscode_setup.md
Nathan L Smith 78d5026fbd
APM-specific Jest configuration (#67858)
Update the x-pack `createJestConfig` function to take the `rootDir` as an argument, which allows for easier overriding of the Jest configuration for a specific directory.

Previously we would run Jest in development from the x-pack directory by running something like:

```
node scripts/jest.js --testPathPattern=plugins/apm --watch
```

Currently (for me anyway) this is failing with:

```
Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:123:28)
```

and it would sometimes not correctly test only the changed files when a change in APM was made. It was also difficult to configure correctly with the [VSCode Jest extension](https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest).

Add a jest.config.js for APM. This makes running with `--watch` better about which files it chooses to re-run and makes the VSCode extension work (including coverage mapping) with minimal configuration.
2020-06-01 20:38:53 -05:00

2.1 KiB
Raw Blame History

Visual Studio Code

When using Visual Studio Code with APM it's best to set up a multi-root workspace 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

The vscode-jest extension is a good way to run your Jest tests inside the editor.

Some of the benefits of using the extension over just running it in a terminal are:

• It shows the pass/fail of a test inline in the test file • It shows the error message in the test file if it fails • You dont have to have the terminal process running • It can automatically update your snapshots when they change • Coverage mapping

The extension doesn't really work well if you're trying to use it on all of Kibana or all of X-Pack, but it works well if you configure it to run only on the files in APM.

If you have a workspace configured as described above you should have:

"jest.disabledWorkspaceFolders": ["kibana", "x-pack"]

Jest debugging

To make the VSCode debugger work with Jest (you can set breakpoints in the code and tests and use the VSCode debugger) you'll need the Node Debug extension installed and can set up a launch configuration like:

{
  "type": "node",
  "name": "vscode-jest-tests",
  "request": "launch",
  "args": ["--runInBand"],
  "cwd": "${workspaceFolder}",
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen",
  "disableOptimisticBPs": true,
  "program": "${workspaceFolder}/../../../node_modules/jest/bin/jest"
}

(you'll want runtimeVersion to match what's in the Kibana root .nvmrc. Depending on your setup, you might be able to remove this line.)