Files
vue-cli/packages/@vue/cli-plugin-unit-jest/index.js
T
Evan You d595adacf4 refactor: adjust mode loading order
BREAKING CHANGE: PluginAPI.setMode() has been removed. Instead, for a plugin to
sepcify the default mode for a registered command, the plugins should expose
`module.exports.defaultModes` in the form of `{ [commandName]: mode }`.

close #959
2018-05-01 17:14:33 -04:00

39 lines
1.0 KiB
JavaScript

module.exports = api => {
api.registerCommand('test', {
description: 'run unit tests with jest',
usage: 'vue-cli-service test [options] <regexForTestFiles>',
options: {
'--watch': 'run tests in watch mode'
},
details:
`All jest command line options are supported.\n` +
`See https://facebook.github.io/jest/docs/en/cli.html for more details.`
}, (args, rawArgv) => {
// for @vue/babel-preset-app
process.env.VUE_CLI_BABEL_TARGET_NODE = true
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = true
const execa = require('execa')
const jestBinPath = require.resolve('jest/bin/jest')
return new Promise((resolve, reject) => {
const child = execa(jestBinPath, rawArgv, {
cwd: api.resolve('.'),
stdio: 'inherit'
})
child.on('error', reject)
child.on('exit', code => {
if (code !== 0) {
reject(`jest exited with code ${code}.`)
} else {
resolve()
}
})
})
})
}
module.exports.defaultModes = {
test: 'test'
}