Skip to content

feat(service): Enable inspector debugging for unit test by mocha #2013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@vue/cli-plugin-unit-mocha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
--bail, -b bail after first test failure
--require, -r require the given module before running tests
--include include the given module into test bundle
--inspect-brk Enable inspector to debug the tests
```

Default files matches are: any files in `tests/unit` that end in `.spec.(ts|js)`.
Expand Down
12 changes: 10 additions & 2 deletions packages/@vue/cli-plugin-unit-mocha/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,29 @@ module.exports = api => {
'--timeout, -t': 'timeout threshold in milliseconds',
'--bail, -b': 'bail after first test failure',
'--require, -r': 'require the given module before running tests',
'--include': 'include the given module into test bundle'
'--include': 'include the given module into test bundle',
'--inspect-brk': 'Enable inspector to debug the tests'
},
details: (
`The above list only includes the most commonly used options.\n` +
`For a full list of available options, see\n` +
`http://zinserjan.github.io/mocha-webpack/docs/installation/cli-usage.html`
)
}, (args, rawArgv) => {
const inspectPos = rawArgv.indexOf('--inspect-brk')
let nodeArgs = []
if (inspectPos !== -1) {
nodeArgs = rawArgv.splice(inspectPos, inspectPos + 1)
}
// for @vue/babel-preset-app
process.env.VUE_CLI_BABEL_TARGET_NODE = true
// start runner
const { execa } = require('@vue/cli-shared-utils')
const bin = require.resolve('mocha-webpack/bin/mocha-webpack')
const hasInlineFilesGlob = args._ && args._.length
const argv = [
...nodeArgs,
bin,
'--recursive',
'--require',
require.resolve('./setup.js'),
Expand All @@ -57,7 +65,7 @@ module.exports = api => {
]

return new Promise((resolve, reject) => {
const child = execa(bin, argv, { stdio: 'inherit' })
const child = execa('node', argv, { stdio: 'inherit' })
child.on('error', reject)
child.on('exit', code => {
if (code !== 0) {
Expand Down