Simple way to run or debug a single or multiple Jest-Tests from context menu.
As it is possible in IntelliJ / Webstorm
Run your Jest Tests from context-menu
- right click your test and select Run Jest from context menu
- to run a test in debug mode use Debug Jest
- run previous test from command palette (strg+shift+p)
- supports yarn & vscode workspaces (monorepo)
- works with CRA & react-scripts!
add this to settings.json
"jestrunner.jestCommand": "npm run test --"
Jest Runner will work out of the box, with a valid Jest config.
If you have a custom setup use the following options to configure Jest Runner:
Command | Description |
---|---|
jestrunner.configPath | Jest config path (relative to ${workFolder} e.g. jest-config.json) |
jestrunner.jestPath | Absolute path to jest bin file (e.g. /usr/lib/node_modules/jest/bin/jest.js) |
jestrunner.debugOptions | Add or overwrite vscode debug configurations (only in debug mode) (e.g. "jestrunner.debugOptions": { "args": ["--no-cache"] } ) |
jestrunner.runOptions | Add CLI Options to the Jest Command (e.g. "jestrunner.runOptions": ["--coverage", "--colors"] ) https://jestjs.io/docs/en/cli |
jestrunner.jestCommand | Define an alternative Jest command (e.g. for Create React App and similar abstractions) |
click File -> Preferences -> Keyboard Shortcuts -> "{}" (top right) the json config file will open add this:
{
"key": "alt+1",
"command": "extension.runJest"
},
{
"key": "alt+2",
"command": "extension.debugJest"
},
Some open topics get you started
-
By default Jest finds its config from the
"jest"
attribute in yourpackage.json
or if you export an objectmodule.export = {}
in ajest.config.js
file in your project root directory.
Read More: Configuring Jest Docs -
If Breakspoints are not working properly, try adding this to vscode config:
"jestrunner.debugOptions": {
"args": ["--no-cache"],
"sourcemaps": "inline",
"disableOptimisticBPs": true,
}