mocha 6.1.0 → 6.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1776 -1751
- package/LICENSE +22 -22
- package/README.md +105 -105
- package/bin/_mocha +10 -10
- package/bin/mocha +149 -149
- package/bin/options.js +10 -10
- package/browser-entry.js +191 -191
- package/index.js +3 -3
- package/lib/browser/growl.js +168 -168
- package/lib/browser/progress.js +119 -119
- package/lib/browser/template.html +18 -18
- package/lib/browser/tty.js +13 -13
- package/lib/cli/cli.js +69 -69
- package/lib/cli/commands.js +13 -13
- package/lib/cli/config.js +101 -101
- package/lib/cli/index.js +9 -9
- package/lib/cli/init.js +37 -37
- package/lib/cli/node-flags.js +86 -86
- package/lib/cli/one-and-dones.js +70 -70
- package/lib/cli/options.js +347 -347
- package/lib/cli/run-helpers.js +337 -337
- package/lib/cli/run-option-metadata.js +76 -76
- package/lib/cli/run.js +297 -297
- package/lib/context.js +101 -101
- package/lib/errors.js +141 -141
- package/lib/growl.js +136 -136
- package/lib/hook.js +46 -46
- package/lib/interfaces/bdd.js +118 -118
- package/lib/interfaces/common.js +191 -191
- package/lib/interfaces/exports.js +60 -60
- package/lib/interfaces/index.js +6 -6
- package/lib/interfaces/qunit.js +99 -99
- package/lib/interfaces/tdd.js +107 -107
- package/lib/mocha.js +843 -843
- package/lib/mocharc.json +10 -10
- package/lib/pending.js +12 -12
- package/lib/reporters/base.js +491 -491
- package/lib/reporters/doc.js +85 -85
- package/lib/reporters/dot.js +81 -81
- package/lib/reporters/html.js +390 -390
- package/lib/reporters/index.js +19 -19
- package/lib/reporters/json-stream.js +90 -90
- package/lib/reporters/json.js +135 -135
- package/lib/reporters/landing.js +108 -108
- package/lib/reporters/list.js +78 -78
- package/lib/reporters/markdown.js +112 -112
- package/lib/reporters/min.js +52 -52
- package/lib/reporters/nyan.js +276 -276
- package/lib/reporters/progress.js +104 -104
- package/lib/reporters/spec.js +99 -99
- package/lib/reporters/tap.js +294 -294
- package/lib/reporters/xunit.js +216 -216
- package/lib/runnable.js +496 -496
- package/lib/runner.js +1049 -1049
- package/lib/stats-collector.js +83 -83
- package/lib/suite.js +642 -642
- package/lib/test.js +51 -51
- package/lib/utils.js +897 -897
- package/mocha.css +326 -326
- package/mocha.js +8170 -8476
- package/package.json +630 -628
package/lib/cli/run.js
CHANGED
|
@@ -1,297 +1,297 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Definition for Mocha's default ("run tests") command
|
|
5
|
-
*
|
|
6
|
-
* @module
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const Mocha = require('../mocha');
|
|
11
|
-
const {
|
|
12
|
-
createUnsupportedError,
|
|
13
|
-
createInvalidArgumentValueError,
|
|
14
|
-
createMissingArgumentError
|
|
15
|
-
} = require('../errors');
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
list,
|
|
19
|
-
handleFiles,
|
|
20
|
-
handleRequires,
|
|
21
|
-
validatePlugin,
|
|
22
|
-
runMocha
|
|
23
|
-
} = require('./run-helpers');
|
|
24
|
-
const {ONE_AND_DONES, ONE_AND_DONE_ARGS} = require('./one-and-dones');
|
|
25
|
-
const debug = require('debug')('mocha:cli:run');
|
|
26
|
-
const defaults = require('../mocharc');
|
|
27
|
-
const {types, aliases} = require('./run-option-metadata');
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Logical option groups
|
|
31
|
-
* @constant
|
|
32
|
-
*/
|
|
33
|
-
const GROUPS = {
|
|
34
|
-
FILES: 'File Handling',
|
|
35
|
-
FILTERS: 'Test Filters',
|
|
36
|
-
NODEJS: 'Node.js & V8',
|
|
37
|
-
OUTPUT: 'Reporting & Output',
|
|
38
|
-
RULES: 'Rules & Behavior',
|
|
39
|
-
CONFIG: 'Configuration'
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
exports.command = ['$0 [spec..]', 'debug [spec..]'];
|
|
43
|
-
|
|
44
|
-
exports.describe = 'Run tests with Mocha';
|
|
45
|
-
|
|
46
|
-
exports.builder = yargs =>
|
|
47
|
-
yargs
|
|
48
|
-
.options({
|
|
49
|
-
'allow-uncaught': {
|
|
50
|
-
description: 'Allow uncaught errors to propagate',
|
|
51
|
-
group: GROUPS.RULES
|
|
52
|
-
},
|
|
53
|
-
'async-only': {
|
|
54
|
-
description:
|
|
55
|
-
'Require all tests to use a callback (async) or return a Promise',
|
|
56
|
-
group: GROUPS.RULES
|
|
57
|
-
},
|
|
58
|
-
bail: {
|
|
59
|
-
description: 'Abort ("bail") after first test failure',
|
|
60
|
-
group: GROUPS.RULES
|
|
61
|
-
},
|
|
62
|
-
'check-leaks': {
|
|
63
|
-
description: 'Check for global variable leaks',
|
|
64
|
-
group: GROUPS.RULES
|
|
65
|
-
},
|
|
66
|
-
color: {
|
|
67
|
-
description: 'Force-enable color output',
|
|
68
|
-
group: GROUPS.OUTPUT
|
|
69
|
-
},
|
|
70
|
-
config: {
|
|
71
|
-
config: true,
|
|
72
|
-
defaultDescription: '(nearest rc file)',
|
|
73
|
-
description: 'Path to config file',
|
|
74
|
-
group: GROUPS.CONFIG
|
|
75
|
-
},
|
|
76
|
-
delay: {
|
|
77
|
-
description: 'Delay initial execution of root suite',
|
|
78
|
-
group: GROUPS.RULES
|
|
79
|
-
},
|
|
80
|
-
diff: {
|
|
81
|
-
default: true,
|
|
82
|
-
description: 'Show diff on failure',
|
|
83
|
-
group: GROUPS.OUTPUT
|
|
84
|
-
},
|
|
85
|
-
exclude: {
|
|
86
|
-
defaultDescription: '(none)',
|
|
87
|
-
description: 'Ignore file(s) or glob pattern(s)',
|
|
88
|
-
group: GROUPS.FILES,
|
|
89
|
-
requiresArg: true
|
|
90
|
-
},
|
|
91
|
-
exit: {
|
|
92
|
-
description: 'Force Mocha to quit after tests complete',
|
|
93
|
-
group: GROUPS.RULES
|
|
94
|
-
},
|
|
95
|
-
extension: {
|
|
96
|
-
default: defaults.extension,
|
|
97
|
-
defaultDescription: 'js',
|
|
98
|
-
description: 'File extension(s) to load and/or watch',
|
|
99
|
-
group: GROUPS.FILES,
|
|
100
|
-
requiresArg: true,
|
|
101
|
-
coerce: list
|
|
102
|
-
},
|
|
103
|
-
fgrep: {
|
|
104
|
-
conflicts: 'grep',
|
|
105
|
-
description: 'Only run tests containing this string',
|
|
106
|
-
group: GROUPS.FILTERS,
|
|
107
|
-
requiresArg: true
|
|
108
|
-
},
|
|
109
|
-
file: {
|
|
110
|
-
defaultDescription: '(none)',
|
|
111
|
-
description:
|
|
112
|
-
'Specify file(s) to be loaded prior to root suite execution',
|
|
113
|
-
group: GROUPS.FILES,
|
|
114
|
-
normalize: true,
|
|
115
|
-
requiresArg: true
|
|
116
|
-
},
|
|
117
|
-
'forbid-only': {
|
|
118
|
-
description: 'Fail if exclusive test(s) encountered',
|
|
119
|
-
group: GROUPS.RULES
|
|
120
|
-
},
|
|
121
|
-
'forbid-pending': {
|
|
122
|
-
description: 'Fail if pending test(s) encountered',
|
|
123
|
-
group: GROUPS.RULES
|
|
124
|
-
},
|
|
125
|
-
'full-trace': {
|
|
126
|
-
description: 'Display full stack traces',
|
|
127
|
-
group: GROUPS.OUTPUT
|
|
128
|
-
},
|
|
129
|
-
global: {
|
|
130
|
-
coerce: list,
|
|
131
|
-
description: 'List of allowed global variables',
|
|
132
|
-
group: GROUPS.RULES,
|
|
133
|
-
requiresArg: true
|
|
134
|
-
},
|
|
135
|
-
grep: {
|
|
136
|
-
coerce: value => (!value ? null : value),
|
|
137
|
-
conflicts: 'fgrep',
|
|
138
|
-
description: 'Only run tests matching this string or regexp',
|
|
139
|
-
group: GROUPS.FILTERS,
|
|
140
|
-
requiresArg: true
|
|
141
|
-
},
|
|
142
|
-
growl: {
|
|
143
|
-
description: 'Enable Growl notifications',
|
|
144
|
-
group: GROUPS.OUTPUT
|
|
145
|
-
},
|
|
146
|
-
'inline-diffs': {
|
|
147
|
-
description:
|
|
148
|
-
'Display actual/expected differences inline within each string',
|
|
149
|
-
group: GROUPS.OUTPUT
|
|
150
|
-
},
|
|
151
|
-
interfaces: {
|
|
152
|
-
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
|
153
|
-
description: 'List built-in user interfaces & exit'
|
|
154
|
-
},
|
|
155
|
-
invert: {
|
|
156
|
-
description: 'Inverts --grep and --fgrep matches',
|
|
157
|
-
group: GROUPS.FILTERS
|
|
158
|
-
},
|
|
159
|
-
'no-colors': {
|
|
160
|
-
description: 'Force-disable color output',
|
|
161
|
-
group: GROUPS.OUTPUT,
|
|
162
|
-
hidden: true
|
|
163
|
-
},
|
|
164
|
-
opts: {
|
|
165
|
-
default: defaults.opts,
|
|
166
|
-
description: 'Path to `mocha.opts`',
|
|
167
|
-
group: GROUPS.CONFIG,
|
|
168
|
-
normalize: true,
|
|
169
|
-
requiresArg: true
|
|
170
|
-
},
|
|
171
|
-
package: {
|
|
172
|
-
description: 'Path to package.json for config',
|
|
173
|
-
group: GROUPS.CONFIG,
|
|
174
|
-
normalize: true,
|
|
175
|
-
requiresArg: true
|
|
176
|
-
},
|
|
177
|
-
recursive: {
|
|
178
|
-
description: 'Look for tests in subdirectories',
|
|
179
|
-
group: GROUPS.FILES
|
|
180
|
-
},
|
|
181
|
-
reporter: {
|
|
182
|
-
default: defaults.reporter,
|
|
183
|
-
description: 'Specify reporter to use',
|
|
184
|
-
group: GROUPS.OUTPUT,
|
|
185
|
-
requiresArg: true
|
|
186
|
-
},
|
|
187
|
-
reporters: {
|
|
188
|
-
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
|
189
|
-
description: 'List built-in reporters & exit'
|
|
190
|
-
},
|
|
191
|
-
'reporter-option': {
|
|
192
|
-
coerce: opts =>
|
|
193
|
-
list(opts).reduce((acc, opt) => {
|
|
194
|
-
const pair = opt.split('=');
|
|
195
|
-
|
|
196
|
-
if (pair.length > 2 || !pair.length) {
|
|
197
|
-
throw createInvalidArgumentValueError(
|
|
198
|
-
`invalid reporter option '${opt}'`,
|
|
199
|
-
'--reporter-option',
|
|
200
|
-
opt,
|
|
201
|
-
'expected "key=value" format'
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
acc[pair[0]] = pair.length === 2 ? pair[1] : true;
|
|
206
|
-
return acc;
|
|
207
|
-
}, {}),
|
|
208
|
-
description: 'Reporter-specific options (<k=v,[k1=v1,..]>)',
|
|
209
|
-
group: GROUPS.OUTPUT,
|
|
210
|
-
requiresArg: true
|
|
211
|
-
},
|
|
212
|
-
require: {
|
|
213
|
-
defaultDescription: '(none)',
|
|
214
|
-
description: 'Require module',
|
|
215
|
-
group: GROUPS.FILES,
|
|
216
|
-
requiresArg: true
|
|
217
|
-
},
|
|
218
|
-
retries: {
|
|
219
|
-
description: 'Retry failed tests this many times',
|
|
220
|
-
group: GROUPS.RULES
|
|
221
|
-
},
|
|
222
|
-
slow: {
|
|
223
|
-
default: defaults.slow,
|
|
224
|
-
description: 'Specify "slow" test threshold (in milliseconds)',
|
|
225
|
-
group: GROUPS.RULES
|
|
226
|
-
},
|
|
227
|
-
sort: {
|
|
228
|
-
description: 'Sort test files',
|
|
229
|
-
group: GROUPS.FILES
|
|
230
|
-
},
|
|
231
|
-
timeout: {
|
|
232
|
-
default: defaults.timeout,
|
|
233
|
-
description: 'Specify test timeout threshold (in milliseconds)',
|
|
234
|
-
group: GROUPS.RULES
|
|
235
|
-
},
|
|
236
|
-
ui: {
|
|
237
|
-
default: defaults.ui,
|
|
238
|
-
description: 'Specify user interface',
|
|
239
|
-
group: GROUPS.RULES,
|
|
240
|
-
requiresArg: true
|
|
241
|
-
},
|
|
242
|
-
watch: {
|
|
243
|
-
description: 'Watch files in the current working directory for changes',
|
|
244
|
-
group: GROUPS.FILES
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
.positional('spec', {
|
|
248
|
-
default: ['test'],
|
|
249
|
-
description: 'One or more files, directories, or globs to test',
|
|
250
|
-
type: 'array'
|
|
251
|
-
})
|
|
252
|
-
.check(argv => {
|
|
253
|
-
// "one-and-dones"; let yargs handle help and version
|
|
254
|
-
Object.keys(ONE_AND_DONES).forEach(opt => {
|
|
255
|
-
if (argv[opt]) {
|
|
256
|
-
ONE_AND_DONES[opt].call(null, yargs);
|
|
257
|
-
process.exit();
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
// yargs.implies() isn't flexible enough to handle this
|
|
262
|
-
if (argv.invert && !('fgrep' in argv || 'grep' in argv)) {
|
|
263
|
-
throw createMissingArgumentError(
|
|
264
|
-
'"--invert" requires one of "--fgrep <str>" or "--grep <regexp>"',
|
|
265
|
-
'--fgrep|--grep',
|
|
266
|
-
'string|regexp'
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (argv.compilers) {
|
|
271
|
-
throw createUnsupportedError(
|
|
272
|
-
`--compilers is DEPRECATED and no longer supported.
|
|
273
|
-
See https://git.io/vdcSr for migration information.`
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// load requires first, because it can impact "plugin" validation
|
|
278
|
-
handleRequires(argv.require);
|
|
279
|
-
validatePlugin(argv, 'reporter', Mocha.reporters);
|
|
280
|
-
validatePlugin(argv, 'ui', Mocha.interfaces);
|
|
281
|
-
|
|
282
|
-
return true;
|
|
283
|
-
})
|
|
284
|
-
.array(types.array)
|
|
285
|
-
.boolean(types.boolean)
|
|
286
|
-
.string(types.string)
|
|
287
|
-
.number(types.number)
|
|
288
|
-
.alias(aliases);
|
|
289
|
-
|
|
290
|
-
exports.handler = argv => {
|
|
291
|
-
debug('post-yargs config', argv);
|
|
292
|
-
const mocha = new Mocha(argv);
|
|
293
|
-
const files = handleFiles(argv);
|
|
294
|
-
|
|
295
|
-
debug('running tests with files', files);
|
|
296
|
-
runMocha(mocha, argv, files);
|
|
297
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Definition for Mocha's default ("run tests") command
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const Mocha = require('../mocha');
|
|
11
|
+
const {
|
|
12
|
+
createUnsupportedError,
|
|
13
|
+
createInvalidArgumentValueError,
|
|
14
|
+
createMissingArgumentError
|
|
15
|
+
} = require('../errors');
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
list,
|
|
19
|
+
handleFiles,
|
|
20
|
+
handleRequires,
|
|
21
|
+
validatePlugin,
|
|
22
|
+
runMocha
|
|
23
|
+
} = require('./run-helpers');
|
|
24
|
+
const {ONE_AND_DONES, ONE_AND_DONE_ARGS} = require('./one-and-dones');
|
|
25
|
+
const debug = require('debug')('mocha:cli:run');
|
|
26
|
+
const defaults = require('../mocharc');
|
|
27
|
+
const {types, aliases} = require('./run-option-metadata');
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Logical option groups
|
|
31
|
+
* @constant
|
|
32
|
+
*/
|
|
33
|
+
const GROUPS = {
|
|
34
|
+
FILES: 'File Handling',
|
|
35
|
+
FILTERS: 'Test Filters',
|
|
36
|
+
NODEJS: 'Node.js & V8',
|
|
37
|
+
OUTPUT: 'Reporting & Output',
|
|
38
|
+
RULES: 'Rules & Behavior',
|
|
39
|
+
CONFIG: 'Configuration'
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
exports.command = ['$0 [spec..]', 'debug [spec..]'];
|
|
43
|
+
|
|
44
|
+
exports.describe = 'Run tests with Mocha';
|
|
45
|
+
|
|
46
|
+
exports.builder = yargs =>
|
|
47
|
+
yargs
|
|
48
|
+
.options({
|
|
49
|
+
'allow-uncaught': {
|
|
50
|
+
description: 'Allow uncaught errors to propagate',
|
|
51
|
+
group: GROUPS.RULES
|
|
52
|
+
},
|
|
53
|
+
'async-only': {
|
|
54
|
+
description:
|
|
55
|
+
'Require all tests to use a callback (async) or return a Promise',
|
|
56
|
+
group: GROUPS.RULES
|
|
57
|
+
},
|
|
58
|
+
bail: {
|
|
59
|
+
description: 'Abort ("bail") after first test failure',
|
|
60
|
+
group: GROUPS.RULES
|
|
61
|
+
},
|
|
62
|
+
'check-leaks': {
|
|
63
|
+
description: 'Check for global variable leaks',
|
|
64
|
+
group: GROUPS.RULES
|
|
65
|
+
},
|
|
66
|
+
color: {
|
|
67
|
+
description: 'Force-enable color output',
|
|
68
|
+
group: GROUPS.OUTPUT
|
|
69
|
+
},
|
|
70
|
+
config: {
|
|
71
|
+
config: true,
|
|
72
|
+
defaultDescription: '(nearest rc file)',
|
|
73
|
+
description: 'Path to config file',
|
|
74
|
+
group: GROUPS.CONFIG
|
|
75
|
+
},
|
|
76
|
+
delay: {
|
|
77
|
+
description: 'Delay initial execution of root suite',
|
|
78
|
+
group: GROUPS.RULES
|
|
79
|
+
},
|
|
80
|
+
diff: {
|
|
81
|
+
default: true,
|
|
82
|
+
description: 'Show diff on failure',
|
|
83
|
+
group: GROUPS.OUTPUT
|
|
84
|
+
},
|
|
85
|
+
exclude: {
|
|
86
|
+
defaultDescription: '(none)',
|
|
87
|
+
description: 'Ignore file(s) or glob pattern(s)',
|
|
88
|
+
group: GROUPS.FILES,
|
|
89
|
+
requiresArg: true
|
|
90
|
+
},
|
|
91
|
+
exit: {
|
|
92
|
+
description: 'Force Mocha to quit after tests complete',
|
|
93
|
+
group: GROUPS.RULES
|
|
94
|
+
},
|
|
95
|
+
extension: {
|
|
96
|
+
default: defaults.extension,
|
|
97
|
+
defaultDescription: 'js',
|
|
98
|
+
description: 'File extension(s) to load and/or watch',
|
|
99
|
+
group: GROUPS.FILES,
|
|
100
|
+
requiresArg: true,
|
|
101
|
+
coerce: list
|
|
102
|
+
},
|
|
103
|
+
fgrep: {
|
|
104
|
+
conflicts: 'grep',
|
|
105
|
+
description: 'Only run tests containing this string',
|
|
106
|
+
group: GROUPS.FILTERS,
|
|
107
|
+
requiresArg: true
|
|
108
|
+
},
|
|
109
|
+
file: {
|
|
110
|
+
defaultDescription: '(none)',
|
|
111
|
+
description:
|
|
112
|
+
'Specify file(s) to be loaded prior to root suite execution',
|
|
113
|
+
group: GROUPS.FILES,
|
|
114
|
+
normalize: true,
|
|
115
|
+
requiresArg: true
|
|
116
|
+
},
|
|
117
|
+
'forbid-only': {
|
|
118
|
+
description: 'Fail if exclusive test(s) encountered',
|
|
119
|
+
group: GROUPS.RULES
|
|
120
|
+
},
|
|
121
|
+
'forbid-pending': {
|
|
122
|
+
description: 'Fail if pending test(s) encountered',
|
|
123
|
+
group: GROUPS.RULES
|
|
124
|
+
},
|
|
125
|
+
'full-trace': {
|
|
126
|
+
description: 'Display full stack traces',
|
|
127
|
+
group: GROUPS.OUTPUT
|
|
128
|
+
},
|
|
129
|
+
global: {
|
|
130
|
+
coerce: list,
|
|
131
|
+
description: 'List of allowed global variables',
|
|
132
|
+
group: GROUPS.RULES,
|
|
133
|
+
requiresArg: true
|
|
134
|
+
},
|
|
135
|
+
grep: {
|
|
136
|
+
coerce: value => (!value ? null : value),
|
|
137
|
+
conflicts: 'fgrep',
|
|
138
|
+
description: 'Only run tests matching this string or regexp',
|
|
139
|
+
group: GROUPS.FILTERS,
|
|
140
|
+
requiresArg: true
|
|
141
|
+
},
|
|
142
|
+
growl: {
|
|
143
|
+
description: 'Enable Growl notifications',
|
|
144
|
+
group: GROUPS.OUTPUT
|
|
145
|
+
},
|
|
146
|
+
'inline-diffs': {
|
|
147
|
+
description:
|
|
148
|
+
'Display actual/expected differences inline within each string',
|
|
149
|
+
group: GROUPS.OUTPUT
|
|
150
|
+
},
|
|
151
|
+
interfaces: {
|
|
152
|
+
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
|
153
|
+
description: 'List built-in user interfaces & exit'
|
|
154
|
+
},
|
|
155
|
+
invert: {
|
|
156
|
+
description: 'Inverts --grep and --fgrep matches',
|
|
157
|
+
group: GROUPS.FILTERS
|
|
158
|
+
},
|
|
159
|
+
'no-colors': {
|
|
160
|
+
description: 'Force-disable color output',
|
|
161
|
+
group: GROUPS.OUTPUT,
|
|
162
|
+
hidden: true
|
|
163
|
+
},
|
|
164
|
+
opts: {
|
|
165
|
+
default: defaults.opts,
|
|
166
|
+
description: 'Path to `mocha.opts`',
|
|
167
|
+
group: GROUPS.CONFIG,
|
|
168
|
+
normalize: true,
|
|
169
|
+
requiresArg: true
|
|
170
|
+
},
|
|
171
|
+
package: {
|
|
172
|
+
description: 'Path to package.json for config',
|
|
173
|
+
group: GROUPS.CONFIG,
|
|
174
|
+
normalize: true,
|
|
175
|
+
requiresArg: true
|
|
176
|
+
},
|
|
177
|
+
recursive: {
|
|
178
|
+
description: 'Look for tests in subdirectories',
|
|
179
|
+
group: GROUPS.FILES
|
|
180
|
+
},
|
|
181
|
+
reporter: {
|
|
182
|
+
default: defaults.reporter,
|
|
183
|
+
description: 'Specify reporter to use',
|
|
184
|
+
group: GROUPS.OUTPUT,
|
|
185
|
+
requiresArg: true
|
|
186
|
+
},
|
|
187
|
+
reporters: {
|
|
188
|
+
conflicts: Array.from(ONE_AND_DONE_ARGS),
|
|
189
|
+
description: 'List built-in reporters & exit'
|
|
190
|
+
},
|
|
191
|
+
'reporter-option': {
|
|
192
|
+
coerce: opts =>
|
|
193
|
+
list(opts).reduce((acc, opt) => {
|
|
194
|
+
const pair = opt.split('=');
|
|
195
|
+
|
|
196
|
+
if (pair.length > 2 || !pair.length) {
|
|
197
|
+
throw createInvalidArgumentValueError(
|
|
198
|
+
`invalid reporter option '${opt}'`,
|
|
199
|
+
'--reporter-option',
|
|
200
|
+
opt,
|
|
201
|
+
'expected "key=value" format'
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
acc[pair[0]] = pair.length === 2 ? pair[1] : true;
|
|
206
|
+
return acc;
|
|
207
|
+
}, {}),
|
|
208
|
+
description: 'Reporter-specific options (<k=v,[k1=v1,..]>)',
|
|
209
|
+
group: GROUPS.OUTPUT,
|
|
210
|
+
requiresArg: true
|
|
211
|
+
},
|
|
212
|
+
require: {
|
|
213
|
+
defaultDescription: '(none)',
|
|
214
|
+
description: 'Require module',
|
|
215
|
+
group: GROUPS.FILES,
|
|
216
|
+
requiresArg: true
|
|
217
|
+
},
|
|
218
|
+
retries: {
|
|
219
|
+
description: 'Retry failed tests this many times',
|
|
220
|
+
group: GROUPS.RULES
|
|
221
|
+
},
|
|
222
|
+
slow: {
|
|
223
|
+
default: defaults.slow,
|
|
224
|
+
description: 'Specify "slow" test threshold (in milliseconds)',
|
|
225
|
+
group: GROUPS.RULES
|
|
226
|
+
},
|
|
227
|
+
sort: {
|
|
228
|
+
description: 'Sort test files',
|
|
229
|
+
group: GROUPS.FILES
|
|
230
|
+
},
|
|
231
|
+
timeout: {
|
|
232
|
+
default: defaults.timeout,
|
|
233
|
+
description: 'Specify test timeout threshold (in milliseconds)',
|
|
234
|
+
group: GROUPS.RULES
|
|
235
|
+
},
|
|
236
|
+
ui: {
|
|
237
|
+
default: defaults.ui,
|
|
238
|
+
description: 'Specify user interface',
|
|
239
|
+
group: GROUPS.RULES,
|
|
240
|
+
requiresArg: true
|
|
241
|
+
},
|
|
242
|
+
watch: {
|
|
243
|
+
description: 'Watch files in the current working directory for changes',
|
|
244
|
+
group: GROUPS.FILES
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
.positional('spec', {
|
|
248
|
+
default: ['test'],
|
|
249
|
+
description: 'One or more files, directories, or globs to test',
|
|
250
|
+
type: 'array'
|
|
251
|
+
})
|
|
252
|
+
.check(argv => {
|
|
253
|
+
// "one-and-dones"; let yargs handle help and version
|
|
254
|
+
Object.keys(ONE_AND_DONES).forEach(opt => {
|
|
255
|
+
if (argv[opt]) {
|
|
256
|
+
ONE_AND_DONES[opt].call(null, yargs);
|
|
257
|
+
process.exit();
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// yargs.implies() isn't flexible enough to handle this
|
|
262
|
+
if (argv.invert && !('fgrep' in argv || 'grep' in argv)) {
|
|
263
|
+
throw createMissingArgumentError(
|
|
264
|
+
'"--invert" requires one of "--fgrep <str>" or "--grep <regexp>"',
|
|
265
|
+
'--fgrep|--grep',
|
|
266
|
+
'string|regexp'
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (argv.compilers) {
|
|
271
|
+
throw createUnsupportedError(
|
|
272
|
+
`--compilers is DEPRECATED and no longer supported.
|
|
273
|
+
See https://git.io/vdcSr for migration information.`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// load requires first, because it can impact "plugin" validation
|
|
278
|
+
handleRequires(argv.require);
|
|
279
|
+
validatePlugin(argv, 'reporter', Mocha.reporters);
|
|
280
|
+
validatePlugin(argv, 'ui', Mocha.interfaces);
|
|
281
|
+
|
|
282
|
+
return true;
|
|
283
|
+
})
|
|
284
|
+
.array(types.array)
|
|
285
|
+
.boolean(types.boolean)
|
|
286
|
+
.string(types.string)
|
|
287
|
+
.number(types.number)
|
|
288
|
+
.alias(aliases);
|
|
289
|
+
|
|
290
|
+
exports.handler = argv => {
|
|
291
|
+
debug('post-yargs config', argv);
|
|
292
|
+
const mocha = new Mocha(argv);
|
|
293
|
+
const files = handleFiles(argv);
|
|
294
|
+
|
|
295
|
+
debug('running tests with files', files);
|
|
296
|
+
runMocha(mocha, argv, files);
|
|
297
|
+
};
|