UNPKG

1.21 kBJavaScriptView Raw
1exports.name = 'karma'
2
3exports.apply = api => {
4 api.hook('createCLI', () => {
5 api.cli
6 .command('karma [...testFiles]', 'Run unit tests with Karma')
7 .usage('karma --test [...testFiles] [options]')
8 .option('-w, --watch', 'Watch files')
9 .option('--no-headless', 'Run with Chrome instead of Chrome Headless')
10 .option('--coverage', 'Report code coverage')
11 .action((testFiles, options) => {
12 api.hook('createWebpackConfig', config => {
13 if (options.coverage) {
14 /* for general usage */
15 const istanbulinstrumenterRule = config.module
16 .rule('istanbul-instrumenter')
17 .test(/\.(jsx?)$/)
18 .exclude.add(/(node_modules|\.test\.jsx?)/)
19 .end()
20 .enforce('pre')
21 istanbulinstrumenterRule
22 .use('istanbul-instrumenter-loader')
23 .loader('istanbul-instrumenter-loader')
24 .options({
25 esModules: true
26 })
27 }
28 })
29
30 return require('./run-karma')(
31 api,
32 testFiles.length === 0 ? ['**/*.{test,spec}.{js,ts}'] : testFiles,
33 options
34 )
35 })
36 })
37}