mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-18 21:30:04 -06:00
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:
@@ -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`.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user