-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
60 lines (51 loc) · 1.75 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
module.exports = ( api, projectOptions ) => {
let karmaOptions = require( './default-karma-config' );
if ( projectOptions.pluginOptions && projectOptions.pluginOptions.karma ) {
karmaOptions = Object.assign( karmaOptions, projectOptions.pluginOptions.karma );
}
api.chainWebpack( webpackConfig => {
if ( process.env.NODE_ENV === 'test' ) {
webpackConfig.merge( {
target: 'node',
devtool: 'inline-cheap-module-source-map'
} );
// 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 => {
options.optimizeSSR = false;
return options;
} );
}
} );
api.registerCommand( 'test:unit', {
description: 'Run unit tests with karma',
usage: 'vue-cli-service test:unit [options] [...files]',
}, ( args ) => {
const webpackConfig = api.resolveWebpackConfig();
process.env.VUE_CLI_BABEL_TARGET_NODE = true
process.env.VUE_CLI_BABEL_TRANSPILE_MODULES = true
return new Promise( ( resolve, reject ) => {
let KarmaServer = require( 'karma' ).Server;
let generateKarmaConfig = require( './karma.conf' );
let karmaServer = new KarmaServer(
generateKarmaConfig( {
webpackConfig,
karmaOptions,
watch: args.watch || args.w
} ), ( exitCode ) => {
console.log( `Karma exited with exitCode ${exitCode}` );
if ( exitCode === 0 ) {
resolve( exitCode );
} else {
reject( exitCode );
}
}
);
karmaServer.start();
} );
}
);
};