diff --git a/packages/@vuepress/test-utils/lib/createJestRunner.js b/packages/@vuepress/test-utils/lib/createJestRunner.js index 0456e0482b..56f57e8e8e 100644 --- a/packages/@vuepress/test-utils/lib/createJestRunner.js +++ b/packages/@vuepress/test-utils/lib/createJestRunner.js @@ -1,21 +1,27 @@ const execa = require('execa') -const rawArgs = process.argv.slice(2) const usedPorts = [] -module.exports = function createJestRunner (jestArgs) { +/** + * Run jest + * + * @param {array} jestArgs an array of Jest CLI options + * @param {array} debug whether start with '--inspect-brk' or not + */ + +module.exports = function createJestRunner (jestArgs, debug) { return async function () { - const execArgv = getChildProcesExecArgv() - const args = [...execArgv, ...jestArgs] + const execArgv = getChildProcessExecArgv() + const args = [require.resolve('jest-cli/bin/jest'), ...execArgv, ...jestArgs] + if (debug) args.unshift('--inspect-brk') console.log(`running node with args: ${args.join(' ')}`) - args.unshift(...rawArgs, require.resolve('jest-cli/bin/jest')) await execa('node', args, { stdio: 'inherit' }) } } -function getChildProcesExecArgv () { +function getChildProcessExecArgv () { const execArgv = process.execArgv.slice(0) const inspectArgvIndex = execArgv.findIndex(argv => argv.includes('--inspect-brk') diff --git a/scripts/test.js b/scripts/test.js index f5ee8cc981..686ba37e64 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -6,9 +6,11 @@ const rawArgs = process.argv.slice(2) const args = minimist(rawArgs) let regex +const debug = !!args['inspect-brk'] + if (args.p) { const packages = (args.p || args.package).split(',').join('|') - regex = `.*@vuepress/(${packages}|plugin-(${packages}))/.*\\.spec\\.js$` + regex = `.*@vuepress/(${packages}|plugin-(${packages}))/.*\\.spec\\.(js|ts)$` const i = rawArgs.indexOf('-p') rawArgs.splice(i, 2) } @@ -17,7 +19,7 @@ const jestRunner = createJestRunner([ '--config', 'scripts/jest.config.js', '--runInBand', ...(regex ? [regex] : []) -]) +], debug) // ensure the basic temp files were generated createApp({