Skip to content

Commit cd88cfa

Browse files
committed
feat(unit-jest): run jest in the same process
This allows vue-cli-service test:unit to be debugged via node inspector.
1 parent e33b04c commit cd88cfa

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

packages/@vue/cli-plugin-unit-jest/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515

1616
All [Jest command line options](https://facebook.github.io/jest/docs/en/cli.html) are also supported.
1717

18+
## Debugging Tests
19+
20+
Note that directly running `jest` will fail because the Babel preset requires hints to make your code work in Node.js, so you must run your tests with `vue-cli-service test:unit`.
21+
22+
If you want to debug your tests via the Node inspector, you can run the following:
23+
24+
``` sh
25+
node --inspect-brk ./node_modules/.bin/vue-cli-service test:unit
26+
```
27+
1828
## Configuration
1929

2030
Jest can be configured via `jest.config.js` in your project root, or the `jest` field in `package.json`.

packages/@vue/cli-plugin-unit-jest/index.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,7 @@ module.exports = api => {
1212
// for @vue/babel-preset-app
1313
process.env.VUE_CLI_BABEL_TARGET_NODE = true
1414
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = true
15-
16-
const { execa } = require('@vue/cli-shared-utils')
17-
const jestBinPath = require.resolve('jest/bin/jest')
18-
19-
return new Promise((resolve, reject) => {
20-
const child = execa(jestBinPath, rawArgv, {
21-
cwd: api.resolve('.'),
22-
stdio: 'inherit'
23-
})
24-
child.on('error', reject)
25-
child.on('exit', code => {
26-
if (code !== 0) {
27-
reject(`jest exited with code ${code}.`)
28-
} else {
29-
resolve()
30-
}
31-
})
32-
})
15+
require('jest').run(rawArgv)
3316
})
3417

3518
// TODO remove in RC

0 commit comments

Comments
 (0)