forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
93 lines (86 loc) · 2.92 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
module.exports = api => {
api.chainWebpack(webpackConfig => {
if (process.env.NODE_ENV === 'test') {
webpackConfig.merge({
target: 'node',
devtool: 'inline-cheap-module-source-map'
})
const { semver, loadModule } = require('@vue/cli-shared-utils')
const vue = loadModule('vue', api.service.context)
const isVue3 = (vue && semver.major(vue.version) === 3)
// when target === 'node', vue-loader will attempt to generate
// SSR-optimized code. We need to turn that off here.
webpackConfig.module
.rule('vue')
.use('vue-loader')
.tap(options => {
if (isVue3) {
options.isServerBuild = false
} else {
options.optimizeSSR = false
}
return options
})
}
})
api.registerCommand('test:unit', {
description: 'run unit tests with mochapack',
usage: 'vue-cli-service test:unit [options] [...files]',
options: {
'--watch, -w': 'run in watch mode',
'--grep, -g': 'only run tests matching <pattern>',
'--slow, -s': '"slow" test threshold in milliseconds',
'--timeout, -t': 'timeout threshold in milliseconds',
'--bail, -b': 'bail after first test failure',
'--require, -r': 'require the given module before running tests',
'--include': 'include the given module into test bundle',
'--inspect-brk': 'Enable inspector to debug the tests'
},
details: (
`The above list only includes the most commonly used options.\n` +
`For a full list of available options, see\n` +
`https://sysgears.github.io/mochapack/docs/installation/cli-usage.html`
)
}, (args, rawArgv) => {
let nodeArgs = []
const inspectPos = rawArgv.findIndex(arg => arg.startsWith('--inspect-brk'))
if (inspectPos !== -1) {
nodeArgs = rawArgv.splice(inspectPos, 1)
}
// for @vue/babel-preset-app <= v4.0.0-rc.7
process.env.VUE_CLI_BABEL_TARGET_NODE = true
// start runner
const { execa } = require('@vue/cli-shared-utils')
const bin = require.resolve('mochapack/bin/mochapack')
const hasInlineFilesGlob = args._ && args._.length
const argv = [
...nodeArgs,
bin,
'--recursive',
'--require',
require.resolve('./setup.js'),
'--webpack-config',
require.resolve('@vue/cli-service/webpack.config.js'),
...rawArgv,
...(hasInlineFilesGlob ? [] : [
api.hasPlugin('typescript')
? `tests/unit/**/*.spec.ts`
: `tests/unit/**/*.spec.js`
])
]
return new Promise((resolve, reject) => {
const child = execa('node', argv, { stdio: 'inherit' })
child.on('error', reject)
child.on('exit', code => {
if (code !== 0) {
reject(`mochapack exited with code ${code}.`)
} else {
resolve()
}
})
})
})
}
module.exports.defaultModes = {
'test:unit': 'test'
}