mocha 10.5.0 → 10.5.1
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/lib/cli/collect-files.js +49 -7
- package/lib/cli/run-helpers.js +47 -6
- package/lib/cli/watch-run.js +2 -2
- package/mocha.js +2 -2
- package/package.json +1 -1
package/lib/cli/collect-files.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const fs = require('fs');
|
|
3
4
|
const path = require('path');
|
|
4
5
|
const ansi = require('ansi-colors');
|
|
5
6
|
const debug = require('debug')('mocha:cli:run:helpers');
|
|
@@ -19,7 +20,7 @@ const {castArray} = require('../utils');
|
|
|
19
20
|
/**
|
|
20
21
|
* Smash together an array of test files in the correct order
|
|
21
22
|
* @param {FileCollectionOptions} [opts] - Options
|
|
22
|
-
* @returns {
|
|
23
|
+
* @returns {FileCollectionResponse} An object containing a list of files to test and unmatched files.
|
|
23
24
|
* @private
|
|
24
25
|
*/
|
|
25
26
|
module.exports = ({
|
|
@@ -30,7 +31,7 @@ module.exports = ({
|
|
|
30
31
|
sort,
|
|
31
32
|
spec
|
|
32
33
|
} = {}) => {
|
|
33
|
-
const
|
|
34
|
+
const unmatchedSpecFiles = [];
|
|
34
35
|
const specFiles = spec.reduce((specFiles, arg) => {
|
|
35
36
|
try {
|
|
36
37
|
const moreSpecFiles = castArray(lookupFiles(arg, extension, recursive))
|
|
@@ -44,7 +45,7 @@ module.exports = ({
|
|
|
44
45
|
return [...specFiles, ...moreSpecFiles];
|
|
45
46
|
} catch (err) {
|
|
46
47
|
if (err.code === NO_FILES_MATCH_PATTERN) {
|
|
47
|
-
|
|
48
|
+
unmatchedSpecFiles.push({message: err.message, pattern: err.pattern});
|
|
48
49
|
return specFiles;
|
|
49
50
|
}
|
|
50
51
|
|
|
@@ -52,6 +53,27 @@ module.exports = ({
|
|
|
52
53
|
}
|
|
53
54
|
}, []);
|
|
54
55
|
|
|
56
|
+
// check that each file passed in to --file exists
|
|
57
|
+
|
|
58
|
+
const unmatchedFiles = [];
|
|
59
|
+
fileArgs.forEach(file => {
|
|
60
|
+
const fileAbsolutePath = path.resolve(file);
|
|
61
|
+
try {
|
|
62
|
+
// Used instead of fs.existsSync to ensure that file-ending less files are still resolved correctly
|
|
63
|
+
require.resolve(fileAbsolutePath);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
if (err.code === 'MODULE_NOT_FOUND') {
|
|
66
|
+
unmatchedFiles.push({
|
|
67
|
+
pattern: file,
|
|
68
|
+
absolutePath: fileAbsolutePath
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
55
77
|
// ensure we don't sort the stuff from fileArgs; order is important!
|
|
56
78
|
if (sort) {
|
|
57
79
|
specFiles.sort();
|
|
@@ -67,19 +89,24 @@ module.exports = ({
|
|
|
67
89
|
if (!files.length) {
|
|
68
90
|
// give full message details when only 1 file is missing
|
|
69
91
|
const noneFoundMsg =
|
|
70
|
-
|
|
71
|
-
? `Error: No test files found: ${JSON.stringify(
|
|
92
|
+
unmatchedSpecFiles.length === 1
|
|
93
|
+
? `Error: No test files found: ${JSON.stringify(
|
|
94
|
+
unmatchedSpecFiles[0].pattern
|
|
95
|
+
)}` // stringify to print escaped characters raw
|
|
72
96
|
: 'Error: No test files found';
|
|
73
97
|
console.error(ansi.red(noneFoundMsg));
|
|
74
98
|
process.exit(1);
|
|
75
99
|
} else {
|
|
76
100
|
// print messages as a warning
|
|
77
|
-
|
|
101
|
+
unmatchedSpecFiles.forEach(warning => {
|
|
78
102
|
console.warn(ansi.yellow(`Warning: ${warning.message}`));
|
|
79
103
|
});
|
|
80
104
|
}
|
|
81
105
|
|
|
82
|
-
return
|
|
106
|
+
return {
|
|
107
|
+
files,
|
|
108
|
+
unmatchedFiles
|
|
109
|
+
};
|
|
83
110
|
};
|
|
84
111
|
|
|
85
112
|
/**
|
|
@@ -93,3 +120,18 @@ module.exports = ({
|
|
|
93
120
|
* @property {boolean} recursive - Find files recursively
|
|
94
121
|
* @property {boolean} sort - Sort test files
|
|
95
122
|
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Diagnostic object containing unmatched files
|
|
126
|
+
* @typedef {Object} UnmatchedFile -
|
|
127
|
+
* @property {string} absolutePath - A list of unmatched files derived from the file arguments passed in.
|
|
128
|
+
* @property {string} pattern - A list of unmatched files derived from the file arguments passed in.
|
|
129
|
+
*
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Response object containing a list of files to test and unmatched files.
|
|
134
|
+
* @typedef {Object} FileCollectionResponse
|
|
135
|
+
* @property {string[]} files - A list of files to test
|
|
136
|
+
* @property {UnmatchedFile[]} unmatchedFiles - A list of unmatched files derived from the file arguments passed in.
|
|
137
|
+
*/
|
package/lib/cli/run-helpers.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const path = require('path');
|
|
12
|
+
const ansi = require('ansi-colors');
|
|
12
13
|
const debug = require('debug')('mocha:cli:run:helpers');
|
|
13
14
|
const {watchRun, watchParallelRun} = require('./watch-run');
|
|
14
15
|
const collectFiles = require('./collect-files');
|
|
@@ -16,6 +17,7 @@ const {format} = require('util');
|
|
|
16
17
|
const {createInvalidLegacyPluginError} = require('../errors');
|
|
17
18
|
const {requireOrImport} = require('../nodejs/esm-utils');
|
|
18
19
|
const PluginLoader = require('../plugin-loader');
|
|
20
|
+
const {UnmatchedFile} = require('./collect-files');
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Exits Mocha when tests + code under test has finished execution (default)
|
|
@@ -106,6 +108,32 @@ exports.handleRequires = async (requires = [], {ignoredPlugins = []} = {}) => {
|
|
|
106
108
|
return plugins;
|
|
107
109
|
};
|
|
108
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Logs errors and exits the app if unmatched files exist
|
|
113
|
+
* @param {Mocha} mocha - Mocha instance
|
|
114
|
+
* @param {UnmatchedFile} unmatchedFiles - object containing unmatched file paths
|
|
115
|
+
* @returns {Promise<Runner>}
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
const handleUnmatchedFiles = (mocha, unmatchedFiles) => {
|
|
119
|
+
if (unmatchedFiles.length === 0) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
unmatchedFiles.forEach(({pattern, absolutePath}) => {
|
|
124
|
+
console.error(
|
|
125
|
+
ansi.yellow(
|
|
126
|
+
`Warning: Cannot find any files matching pattern "${pattern}" at the absolute path "${absolutePath}"`
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
console.log(
|
|
131
|
+
'No test file(s) found with the given pattern, exiting with code 1'
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return mocha.run(exitMocha(1));
|
|
135
|
+
};
|
|
136
|
+
|
|
109
137
|
/**
|
|
110
138
|
* Collect and load test files, then run mocha instance.
|
|
111
139
|
* @param {Mocha} mocha - Mocha instance
|
|
@@ -117,9 +145,14 @@ exports.handleRequires = async (requires = [], {ignoredPlugins = []} = {}) => {
|
|
|
117
145
|
* @private
|
|
118
146
|
*/
|
|
119
147
|
const singleRun = async (mocha, {exit}, fileCollectParams) => {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
148
|
+
const fileCollectionObj = collectFiles(fileCollectParams);
|
|
149
|
+
|
|
150
|
+
if (fileCollectionObj.unmatchedFiles.length > 0) {
|
|
151
|
+
return handleUnmatchedFiles(mocha, fileCollectionObj.unmatchedFiles);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
debug('single run with %d file(s)', fileCollectionObj.files.length);
|
|
155
|
+
mocha.files = fileCollectionObj.files;
|
|
123
156
|
|
|
124
157
|
// handles ESM modules
|
|
125
158
|
await mocha.loadFilesAsync();
|
|
@@ -140,9 +173,17 @@ const singleRun = async (mocha, {exit}, fileCollectParams) => {
|
|
|
140
173
|
* @private
|
|
141
174
|
*/
|
|
142
175
|
const parallelRun = async (mocha, options, fileCollectParams) => {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
176
|
+
const fileCollectionObj = collectFiles(fileCollectParams);
|
|
177
|
+
|
|
178
|
+
if (fileCollectionObj.unmatchedFiles.length > 0) {
|
|
179
|
+
return handleUnmatchedFiles(mocha, fileCollectionObj.unmatchedFiles);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
debug(
|
|
183
|
+
'executing %d test file(s) in parallel mode',
|
|
184
|
+
fileCollectionObj.files.length
|
|
185
|
+
);
|
|
186
|
+
mocha.files = fileCollectionObj.files;
|
|
146
187
|
|
|
147
188
|
// note that we DO NOT load any files here; this is handled by the worker
|
|
148
189
|
return mocha.run(options.exit ? exitMocha : exitMochaLater);
|
package/lib/cli/watch-run.js
CHANGED
|
@@ -58,7 +58,7 @@ exports.watchParallelRun = (
|
|
|
58
58
|
newMocha.suite.ctx = new Context();
|
|
59
59
|
|
|
60
60
|
// reset the list of files
|
|
61
|
-
newMocha.files = collectFiles(fileCollectParams);
|
|
61
|
+
newMocha.files = collectFiles(fileCollectParams).files;
|
|
62
62
|
|
|
63
63
|
// because we've swapped out the root suite (see the `run` inner function
|
|
64
64
|
// in `createRerunner`), we need to call `mocha.ui()` again to set up the context/globals.
|
|
@@ -120,7 +120,7 @@ exports.watchRun = (mocha, {watchFiles, watchIgnore}, fileCollectParams) => {
|
|
|
120
120
|
newMocha.suite.ctx = new Context();
|
|
121
121
|
|
|
122
122
|
// reset the list of files
|
|
123
|
-
newMocha.files = collectFiles(fileCollectParams);
|
|
123
|
+
newMocha.files = collectFiles(fileCollectParams).files;
|
|
124
124
|
|
|
125
125
|
// because we've swapped out the root suite (see the `run` inner function
|
|
126
126
|
// in `createRerunner`), we need to call `mocha.ui()` again to set up the context/globals.
|
package/mocha.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// mocha@10.5.
|
|
1
|
+
// mocha@10.5.1 in javascript ES2018
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
@@ -18986,7 +18986,7 @@
|
|
|
18986
18986
|
};
|
|
18987
18987
|
|
|
18988
18988
|
var name = "mocha";
|
|
18989
|
-
var version = "10.5.
|
|
18989
|
+
var version = "10.5.1";
|
|
18990
18990
|
var homepage = "https://mochajs.org/";
|
|
18991
18991
|
var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
|
|
18992
18992
|
var require$$17 = {
|