Skip to content

Commit

Permalink
fix: fail to test specific package (#2099)
Browse files Browse the repository at this point in the history
  • Loading branch information
billyyyyy3320 committed Mar 10, 2020
1 parent e9fde5c commit 0aadf05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 12 additions & 6 deletions 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')
Expand Down
6 changes: 4 additions & 2 deletions scripts/test.js
Expand Up @@ -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)
}
Expand All @@ -17,7 +19,7 @@ const jestRunner = createJestRunner([
'--config', 'scripts/jest.config.js',
'--runInBand',
...(regex ? [regex] : [])
])
], debug)

// ensure the basic temp files were generated
createApp({
Expand Down

0 comments on commit 0aadf05

Please sign in to comment.