-
Notifications
You must be signed in to change notification settings - Fork 59
/
test.js
128 lines (123 loc) · 4.13 KB
/
test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os from 'os'
import kleur from 'kleur'
import { loadUserConfig } from '../config/user.js'
import testCmd from '../test/index.js'
/**
* @typedef {import("yargs").Argv} Argv
* @typedef {import("yargs").CommandModule} CommandModule
*/
const EPILOG = `
By default browser tests run in Chromium headless.
Testing supports options forwarding with '--' for more info check https://github.com/hugomrdias/playwright-test#options, https://mochajs.org/#command-line-usage or https://github.com/jprichardson/electron-mocha#run-tests.
`
/** @type {CommandModule} */
export default {
command: 'test',
describe: 'Test your code in different environments',
/**
* @param {Argv} yargs
*/
builder: async (yargs) => {
const userConfig = await loadUserConfig()
return yargs
.epilog(EPILOG)
.example(
'aegir test -t webworker',
'Run tests in the browser inside a webworker.'
)
.example(
'aegir test -t browser -- --browser firefox',
'Tell `playwright-test` to run tests in firefox.'
)
.example(
'aegir test -w -t browser -- --browser webkit --debug',
'Debug tests with watch mode and tell `playwright-test` to open webkit in a non-headless mode.'
)
.example(
'aegir test -t electron-renderer -- --interactive',
'Debug electron renderer test with a persistent window.'
)
.example(
'aegir test -t node --cov && npx nyc report',
'Run test with coverage enabled and report to the terminal.'
)
.options({
build: {
alias: 'b',
describe: 'Build the project before running the tests',
type: 'boolean',
default: userConfig.test.build
},
types: {
type: 'boolean',
describe: 'If a tsconfig.json is present in the project, run tsc.',
default: userConfig.build.types
},
target: {
alias: 't',
describe: 'In which target environment to execute the tests',
array: true,
choices: ['node', 'browser', 'webworker', 'electron-main', 'electron-renderer', 'react-native-android', 'react-native-ios'],
default: userConfig.test.target
},
watch: {
alias: 'w',
describe: 'Watch files for changes and rerun tests',
type: 'boolean',
default: userConfig.test.watch
},
files: {
alias: 'f',
describe: 'Custom globs for files to test',
array: true,
default: userConfig.test.files
},
timeout: {
describe: 'The default time a single test has to run',
type: 'number',
default: userConfig.test.timeout
},
grep: {
alias: 'g',
type: 'string',
describe: 'Limit tests to those whose names match given pattern'
},
bail: {
alias: 'b',
describe: 'Mocha should bail once a test fails',
type: 'boolean',
default: userConfig.test.bail
},
progress: {
describe: 'Use progress reporters on mocha and karma',
type: 'boolean',
default: userConfig.test.progress
},
cov: {
describe: 'Enable coverage output. Output is already in Istanbul JSON format and can be uploaded directly to codecov.',
type: 'boolean',
default: userConfig.test.cov
},
covTimeout: {
describe: 'How long to wait for coverage collection. Workaround for https://github.com/ipfs/aegir/issues/1206',
type: 'number',
default: userConfig.test.covTimeout
}
})
},
/**
* @param {any} argv
*/
async handler (argv) {
// temporarily disable code coverage on Windows
if (argv.cov && os.platform() === 'win32') {
console.warn(kleur.red('!!! Temporarily disabling code coverage\n')) // eslint-disable-line no-console
console.warn(kleur.red('!!! See https://github.com/ipfs/aegir/issues/1206 for more information')) // eslint-disable-line no-console
delete argv.cov
}
await testCmd.run({
...argv,
bundle: false
})
}
}