mocha 6.1.1 → 6.2.0
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 +60 -1
- package/bin/_mocha +0 -0
- package/bin/mocha +32 -26
- package/lib/cli/cli.js +8 -3
- package/lib/cli/collect-files.js +85 -0
- package/lib/cli/options.js +24 -10
- package/lib/cli/run-helpers.js +35 -193
- package/lib/cli/run-option-metadata.js +14 -3
- package/lib/cli/run.js +7 -11
- package/lib/cli/watch-run.js +106 -0
- package/lib/mocha.js +10 -3
- package/lib/reporters/base.js +15 -8
- package/lib/reporters/doc.js +14 -10
- package/lib/reporters/dot.js +1 -1
- package/lib/reporters/landing.js +1 -1
- package/lib/reporters/list.js +4 -4
- package/lib/reporters/progress.js +2 -2
- package/lib/reporters/spec.js +7 -7
- package/lib/reporters/xunit.js +1 -1
- package/lib/utils.js +26 -16
- package/mocha.css +0 -1
- package/mocha.js +124 -402
- package/package.json +38 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,67 @@
|
|
|
1
|
+
# 6.2.0 / 2019-07-18
|
|
2
|
+
|
|
3
|
+
## :tada: Enhancements
|
|
4
|
+
|
|
5
|
+
- [#3827](https://github.com/mochajs/mocha/issues/3827): Do not fork child-process if no Node flags are present ([**@boneskull**](https://github.com/boneskull))
|
|
6
|
+
- [#3725](https://github.com/mochajs/mocha/issues/3725): Base reporter store ref to console.log, see [mocha/wiki](https://github.com/mochajs/mocha/wiki/HOW-TO:-Correctly-stub-stdout) ([**@craigtaub**](https://github.com/craigtaub))
|
|
7
|
+
|
|
8
|
+
## :bug: Fixes
|
|
9
|
+
|
|
10
|
+
- [#3942](https://github.com/mochajs/mocha/issues/3942): Fix "No test files found" Error when file is passed via `--file` ([**@gabegorelick**](https://github.com/gabegorelick))
|
|
11
|
+
- [#3914](https://github.com/mochajs/mocha/issues/3914): Modify Mocha constructor to accept options `global` or `globals` ([**@pascalpp**](https://github.com/pascalpp))
|
|
12
|
+
- [#3894](https://github.com/mochajs/mocha/issues/3894): Fix parsing of config files with `_mocha` binary ([**@juergba**](https://github.com/juergba))
|
|
13
|
+
- [#3834](https://github.com/mochajs/mocha/issues/3834): Fix CLI parsing with default values ([**@boneskull**](https://github.com/boneskull), [**@juergba**](https://github.com/juergba))
|
|
14
|
+
- [#3831](https://github.com/mochajs/mocha/issues/3831): Fix `--timeout`/`--slow` string values and duplicate arguments ([**@boneskull**](https://github.com/boneskull), [**@juergba**](https://github.com/juergba))
|
|
15
|
+
|
|
16
|
+
## :book: Documentation
|
|
17
|
+
|
|
18
|
+
- [#3906](https://github.com/mochajs/mocha/issues/3906): Document option to define custom report name for XUnit reporter ([**@pkuczynski**](https://github.com/pkuczynski))
|
|
19
|
+
- [#3889](https://github.com/mochajs/mocha/issues/3889): Adds doc links for mocha-examples ([**@craigtaub**](https://github.com/craigtaub))
|
|
20
|
+
- [#3887](https://github.com/mochajs/mocha/issues/3887): Fix broken links ([**@toyjhlee**](https://github.com/toyjhlee))
|
|
21
|
+
- [#3841](https://github.com/mochajs/mocha/issues/3841): Fix anchors to configuration section ([**@trescube**](https://github.com/trescube))
|
|
22
|
+
|
|
23
|
+
## :mag: Coverage
|
|
24
|
+
|
|
25
|
+
- [#3915](https://github.com/mochajs/mocha/issues/3915), [#3929](https://github.com/mochajs/mocha/issues/3929): Increase tests coverage for `--watch` options ([**@geigerzaehler**](https://github.com/geigerzaehler))
|
|
26
|
+
|
|
27
|
+
## :nut_and_bolt: Other
|
|
28
|
+
|
|
29
|
+
- [#3953](https://github.com/mochajs/mocha/issues/3953): Collect test files later, prepares improvements to the `--watch` mode behavior ([**@geigerzaehler**](https://github.com/geigerzaehler))
|
|
30
|
+
- [#3939](https://github.com/mochajs/mocha/issues/3939): Upgrade for npm audit ([**@boneskull**](https://github.com/boneskull))
|
|
31
|
+
- [#3930](https://github.com/mochajs/mocha/issues/3930): Extract `runWatch` into separate module ([**@geigerzaehler**](https://github.com/geigerzaehler))
|
|
32
|
+
- [#3922](https://github.com/mochajs/mocha/issues/3922): Add `mocha.min.js` file to stacktrace filter ([**@brian-lagerman**](https://github.com/brian-lagerman))
|
|
33
|
+
- [#3919](https://github.com/mochajs/mocha/issues/3919): Update CI config files to use Node-12.x ([**@plroebuck**](https://github.com/plroebuck))
|
|
34
|
+
- [#3892](https://github.com/mochajs/mocha/issues/3892): Rework reporter tests ([**@plroebuck**](https://github.com/plroebuck))
|
|
35
|
+
- [#3872](https://github.com/mochajs/mocha/issues/3872): Rename `--exclude` to `--ignore` and create alias ([**@boneskull**](https://github.com/boneskull))
|
|
36
|
+
- [#3963](https://github.com/mochajs/mocha/issues/3963): Hide stacktrace when cli args are missing ([**@outsideris**](https://github.com/outsideris))
|
|
37
|
+
- [#3956](https://github.com/mochajs/mocha/issues/3956): Do not redeclare variable in docs array example ([**@DanielRuf**](https://github.com/DanielRuf))
|
|
38
|
+
- [#3957](https://github.com/mochajs/mocha/issues/3957): Remove duplicate line-height property in `mocha.css` ([**@DanielRuf**](https://github.com/DanielRuf))
|
|
39
|
+
- [#3960](https://github.com/mochajs/mocha/issues/3960): Don't re-initialize grep option on watch re-run ([**@geigerzaehler**](https://github.com/geigerzaehler))
|
|
40
|
+
|
|
41
|
+
# 6.1.4 / 2019-04-18
|
|
42
|
+
|
|
43
|
+
## :lock: Security Fixes
|
|
44
|
+
|
|
45
|
+
- [#3877](https://github.com/mochajs/mocha/issues/3877): Upgrade [js-yaml](https://npm.im/js-yaml), addressing [code injection vulnerability](https://www.npmjs.com/advisories/813) ([**@bjornstar**](https://github.com/bjornstar))
|
|
46
|
+
|
|
47
|
+
# 6.1.3 / 2019-04-11
|
|
48
|
+
|
|
49
|
+
## :bug: Fixes
|
|
50
|
+
|
|
51
|
+
- [#3863](https://github.com/mochajs/mocha/issues/3863): Fix `yargs`-related global scope pollution ([**@inukshuk**](https://github.com/inukshuk))
|
|
52
|
+
- [#3869](https://github.com/mochajs/mocha/issues/3869): Fix failure when installed w/ `pnpm` ([**@boneskull**](https://github.com/boneskull))
|
|
53
|
+
|
|
54
|
+
# 6.1.2 / 2019-04-08
|
|
55
|
+
|
|
56
|
+
## :bug: Fixes
|
|
57
|
+
|
|
58
|
+
- [#3867](https://github.com/mochajs/mocha/issues/3867): Re-publish v6.1.1 from POSIX OS to avoid dropped executable flags ([**@boneskull**](https://github.com/boneskull))
|
|
59
|
+
|
|
1
60
|
# 6.1.1 / 2019-04-07
|
|
2
61
|
|
|
3
62
|
## :bug: Fixes
|
|
4
63
|
|
|
5
|
-
- Fix Windows End-of-Line publishing issue
|
|
64
|
+
- [#3866](https://github.com/mochajs/mocha/issues/3866): Fix Windows End-of-Line publishing issue ([**@juergba**](https://github.com/juergba) & [**@cspotcode**](https://github.com/cspotcode))
|
|
6
65
|
|
|
7
66
|
# 6.1.0 / 2019-04-07
|
|
8
67
|
|
package/bin/_mocha
CHANGED
|
File without changes
|
package/bin/mocha
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* This wrapper executable checks for known node flags and appends them when found,
|
|
6
|
+
* This wrapper executable checks for known node flags and appends them when found,
|
|
7
|
+
* before invoking the "real" executable (`lib/cli/cli.js`)
|
|
7
8
|
*
|
|
8
9
|
* @module bin/mocha
|
|
9
10
|
* @private
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
const {deprecate, warn} = require('../lib/utils');
|
|
13
|
-
const {spawn} = require('child_process');
|
|
14
14
|
const {loadOptions} = require('../lib/cli/options');
|
|
15
15
|
const {
|
|
16
16
|
unparseNodeFlags,
|
|
@@ -22,7 +22,6 @@ const debug = require('debug')('mocha:cli:mocha');
|
|
|
22
22
|
const {aliases} = require('../lib/cli/run-option-metadata');
|
|
23
23
|
const nodeEnv = require('node-environment-flags');
|
|
24
24
|
|
|
25
|
-
const mochaPath = require.resolve('./_mocha');
|
|
26
25
|
const mochaArgs = {};
|
|
27
26
|
const nodeArgs = {};
|
|
28
27
|
|
|
@@ -118,32 +117,39 @@ if (nodeArgs.gc) {
|
|
|
118
117
|
delete nodeArgs.gc;
|
|
119
118
|
}
|
|
120
119
|
|
|
121
|
-
|
|
120
|
+
if (Object.keys(nodeArgs).length) {
|
|
121
|
+
const {spawn} = require('child_process');
|
|
122
|
+
const mochaPath = require.resolve('../lib/cli/cli.js');
|
|
122
123
|
|
|
123
|
-
|
|
124
|
-
unparseNodeFlags(nodeArgs),
|
|
125
|
-
mochaPath,
|
|
126
|
-
unparse(mochaArgs, {alias: aliases})
|
|
127
|
-
);
|
|
124
|
+
debug('final node args', nodeArgs);
|
|
128
125
|
|
|
129
|
-
|
|
126
|
+
const args = [].concat(
|
|
127
|
+
unparseNodeFlags(nodeArgs),
|
|
128
|
+
mochaPath,
|
|
129
|
+
unparse(mochaArgs, {alias: aliases})
|
|
130
|
+
);
|
|
130
131
|
|
|
131
|
-
|
|
132
|
-
stdio: 'inherit'
|
|
133
|
-
});
|
|
132
|
+
debug(`exec ${process.execPath} w/ args:`, args);
|
|
134
133
|
|
|
135
|
-
proc.
|
|
136
|
-
|
|
137
|
-
if (signal) {
|
|
138
|
-
process.kill(process.pid, signal);
|
|
139
|
-
} else {
|
|
140
|
-
process.exit(code);
|
|
141
|
-
}
|
|
134
|
+
const proc = spawn(process.execPath, args, {
|
|
135
|
+
stdio: 'inherit'
|
|
142
136
|
});
|
|
143
|
-
});
|
|
144
137
|
|
|
145
|
-
|
|
146
|
-
process.on('
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
138
|
+
proc.on('exit', (code, signal) => {
|
|
139
|
+
process.on('exit', () => {
|
|
140
|
+
if (signal) {
|
|
141
|
+
process.kill(process.pid, signal);
|
|
142
|
+
} else {
|
|
143
|
+
process.exit(code);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// terminate children.
|
|
149
|
+
process.on('SIGINT', () => {
|
|
150
|
+
proc.kill('SIGINT'); // calls runner.abort()
|
|
151
|
+
proc.kill('SIGTERM'); // if that didn't work, we're probably in an infinite loop, so make it die.
|
|
152
|
+
});
|
|
153
|
+
} else {
|
|
154
|
+
require('../lib/cli/cli').main(unparse(mochaArgs, {alias: aliases}));
|
|
155
|
+
}
|
package/lib/cli/cli.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
1
3
|
'use strict';
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -11,7 +13,7 @@
|
|
|
11
13
|
|
|
12
14
|
const debug = require('debug')('mocha:cli:cli');
|
|
13
15
|
const symbols = require('log-symbols');
|
|
14
|
-
const yargs = require('yargs');
|
|
16
|
+
const yargs = require('yargs/yargs');
|
|
15
17
|
const path = require('path');
|
|
16
18
|
const {loadOptions, YARGS_PARSER_CONFIG} = require('./options');
|
|
17
19
|
const commands = require('./commands');
|
|
@@ -32,7 +34,9 @@ exports.main = (argv = process.argv.slice(2)) => {
|
|
|
32
34
|
|
|
33
35
|
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
var args = loadOptions(argv);
|
|
38
|
+
|
|
39
|
+
yargs()
|
|
36
40
|
.scriptName('mocha')
|
|
37
41
|
.command(commands.run)
|
|
38
42
|
.command(commands.init)
|
|
@@ -60,7 +64,8 @@ exports.main = (argv = process.argv.slice(2)) => {
|
|
|
60
64
|
`
|
|
61
65
|
)
|
|
62
66
|
.parserConfiguration(YARGS_PARSER_CONFIG)
|
|
63
|
-
.
|
|
67
|
+
.config(args)
|
|
68
|
+
.parse(args._);
|
|
64
69
|
};
|
|
65
70
|
|
|
66
71
|
// allow direct execution
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const ansi = require('ansi-colors');
|
|
5
|
+
const debug = require('debug')('mocha:cli:run:helpers');
|
|
6
|
+
const minimatch = require('minimatch');
|
|
7
|
+
const utils = require('../utils');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Exports a function that collects test files from CLI parameters.
|
|
11
|
+
* @see module:lib/cli/run-helpers
|
|
12
|
+
* @see module:lib/cli/watch-run
|
|
13
|
+
* @module
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Smash together an array of test files in the correct order
|
|
19
|
+
* @param {Object} opts - Options
|
|
20
|
+
* @param {string[]} opts.extension - File extensions to use
|
|
21
|
+
* @param {string[]} opts.spec - Files, dirs, globs to run
|
|
22
|
+
* @param {string[]} opts.ignore - Files, dirs, globs to ignore
|
|
23
|
+
* @param {string[]} opts.file - List of additional files to include
|
|
24
|
+
* @param {boolean} opts.recursive - Find files recursively
|
|
25
|
+
* @param {boolean} opts.sort - Sort test files
|
|
26
|
+
* @returns {string[]} List of files to test
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
module.exports = ({ignore, extension, file, recursive, sort, spec} = {}) => {
|
|
30
|
+
let files = [];
|
|
31
|
+
const unmatched = [];
|
|
32
|
+
spec.forEach(arg => {
|
|
33
|
+
let newFiles;
|
|
34
|
+
try {
|
|
35
|
+
newFiles = utils.lookupFiles(arg, extension, recursive);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') {
|
|
38
|
+
unmatched.push({message: err.message, pattern: err.pattern});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (typeof newFiles !== 'undefined') {
|
|
46
|
+
if (typeof newFiles === 'string') {
|
|
47
|
+
newFiles = [newFiles];
|
|
48
|
+
}
|
|
49
|
+
newFiles = newFiles.filter(fileName =>
|
|
50
|
+
ignore.every(pattern => !minimatch(fileName, pattern))
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
files = files.concat(newFiles);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const fileArgs = file.map(filepath => path.resolve(filepath));
|
|
58
|
+
files = files.map(filepath => path.resolve(filepath));
|
|
59
|
+
|
|
60
|
+
// ensure we don't sort the stuff from fileArgs; order is important!
|
|
61
|
+
if (sort) {
|
|
62
|
+
files.sort();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// add files given through --file to be ran first
|
|
66
|
+
files = fileArgs.concat(files);
|
|
67
|
+
debug('files (in order): ', files);
|
|
68
|
+
|
|
69
|
+
if (!files.length) {
|
|
70
|
+
// give full message details when only 1 file is missing
|
|
71
|
+
const noneFoundMsg =
|
|
72
|
+
unmatched.length === 1
|
|
73
|
+
? `Error: No test files found: ${JSON.stringify(unmatched[0].pattern)}` // stringify to print escaped characters raw
|
|
74
|
+
: 'Error: No test files found';
|
|
75
|
+
console.error(ansi.red(noneFoundMsg));
|
|
76
|
+
process.exit(1);
|
|
77
|
+
} else {
|
|
78
|
+
// print messages as an warning
|
|
79
|
+
unmatched.forEach(warning => {
|
|
80
|
+
console.warn(ansi.yellow(`Warning: ${warning.message}`));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return files;
|
|
85
|
+
};
|
package/lib/cli/options.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
const fs = require('fs');
|
|
10
|
+
const ansi = require('ansi-colors');
|
|
10
11
|
const yargsParser = require('yargs-parser');
|
|
11
12
|
const {types, aliases} = require('./run-option-metadata');
|
|
12
13
|
const {ONE_AND_DONE_ARGS} = require('./one-and-dones');
|
|
@@ -16,7 +17,6 @@ const {loadConfig, findConfig} = require('./config');
|
|
|
16
17
|
const findUp = require('find-up');
|
|
17
18
|
const {deprecate} = require('../utils');
|
|
18
19
|
const debug = require('debug')('mocha:cli:options');
|
|
19
|
-
const {createMissingArgumentError} = require('../errors');
|
|
20
20
|
const {isNodeFlag} = require('./node-flags');
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -54,15 +54,26 @@ const configuration = Object.assign({}, YARGS_PARSER_CONFIG, {
|
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* This is a really fancy way to
|
|
58
|
-
* options
|
|
57
|
+
* This is a really fancy way to:
|
|
58
|
+
* - ensure unique values for `array`-type options
|
|
59
|
+
* - use its array's last element for `boolean`/`number`/`string`- options given multiple times
|
|
59
60
|
* This is passed as the `coerce` option to `yargs-parser`
|
|
60
61
|
* @private
|
|
61
62
|
* @ignore
|
|
62
63
|
*/
|
|
63
|
-
const coerceOpts =
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const coerceOpts = Object.assign(
|
|
65
|
+
types.array.reduce(
|
|
66
|
+
(acc, arg) =>
|
|
67
|
+
Object.assign(acc, {[arg]: v => Array.from(new Set(list(v)))}),
|
|
68
|
+
{}
|
|
69
|
+
),
|
|
70
|
+
types.boolean
|
|
71
|
+
.concat(types.string, types.number)
|
|
72
|
+
.reduce(
|
|
73
|
+
(acc, arg) =>
|
|
74
|
+
Object.assign(acc, {[arg]: v => (Array.isArray(v) ? v.pop() : v)}),
|
|
75
|
+
{}
|
|
76
|
+
)
|
|
66
77
|
);
|
|
67
78
|
|
|
68
79
|
/**
|
|
@@ -80,11 +91,12 @@ const nargOpts = types.array
|
|
|
80
91
|
/**
|
|
81
92
|
* Wrapper around `yargs-parser` which applies our settings
|
|
82
93
|
* @param {string|string[]} args - Arguments to parse
|
|
94
|
+
* @param {Object} defaultValues - Default values of mocharc.json
|
|
83
95
|
* @param {...Object} configObjects - `configObjects` for yargs-parser
|
|
84
96
|
* @private
|
|
85
97
|
* @ignore
|
|
86
98
|
*/
|
|
87
|
-
const parse = (args = [], ...configObjects) => {
|
|
99
|
+
const parse = (args = [], defaultValues = {}, ...configObjects) => {
|
|
88
100
|
// save node-specific args for special handling.
|
|
89
101
|
// 1. when these args have a "=" they should be considered to have values
|
|
90
102
|
// 2. if they don't, they just boolean flags
|
|
@@ -109,6 +121,7 @@ const parse = (args = [], ...configObjects) => {
|
|
|
109
121
|
const result = yargsParser.detailed(args, {
|
|
110
122
|
configuration,
|
|
111
123
|
configObjects,
|
|
124
|
+
default: defaultValues,
|
|
112
125
|
coerce: coerceOpts,
|
|
113
126
|
narg: nargOpts,
|
|
114
127
|
alias: aliases,
|
|
@@ -118,7 +131,8 @@ const parse = (args = [], ...configObjects) => {
|
|
|
118
131
|
boolean: types.boolean.concat(nodeArgs.map(pair => pair[0]))
|
|
119
132
|
});
|
|
120
133
|
if (result.error) {
|
|
121
|
-
|
|
134
|
+
console.error(ansi.red(`Error: ${result.error.message}`));
|
|
135
|
+
process.exit(1);
|
|
122
136
|
}
|
|
123
137
|
|
|
124
138
|
// reapply "=" arg values from above
|
|
@@ -324,11 +338,11 @@ const loadOptions = (argv = []) => {
|
|
|
324
338
|
|
|
325
339
|
args = parse(
|
|
326
340
|
args._,
|
|
341
|
+
mocharc,
|
|
327
342
|
args,
|
|
328
343
|
rcConfig || {},
|
|
329
344
|
pkgConfig || {},
|
|
330
|
-
optsConfig || {}
|
|
331
|
-
mocharc
|
|
345
|
+
optsConfig || {}
|
|
332
346
|
);
|
|
333
347
|
|
|
334
348
|
// recombine positional arguments and "spec"
|
package/lib/cli/run-helpers.js
CHANGED
|
@@ -9,15 +9,14 @@
|
|
|
9
9
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const path = require('path');
|
|
12
|
-
const ansi = require('ansi-colors');
|
|
13
12
|
const debug = require('debug')('mocha:cli:run:helpers');
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const Mocha = require('../mocha');
|
|
17
|
-
const utils = require('../utils');
|
|
13
|
+
const watchRun = require('./watch-run');
|
|
14
|
+
const collectFiles = require('./collect-files');
|
|
18
15
|
|
|
19
16
|
const cwd = (exports.cwd = process.cwd());
|
|
20
17
|
|
|
18
|
+
exports.watchRun = watchRun;
|
|
19
|
+
|
|
21
20
|
/**
|
|
22
21
|
* Exits Mocha when tests + code under test has finished execution (default)
|
|
23
22
|
* @param {number} code - Exit code; typically # of failures
|
|
@@ -65,32 +64,6 @@ const exitMocha = code => {
|
|
|
65
64
|
done();
|
|
66
65
|
};
|
|
67
66
|
|
|
68
|
-
/**
|
|
69
|
-
* Hide the cursor.
|
|
70
|
-
* @ignore
|
|
71
|
-
* @private
|
|
72
|
-
*/
|
|
73
|
-
const hideCursor = () => {
|
|
74
|
-
process.stdout.write('\u001b[?25l');
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Show the cursor.
|
|
79
|
-
* @ignore
|
|
80
|
-
* @private
|
|
81
|
-
*/
|
|
82
|
-
const showCursor = () => {
|
|
83
|
-
process.stdout.write('\u001b[?25h');
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Stop cursor business
|
|
88
|
-
* @private
|
|
89
|
-
*/
|
|
90
|
-
const stop = () => {
|
|
91
|
-
process.stdout.write('\u001b[2K');
|
|
92
|
-
};
|
|
93
|
-
|
|
94
67
|
/**
|
|
95
68
|
* Coerce a comma-delimited string (or array thereof) into a flattened array of
|
|
96
69
|
* strings
|
|
@@ -119,185 +92,54 @@ exports.handleRequires = (requires = []) => {
|
|
|
119
92
|
};
|
|
120
93
|
|
|
121
94
|
/**
|
|
122
|
-
*
|
|
123
|
-
* @param {Object} [opts] - Options
|
|
124
|
-
* @param {string[]} [opts.extension] - File extensions to use
|
|
125
|
-
* @param {string[]} [opts.spec] - Files, dirs, globs to run
|
|
126
|
-
* @param {string[]} [opts.exclude] - Files, dirs, globs to exclude
|
|
127
|
-
* @param {boolean} [opts.recursive=false] - Find files recursively
|
|
128
|
-
* @param {boolean} [opts.sort=false] - Sort test files
|
|
129
|
-
* @returns {string[]} List of files to test
|
|
130
|
-
* @private
|
|
131
|
-
*/
|
|
132
|
-
exports.handleFiles = ({
|
|
133
|
-
exclude = [],
|
|
134
|
-
extension = [],
|
|
135
|
-
file = [],
|
|
136
|
-
recursive = false,
|
|
137
|
-
sort = false,
|
|
138
|
-
spec = []
|
|
139
|
-
} = {}) => {
|
|
140
|
-
let files = [];
|
|
141
|
-
const unmatched = [];
|
|
142
|
-
spec.forEach(arg => {
|
|
143
|
-
let newFiles;
|
|
144
|
-
try {
|
|
145
|
-
newFiles = utils.lookupFiles(arg, extension, recursive);
|
|
146
|
-
} catch (err) {
|
|
147
|
-
if (err.code === 'ERR_MOCHA_NO_FILES_MATCH_PATTERN') {
|
|
148
|
-
unmatched.push({message: err.message, pattern: err.pattern});
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
throw err;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (typeof newFiles !== 'undefined') {
|
|
156
|
-
if (typeof newFiles === 'string') {
|
|
157
|
-
newFiles = [newFiles];
|
|
158
|
-
}
|
|
159
|
-
newFiles = newFiles.filter(fileName =>
|
|
160
|
-
exclude.every(pattern => !minimatch(fileName, pattern))
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
files = files.concat(newFiles);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
if (!files.length) {
|
|
168
|
-
// give full message details when only 1 file is missing
|
|
169
|
-
const noneFoundMsg =
|
|
170
|
-
unmatched.length === 1
|
|
171
|
-
? `Error: No test files found: ${JSON.stringify(unmatched[0].pattern)}` // stringify to print escaped characters raw
|
|
172
|
-
: 'Error: No test files found';
|
|
173
|
-
console.error(ansi.red(noneFoundMsg));
|
|
174
|
-
process.exit(1);
|
|
175
|
-
} else {
|
|
176
|
-
// print messages as an warning
|
|
177
|
-
unmatched.forEach(warning => {
|
|
178
|
-
console.warn(ansi.yellow(`Warning: ${warning.message}`));
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const fileArgs = file.map(filepath => path.resolve(filepath));
|
|
183
|
-
files = files.map(filepath => path.resolve(filepath));
|
|
184
|
-
|
|
185
|
-
// ensure we don't sort the stuff from fileArgs; order is important!
|
|
186
|
-
if (sort) {
|
|
187
|
-
files.sort();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// add files given through --file to be ran first
|
|
191
|
-
files = fileArgs.concat(files);
|
|
192
|
-
debug('files (in order): ', files);
|
|
193
|
-
return files;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Give Mocha files and tell it to run
|
|
95
|
+
* Collect test files and run mocha instance.
|
|
198
96
|
* @param {Mocha} mocha - Mocha instance
|
|
199
|
-
* @param {Options} [opts] -
|
|
200
|
-
* @param {string[]} [opts.files] - List of test files
|
|
97
|
+
* @param {Options} [opts] - Command line options
|
|
201
98
|
* @param {boolean} [opts.exit] - Whether or not to force-exit after tests are complete
|
|
99
|
+
* @param {Object} fileCollectParams - Parameters that control test
|
|
100
|
+
* file collection. See `lib/cli/collect-files.js`.
|
|
202
101
|
* @returns {Runner}
|
|
203
102
|
* @private
|
|
204
103
|
*/
|
|
205
|
-
exports.singleRun = (mocha, {
|
|
104
|
+
exports.singleRun = (mocha, {exit}, fileCollectParams) => {
|
|
105
|
+
const files = collectFiles(fileCollectParams);
|
|
106
|
+
debug('running tests with files', files);
|
|
206
107
|
mocha.files = files;
|
|
207
108
|
return mocha.run(exit ? exitMocha : exitMochaLater);
|
|
208
109
|
};
|
|
209
110
|
|
|
210
111
|
/**
|
|
211
|
-
*
|
|
112
|
+
* Actually run tests
|
|
212
113
|
* @param {Mocha} mocha - Mocha instance
|
|
213
|
-
* @param {Object}
|
|
214
|
-
* @param {string[]} [opts.extension] - List of extensions to watch
|
|
215
|
-
* @param {string|RegExp} [opts.grep] - Grep for test titles
|
|
216
|
-
* @param {string} [opts.ui=bdd] - User interface
|
|
217
|
-
* @param {string[]} [files] - Array of test files
|
|
114
|
+
* @param {Object} opts - Command line options
|
|
218
115
|
* @private
|
|
219
116
|
*/
|
|
220
|
-
exports.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
runAgain = false;
|
|
241
|
-
runner = mocha.run(() => {
|
|
242
|
-
runner = null;
|
|
243
|
-
if (runAgain) {
|
|
244
|
-
rerun();
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
} catch (e) {
|
|
248
|
-
console.log(e.stack);
|
|
249
|
-
}
|
|
117
|
+
exports.runMocha = (mocha, options) => {
|
|
118
|
+
const {
|
|
119
|
+
watch = false,
|
|
120
|
+
extension = [],
|
|
121
|
+
ui = 'bdd',
|
|
122
|
+
exit = false,
|
|
123
|
+
ignore = [],
|
|
124
|
+
file = [],
|
|
125
|
+
recursive = false,
|
|
126
|
+
sort = false,
|
|
127
|
+
spec = []
|
|
128
|
+
} = options;
|
|
129
|
+
|
|
130
|
+
const fileCollectParams = {
|
|
131
|
+
ignore,
|
|
132
|
+
extension,
|
|
133
|
+
file,
|
|
134
|
+
recursive,
|
|
135
|
+
sort,
|
|
136
|
+
spec
|
|
250
137
|
};
|
|
251
138
|
|
|
252
|
-
const purge = () => {
|
|
253
|
-
watchFiles.forEach(Mocha.unloadFile);
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
loadAndRun();
|
|
257
|
-
|
|
258
|
-
const rerun = () => {
|
|
259
|
-
purge();
|
|
260
|
-
stop();
|
|
261
|
-
if (!grep) {
|
|
262
|
-
mocha.grep(null);
|
|
263
|
-
}
|
|
264
|
-
mocha.suite = mocha.suite.clone();
|
|
265
|
-
mocha.suite.ctx = new Context();
|
|
266
|
-
mocha.ui(ui);
|
|
267
|
-
loadAndRun();
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
utils.watch(watchFiles, () => {
|
|
271
|
-
runAgain = true;
|
|
272
|
-
if (runner) {
|
|
273
|
-
runner.abort();
|
|
274
|
-
} else {
|
|
275
|
-
rerun();
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Actually run tests
|
|
282
|
-
* @param {Mocha} mocha - Mocha instance
|
|
283
|
-
* @param {Object} [opts] - Options
|
|
284
|
-
* @param {boolean} [opts.watch=false] - Enable watch mode
|
|
285
|
-
* @param {string[]} [opts.extension] - List of extensions to watch
|
|
286
|
-
* @param {string|RegExp} [opts.grep] - Grep for test titles
|
|
287
|
-
* @param {string} [opts.ui=bdd] - User interface
|
|
288
|
-
* @param {boolean} [opts.exit=false] - Force-exit Mocha when tests done
|
|
289
|
-
* @param {string[]} [files] - Array of test files
|
|
290
|
-
* @private
|
|
291
|
-
*/
|
|
292
|
-
exports.runMocha = (
|
|
293
|
-
mocha,
|
|
294
|
-
{watch = false, extension = ['js'], grep = '', ui = 'bdd', exit = false} = {},
|
|
295
|
-
files = []
|
|
296
|
-
) => {
|
|
297
139
|
if (watch) {
|
|
298
|
-
|
|
140
|
+
watchRun(mocha, {ui}, fileCollectParams);
|
|
299
141
|
} else {
|
|
300
|
-
exports.singleRun(mocha, {
|
|
142
|
+
exports.singleRun(mocha, {exit}, fileCollectParams);
|
|
301
143
|
}
|
|
302
144
|
};
|
|
303
145
|
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
*/
|
|
15
15
|
exports.types = {
|
|
16
16
|
array: [
|
|
17
|
-
'exclude',
|
|
18
17
|
'extension',
|
|
19
18
|
'file',
|
|
20
19
|
'global',
|
|
20
|
+
'ignore',
|
|
21
21
|
'require',
|
|
22
22
|
'reporter-option',
|
|
23
23
|
'spec'
|
|
@@ -44,8 +44,18 @@ exports.types = {
|
|
|
44
44
|
'sort',
|
|
45
45
|
'watch'
|
|
46
46
|
],
|
|
47
|
-
number: ['retries'
|
|
48
|
-
string: [
|
|
47
|
+
number: ['retries'],
|
|
48
|
+
string: [
|
|
49
|
+
'config',
|
|
50
|
+
'fgrep',
|
|
51
|
+
'grep',
|
|
52
|
+
'opts',
|
|
53
|
+
'package',
|
|
54
|
+
'reporter',
|
|
55
|
+
'ui',
|
|
56
|
+
'slow',
|
|
57
|
+
'timeout'
|
|
58
|
+
]
|
|
49
59
|
};
|
|
50
60
|
|
|
51
61
|
/**
|
|
@@ -63,6 +73,7 @@ exports.aliases = {
|
|
|
63
73
|
global: ['globals'],
|
|
64
74
|
grep: ['g'],
|
|
65
75
|
growl: ['G'],
|
|
76
|
+
ignore: ['exclude'],
|
|
66
77
|
invert: ['i'],
|
|
67
78
|
'no-colors': ['C'],
|
|
68
79
|
reporter: ['R'],
|