1 | 'use strict'
|
2 |
|
3 | const execa = require('execa')
|
4 | const path = require('path')
|
5 | const { hook, fromAegir } = require('../utils')
|
6 | const merge = require('merge-options')
|
7 |
|
8 | const DEFAULT_TIMEOUT = global.DEFAULT_TIMEOUT || 5 * 1000
|
9 |
|
10 |
|
11 |
|
12 | function testNode (ctx, execaOptions) {
|
13 | let exec = 'mocha'
|
14 | const env = {
|
15 | NODE_ENV: 'test',
|
16 | AEGIR_RUNNER: 'node',
|
17 | AEGIR_TS: ctx.ts
|
18 | }
|
19 | const timeout = ctx.timeout || DEFAULT_TIMEOUT
|
20 |
|
21 | let args = [
|
22 | ctx.progress && '--reporter=progress',
|
23 | '--ui', 'bdd',
|
24 | '--timeout', timeout,
|
25 | `--unhandled-rejections=${ctx.noUnhandledPromiseRejections ? 'strict' : 'warn'}`
|
26 | ].filter(Boolean)
|
27 |
|
28 | let files = [
|
29 | 'test/node.{js,ts}',
|
30 | 'test/**/*.spec.{js,ts}'
|
31 | ]
|
32 |
|
33 | if (ctx.colors) {
|
34 | args.push('--colors')
|
35 | } else {
|
36 | args.push('--no-colors')
|
37 | }
|
38 |
|
39 | if (ctx.grep) {
|
40 | args.push(`--grep=${ctx.grep}`)
|
41 | }
|
42 |
|
43 | if (ctx.invert) {
|
44 | args.push('--invert')
|
45 | }
|
46 |
|
47 | if (ctx.files && ctx.files.length > 0) {
|
48 | files = ctx.files
|
49 | }
|
50 |
|
51 | if (ctx.verbose) {
|
52 | args.push('--verbose')
|
53 | }
|
54 |
|
55 | if (ctx.watch) {
|
56 | args.push('--watch')
|
57 | }
|
58 |
|
59 | if (ctx.exit) {
|
60 | args.push('--exit')
|
61 | }
|
62 |
|
63 | if (ctx.bail) {
|
64 | args.push('--bail')
|
65 | }
|
66 |
|
67 | if (ctx.ts) {
|
68 | args.push(...['--require', fromAegir('src/config/register.js')])
|
69 | }
|
70 |
|
71 | const postHook = hook('node', 'post')
|
72 | const preHook = hook('node', 'pre')
|
73 |
|
74 | if (ctx['100']) {
|
75 | args = [
|
76 | '--check-coverage',
|
77 | '--branches=100',
|
78 | '--functions=100',
|
79 | '--lines=100',
|
80 | '--statements=100',
|
81 | exec
|
82 | ].concat(args)
|
83 | exec = 'nyc'
|
84 | }
|
85 |
|
86 | return preHook(ctx)
|
87 | .then((hook = {}) => {
|
88 | return execa(exec,
|
89 | args.concat(files.map((p) => path.normalize(p))),
|
90 | merge(
|
91 | {
|
92 | env: {
|
93 | ...env,
|
94 | ...hook.env
|
95 | },
|
96 | preferLocal: true,
|
97 | localDir: path.join(__dirname, '../..'),
|
98 | stdio: 'inherit'
|
99 | },
|
100 | execaOptions
|
101 | )
|
102 | )
|
103 | })
|
104 | .then(() => postHook(ctx))
|
105 | }
|
106 |
|
107 | module.exports = testNode
|