-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·121 lines (117 loc) · 3.28 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
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
#!/usr/bin/env node
'use strict';
const yargs = require('yargs');
const { hideBin } = require('yargs/helpers');
const { mochify } = require('@mochify/mochify');
const opts = yargs(hideBin(process.argv))
.usage('$0 [config] <spec...>')
.option('config', {
alias: 'C',
type: 'string',
group: 'Options:',
describe: 'Specify a config file, skipping default lookup'
})
.option('driver', {
alias: 'D',
type: 'string',
group: 'Options:',
describe: 'Specify the driver module'
})
.option('driver-option', {
type: 'object',
group: 'Options:',
describe: 'Pass options to the driver'
})
.option('reporter', {
alias: 'R',
type: 'string',
group: 'Options:',
describe: 'Specify the Mocha reporter'
})
.option('bundle', {
alias: 'B',
type: 'string',
group: 'Options:',
describe: 'Bundle the resolved spec using the given command'
})
.option('bundle-stdin', {
type: 'string',
group: 'Options:',
describe:
'Pass a synthetic file as stdin to the bundler with "require" or "import" statements for each spec file'
})
.option('esm', {
type: 'boolean',
group: 'Options:',
describe: 'Run a local web server, inject spec files as ES modules'
})
.option('serve', {
alias: 'S',
type: 'string',
group: 'Options:',
describe:
'Run tests in the context of a local web server, serve the given directory'
})
.option('server-option', {
type: 'object',
group: 'Options:',
describe: 'Pass options to the server (requires --serve or --esm)'
})
.updateStrings({
'Options:': 'Other:'
})
.example(
'$0 --driver puppeteer --bundle browserify "./src/**/*.test.js"',
'Bundle all files matching the given spec using browserify and run them using @mochify/driver-puppeteer.'
)
.example(
'$0 --driver playwright --bundle esbuild --bundle-stdin "require" "./src/**/*.test.js"',
'Bundle all files matching the given spec using esbuild and run them using @mochify/driver-playwright.'
)
.example(
'$0 --esm --reporter dot --driver puppeteer "./src/**/*.test.js"',
'Run all tests matching the given spec as ES modules in puppeteer and use the "dot" reporter for output.'
)
.example(
'$0 "./src/**/*.test.js"',
'Run all tests matching the given spec using the default configuration lookup.'
)
.example(
'$0 --config mochify.webdriver.js "./src/**/*.test.js"',
'Run all tests matching the given spec using the configuration from mochify.webdriver.js.'
)
.example(
'browserify "./src/**/*.test.js" | $0 -',
'Read a bundled test suite from stdin.'
)
.epilogue(
`Mochify Resources:
GitHub: https://github.com/mochify-js`
)
.wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
.parse();
if (opts['driver-option']) {
opts.driver_options = opts['driver-option'];
}
if (opts['server-option']) {
opts.server_options = opts['server-option'];
}
if (opts['bundle-stdin']) {
opts.bundle_stdin = opts['bundle-stdin'];
}
if (opts._.length) {
if (opts._[0] === '-') {
opts.spec = process.stdin;
} else {
opts.spec = opts._;
}
}
delete opts._;
mochify(opts)
.catch((err) => {
console.error(err.stack);
return { exit_code: 1 };
})
.then(({ exit_code }) => {
process.exitCode = exit_code;
});