UNPKG

1.83 kBJavaScriptView Raw
1'use strict'
2const path = require('path')
3const execa = require('execa')
4const { hook, fromAegir } = require('../utils')
5const merge = require('merge-options')
6
7/** @typedef { import("execa").Options} ExecaOptions */
8
9module.exports = (argv, execaOptions) => {
10 const input = argv._.slice(1)
11 const forwardOptions = argv['--'] ? argv['--'] : []
12 const watch = argv.watch ? ['--auto-watch', '--no-single-run'] : []
13 const files = argv.files ? ['--files-custom', ...argv.files] : []
14 const verbose = argv.verbose ? ['--log-level', 'debug'] : ['--log-level', 'error']
15 const grep = argv.grep ? ['--grep', argv.grep] : []
16 const invert = argv.invert ? ['--invert'] : []
17 const progress = argv.progress ? ['--progress', argv.progress] : []
18 const bail = argv.bail ? ['--bail', argv.bail] : []
19 const timeout = argv.timeout ? ['--timeout', argv.timeout] : []
20
21 return hook('browser', 'pre')(argv.userConfig)
22 .then((hook = {}) => {
23 return execa('karma',
24 [
25 'start',
26 fromAegir('src/config/karma.conf.js'),
27 ...watch,
28 ...files,
29 ...verbose,
30 ...grep,
31 ...invert,
32 ...progress,
33 ...input,
34 ...bail,
35 ...timeout,
36 ...forwardOptions
37 ],
38 merge(
39 {
40 env: {
41 NODE_ENV: process.env.NODE_ENV || 'test',
42 AEGIR_RUNNER: argv.webworker ? 'webworker' : 'browser',
43 AEGIR_NODE: argv.node,
44 AEGIR_TS: argv.ts,
45 IS_WEBPACK_BUILD: true,
46 ...hook.env
47 },
48 preferLocal: true,
49 localDir: path.join(__dirname, '../..'),
50 stdio: 'inherit'
51 },
52 execaOptions
53 )
54 )
55 })
56 .then(() => hook('browser', 'post')(argv.userConfig))
57}