feat(unit-jest): run jest in the same process

This allows vue-cli-service test:unit to be debugged via node inspector.
This commit is contained in:
Evan You
2018-07-18 17:12:17 -04:00
parent e33b04c306
commit cd88cfa1e4
2 changed files with 11 additions and 18 deletions

View File

@@ -15,6 +15,16 @@
All [Jest command line options](https://facebook.github.io/jest/docs/en/cli.html) are also supported.
## Debugging Tests
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`.
If you want to debug your tests via the Node inspector, you can run the following:
``` sh
node --inspect-brk ./node_modules/.bin/vue-cli-service test:unit
```
## Configuration
Jest can be configured via `jest.config.js` in your project root, or the `jest` field in `package.json`.

View File

@@ -12,24 +12,7 @@ module.exports = api => {
// for @vue/babel-preset-app
process.env.VUE_CLI_BABEL_TARGET_NODE = true
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = true
const { execa } = require('@vue/cli-shared-utils')
const jestBinPath = require.resolve('jest/bin/jest')
return new Promise((resolve, reject) => {
const child = execa(jestBinPath, rawArgv, {
cwd: api.resolve('.'),
stdio: 'inherit'
})
child.on('error', reject)
child.on('exit', code => {
if (code !== 0) {
reject(`jest exited with code ${code}.`)
} else {
resolve()
}
})
})
require('jest').run(rawArgv)
})
// TODO remove in RC