-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
72 lines (60 loc) · 2.14 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
module.exports = (api, projectOptions) => {
let optionsForThisPlugin = require('./config-defaults')
if (projectOptions.pluginOptions && projectOptions.pluginOptions.karma) {
Object.assign(optionsForThisPlugin, projectOptions.pluginOptions.karma)
}
api.registerCommand('test:unit',
{
'description': 'run unit tests with karma-webpack',
'usage': 'vue-cli-service test',
options: {
'--watch, -w': 'run in watch mode',
'--junit [dirname], -j [dirname]': 'output JUnit-style XML test reports for each browser'
}
},
(args, rawArgv) => {
let webpackConfigForTests = api.resolveChainableWebpackConfig()
.target()
.clear()
webpackConfigForTests = webpackConfigForTests.toConfig()
// workaround for: https://github.com/webpack-contrib/karma-webpack/pull/325
// TODO: remove this when the above PR is merged
webpackConfigForTests.optimization = {
splitChunks: false,
runtimeChunk: false
}
webpackConfigForTests.mode = 'development'
return new Promise((resolve, reject) => {
let KarmaServer = require('karma').Server
let generateKarmaConfig = require('./karma.conf')
let expressServer
if (optionsForThisPlugin.expressServer) {
let expressApp = require('express')()
optionsForThisPlugin.expressServer.setup(expressApp)
expressServer = expressApp.listen(optionsForThisPlugin.expressServer.port)
}
let karmaServer = new KarmaServer(
generateKarmaConfig({
optionsForThisPlugin,
webpackConfig: webpackConfigForTests,
watch: args.watch || args.w,
junit: args.junit || args.j
}),
function (exitCode) {
console.log('Karma has exited with ' + exitCode)
if (expressServer) {
expressServer.close()
}
if (exitCode === 0) {
resolve(exitCode)
} else {
reject(exitCode)
}
})
karmaServer.start()
})
})
}
module.exports.defaultModes = {
'test:unit': 'test'
}