Skip to content

Commit 0aadf05

Browse files
fix: fail to test specific package (#2099)
1 parent e9fde5c commit 0aadf05

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/@vuepress/test-utils/lib/createJestRunner.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
const execa = require('execa')
2-
const rawArgs = process.argv.slice(2)
32

43
const usedPorts = []
54

6-
module.exports = function createJestRunner (jestArgs) {
5+
/**
6+
* Run jest
7+
*
8+
* @param {array} jestArgs an array of Jest CLI options
9+
* @param {array} debug whether start with '--inspect-brk' or not
10+
*/
11+
12+
module.exports = function createJestRunner (jestArgs, debug) {
713
return async function () {
8-
const execArgv = getChildProcesExecArgv()
9-
const args = [...execArgv, ...jestArgs]
14+
const execArgv = getChildProcessExecArgv()
15+
const args = [require.resolve('jest-cli/bin/jest'), ...execArgv, ...jestArgs]
16+
if (debug) args.unshift('--inspect-brk')
1017
console.log(`running node with args: ${args.join(' ')}`)
11-
args.unshift(...rawArgs, require.resolve('jest-cli/bin/jest'))
1218
await execa('node', args, {
1319
stdio: 'inherit'
1420
})
1521
}
1622
}
1723

18-
function getChildProcesExecArgv () {
24+
function getChildProcessExecArgv () {
1925
const execArgv = process.execArgv.slice(0)
2026
const inspectArgvIndex = execArgv.findIndex(argv =>
2127
argv.includes('--inspect-brk')

scripts/test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const rawArgs = process.argv.slice(2)
66
const args = minimist(rawArgs)
77

88
let regex
9+
const debug = !!args['inspect-brk']
10+
911
if (args.p) {
1012
const packages = (args.p || args.package).split(',').join('|')
11-
regex = `.*@vuepress/(${packages}|plugin-(${packages}))/.*\\.spec\\.js$`
13+
regex = `.*@vuepress/(${packages}|plugin-(${packages}))/.*\\.spec\\.(js|ts)$`
1214
const i = rawArgs.indexOf('-p')
1315
rawArgs.splice(i, 2)
1416
}
@@ -17,7 +19,7 @@ const jestRunner = createJestRunner([
1719
'--config', 'scripts/jest.config.js',
1820
'--runInBand',
1921
...(regex ? [regex] : [])
20-
])
22+
], debug)
2123

2224
// ensure the basic temp files were generated
2325
createApp({

0 commit comments

Comments
 (0)