Skip to content

Commit 2243515

Browse files
YuJianrongyyx990803
authored andcommitted
feat(service): Enable inspector debugging for unit test by mocha (#2013)
1 parent 31710fe commit 2243515

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
--bail, -b bail after first test failure
2323
--require, -r require the given module before running tests
2424
--include include the given module into test bundle
25+
--inspect-brk Enable inspector to debug the tests
2526
```
2627

2728
Default files matches are: any files in `tests/unit` that end in `.spec.(ts|js)`.

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,29 @@ module.exports = api => {
2828
'--timeout, -t': 'timeout threshold in milliseconds',
2929
'--bail, -b': 'bail after first test failure',
3030
'--require, -r': 'require the given module before running tests',
31-
'--include': 'include the given module into test bundle'
31+
'--include': 'include the given module into test bundle',
32+
'--inspect-brk': 'Enable inspector to debug the tests'
3233
},
3334
details: (
3435
`The above list only includes the most commonly used options.\n` +
3536
`For a full list of available options, see\n` +
3637
`http://zinserjan.github.io/mocha-webpack/docs/installation/cli-usage.html`
3738
)
3839
}, (args, rawArgv) => {
40+
const inspectPos = rawArgv.indexOf('--inspect-brk')
41+
let nodeArgs = []
42+
if (inspectPos !== -1) {
43+
nodeArgs = rawArgv.splice(inspectPos, inspectPos + 1)
44+
}
3945
// for @vue/babel-preset-app
4046
process.env.VUE_CLI_BABEL_TARGET_NODE = true
4147
// start runner
4248
const { execa } = require('@vue/cli-shared-utils')
4349
const bin = require.resolve('mocha-webpack/bin/mocha-webpack')
4450
const hasInlineFilesGlob = args._ && args._.length
4551
const argv = [
52+
...nodeArgs,
53+
bin,
4654
'--recursive',
4755
'--require',
4856
require.resolve('./setup.js'),
@@ -57,7 +65,7 @@ module.exports = api => {
5765
]
5866

5967
return new Promise((resolve, reject) => {
60-
const child = execa(bin, argv, { stdio: 'inherit' })
68+
const child = execa('node', argv, { stdio: 'inherit' })
6169
child.on('error', reject)
6270
child.on('exit', code => {
6371
if (code !== 0) {

0 commit comments

Comments
 (0)