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.
Files changed (61) hide show
  1. package/CHANGELOG.md +1776 -1751
  2. package/LICENSE +22 -22
  3. package/README.md +105 -105
  4. package/bin/_mocha +10 -10
  5. package/bin/mocha +149 -149
  6. package/bin/options.js +10 -10
  7. package/browser-entry.js +191 -191
  8. package/index.js +3 -3
  9. package/lib/browser/growl.js +168 -168
  10. package/lib/browser/progress.js +119 -119
  11. package/lib/browser/template.html +18 -18
  12. package/lib/browser/tty.js +13 -13
  13. package/lib/cli/cli.js +69 -69
  14. package/lib/cli/commands.js +13 -13
  15. package/lib/cli/config.js +101 -101
  16. package/lib/cli/index.js +9 -9
  17. package/lib/cli/init.js +37 -37
  18. package/lib/cli/node-flags.js +86 -86
  19. package/lib/cli/one-and-dones.js +70 -70
  20. package/lib/cli/options.js +347 -347
  21. package/lib/cli/run-helpers.js +337 -337
  22. package/lib/cli/run-option-metadata.js +76 -76
  23. package/lib/cli/run.js +297 -297
  24. package/lib/context.js +101 -101
  25. package/lib/errors.js +141 -141
  26. package/lib/growl.js +136 -136
  27. package/lib/hook.js +46 -46
  28. package/lib/interfaces/bdd.js +118 -118
  29. package/lib/interfaces/common.js +191 -191
  30. package/lib/interfaces/exports.js +60 -60
  31. package/lib/interfaces/index.js +6 -6
  32. package/lib/interfaces/qunit.js +99 -99
  33. package/lib/interfaces/tdd.js +107 -107
  34. package/lib/mocha.js +843 -843
  35. package/lib/mocharc.json +10 -10
  36. package/lib/pending.js +12 -12
  37. package/lib/reporters/base.js +491 -491
  38. package/lib/reporters/doc.js +85 -85
  39. package/lib/reporters/dot.js +81 -81
  40. package/lib/reporters/html.js +390 -390
  41. package/lib/reporters/index.js +19 -19
  42. package/lib/reporters/json-stream.js +90 -90
  43. package/lib/reporters/json.js +135 -135
  44. package/lib/reporters/landing.js +108 -108
  45. package/lib/reporters/list.js +78 -78
  46. package/lib/reporters/markdown.js +112 -112
  47. package/lib/reporters/min.js +52 -52
  48. package/lib/reporters/nyan.js +276 -276
  49. package/lib/reporters/progress.js +104 -104
  50. package/lib/reporters/spec.js +99 -99
  51. package/lib/reporters/tap.js +294 -294
  52. package/lib/reporters/xunit.js +216 -216
  53. package/lib/runnable.js +496 -496
  54. package/lib/runner.js +1049 -1049
  55. package/lib/stats-collector.js +83 -83
  56. package/lib/suite.js +642 -642
  57. package/lib/test.js +51 -51
  58. package/lib/utils.js +897 -897
  59. package/mocha.css +326 -326
  60. package/mocha.js +8170 -8476
  61. package/package.json +630 -628
package/lib/cli/cli.js CHANGED
@@ -1,69 +1,69 @@
1
- 'use strict';
2
-
3
- /**
4
- * This is where we finally parse and handle arguments passed to the `mocha` executable.
5
- * Option parsing is handled by {@link https://npm.im/yargs yargs}.
6
- * If executed via `node`, this module will run {@linkcode module:lib/cli/cli.main main()}.
7
- *
8
- * @private
9
- * @module
10
- */
11
-
12
- const debug = require('debug')('mocha:cli:cli');
13
- const symbols = require('log-symbols');
14
- const yargs = require('yargs');
15
- const path = require('path');
16
- const {loadOptions, YARGS_PARSER_CONFIG} = require('./options');
17
- const commands = require('./commands');
18
- const ansi = require('ansi-colors');
19
- const {repository, homepage, version, gitter} = require('../../package.json');
20
-
21
- /**
22
- * - Accepts an `Array` of arguments
23
- * - Modifies {@link https://nodejs.org/api/modules.html#modules_module_paths Node.js' search path} for easy loading of consumer modules
24
- * - Sets {@linkcode https://nodejs.org/api/errors.html#errors_error_stacktracelimit Error.stackTraceLimit} to `Infinity`
25
- * @summary Mocha's main entry point from the command-line.
26
- * @param {string[]} argv - Array of arguments to parse, or by default the lovely `process.argv.slice(2)`
27
- */
28
- exports.main = (argv = process.argv.slice(2)) => {
29
- debug('entered main with raw args', argv);
30
- // ensure we can require() from current working directory
31
- module.paths.push(process.cwd(), path.resolve('node_modules'));
32
-
33
- Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
34
-
35
- yargs
36
- .scriptName('mocha')
37
- .command(commands.run)
38
- .command(commands.init)
39
- .updateStrings({
40
- 'Positionals:': 'Positional Arguments',
41
- 'Options:': 'Other Options',
42
- 'Commands:': 'Commands'
43
- })
44
- .fail((msg, err, yargs) => {
45
- debug(err);
46
- yargs.showHelp();
47
- console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
48
- process.exit(1);
49
- })
50
- .help('help', 'Show usage information & exit')
51
- .alias('help', 'h')
52
- .version('version', 'Show version number & exit', version)
53
- .alias('version', 'V')
54
- .wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
55
- .epilog(
56
- `Mocha Resources
57
- Chat: ${ansi.magenta(gitter)}
58
- GitHub: ${ansi.blue(repository.url)}
59
- Docs: ${ansi.yellow(homepage)}
60
- `
61
- )
62
- .parserConfiguration(YARGS_PARSER_CONFIG)
63
- .parse(argv, loadOptions(argv));
64
- };
65
-
66
- // allow direct execution
67
- if (require.main === module) {
68
- exports.main();
69
- }
1
+ 'use strict';
2
+
3
+ /**
4
+ * This is where we finally parse and handle arguments passed to the `mocha` executable.
5
+ * Option parsing is handled by {@link https://npm.im/yargs yargs}.
6
+ * If executed via `node`, this module will run {@linkcode module:lib/cli/cli.main main()}.
7
+ *
8
+ * @private
9
+ * @module
10
+ */
11
+
12
+ const debug = require('debug')('mocha:cli:cli');
13
+ const symbols = require('log-symbols');
14
+ const yargs = require('yargs/yargs');
15
+ const path = require('path');
16
+ const {loadOptions, YARGS_PARSER_CONFIG} = require('./options');
17
+ const commands = require('./commands');
18
+ const ansi = require('ansi-colors');
19
+ const {repository, homepage, version, gitter} = require('../../package.json');
20
+
21
+ /**
22
+ * - Accepts an `Array` of arguments
23
+ * - Modifies {@link https://nodejs.org/api/modules.html#modules_module_paths Node.js' search path} for easy loading of consumer modules
24
+ * - Sets {@linkcode https://nodejs.org/api/errors.html#errors_error_stacktracelimit Error.stackTraceLimit} to `Infinity`
25
+ * @summary Mocha's main entry point from the command-line.
26
+ * @param {string[]} argv - Array of arguments to parse, or by default the lovely `process.argv.slice(2)`
27
+ */
28
+ exports.main = (argv = process.argv.slice(2)) => {
29
+ debug('entered main with raw args', argv);
30
+ // ensure we can require() from current working directory
31
+ module.paths.push(process.cwd(), path.resolve('node_modules'));
32
+
33
+ Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
34
+
35
+ yargs()
36
+ .scriptName('mocha')
37
+ .command(commands.run)
38
+ .command(commands.init)
39
+ .updateStrings({
40
+ 'Positionals:': 'Positional Arguments',
41
+ 'Options:': 'Other Options',
42
+ 'Commands:': 'Commands'
43
+ })
44
+ .fail((msg, err, yargs) => {
45
+ debug(err);
46
+ yargs.showHelp();
47
+ console.error(`\n${symbols.error} ${ansi.red('ERROR:')} ${msg}`);
48
+ process.exit(1);
49
+ })
50
+ .help('help', 'Show usage information & exit')
51
+ .alias('help', 'h')
52
+ .version('version', 'Show version number & exit', version)
53
+ .alias('version', 'V')
54
+ .wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
55
+ .epilog(
56
+ `Mocha Resources
57
+ Chat: ${ansi.magenta(gitter)}
58
+ GitHub: ${ansi.blue(repository.url)}
59
+ Docs: ${ansi.yellow(homepage)}
60
+ `
61
+ )
62
+ .parserConfiguration(YARGS_PARSER_CONFIG)
63
+ .parse(argv, loadOptions(argv));
64
+ };
65
+
66
+ // allow direct execution
67
+ if (require.main === module) {
68
+ exports.main();
69
+ }
@@ -1,13 +1,13 @@
1
- 'use strict';
2
-
3
- /**
4
- * Exports Yargs commands
5
- * @see https://git.io/fpJ0G
6
- * @private
7
- * @module
8
- */
9
-
10
- exports.init = require('./init');
11
-
12
- // default command
13
- exports.run = require('./run');
1
+ 'use strict';
2
+
3
+ /**
4
+ * Exports Yargs commands
5
+ * @see https://git.io/fpJ0G
6
+ * @private
7
+ * @module
8
+ */
9
+
10
+ exports.init = require('./init');
11
+
12
+ // default command
13
+ exports.run = require('./run');
package/lib/cli/config.js CHANGED
@@ -1,101 +1,101 @@
1
- 'use strict';
2
-
3
- /**
4
- * Responsible for loading / finding Mocha's "rc" files.
5
- * This doesn't have anything to do with `mocha.opts`.
6
- *
7
- * @private
8
- * @module
9
- */
10
-
11
- const fs = require('fs');
12
- const path = require('path');
13
- const debug = require('debug')('mocha:cli:config');
14
- const findUp = require('find-up');
15
-
16
- /**
17
- * These are the valid config files, in order of precedence;
18
- * e.g., if `.mocharc.js` is present, then `.mocharc.yaml` and the rest
19
- * will be ignored.
20
- * The user should still be able to explicitly specify a file.
21
- * @private
22
- */
23
- exports.CONFIG_FILES = [
24
- '.mocharc.js',
25
- '.mocharc.yaml',
26
- '.mocharc.yml',
27
- '.mocharc.jsonc',
28
- '.mocharc.json'
29
- ];
30
-
31
- const isModuleNotFoundError = err =>
32
- err.code !== 'MODULE_NOT_FOUND' ||
33
- err.message.indexOf('Cannot find module') !== -1;
34
-
35
- /**
36
- * Parsers for various config filetypes. Each accepts a filepath and
37
- * returns an object (but could throw)
38
- */
39
- const parsers = (exports.parsers = {
40
- yaml: filepath =>
41
- require('js-yaml').safeLoad(fs.readFileSync(filepath, 'utf8')),
42
- js: filepath => {
43
- const cwdFilepath = path.resolve(filepath);
44
- try {
45
- debug(`parsers: load using cwd-relative path: "${cwdFilepath}"`);
46
- return require(cwdFilepath);
47
- } catch (err) {
48
- if (isModuleNotFoundError(err)) {
49
- debug(`parsers: retry load as module-relative path: "${filepath}"`);
50
- return require(filepath);
51
- } else {
52
- throw err; // rethrow
53
- }
54
- }
55
- },
56
- json: filepath =>
57
- JSON.parse(
58
- require('strip-json-comments')(fs.readFileSync(filepath, 'utf8'))
59
- )
60
- });
61
-
62
- /**
63
- * Loads and parses, based on file extension, a config file.
64
- * "JSON" files may have comments.
65
- *
66
- * @private
67
- * @param {string} filepath - Config file path to load
68
- * @returns {Object} Parsed config object
69
- */
70
- exports.loadConfig = filepath => {
71
- let config = {};
72
- debug(`loadConfig: "${filepath}"`);
73
-
74
- const ext = path.extname(filepath);
75
- try {
76
- if (ext === '.yml' || ext === '.yaml') {
77
- config = parsers.yaml(filepath);
78
- } else if (ext === '.js') {
79
- config = parsers.js(filepath);
80
- } else {
81
- config = parsers.json(filepath);
82
- }
83
- } catch (err) {
84
- throw new Error(`failed to parse config "${filepath}": ${err}`);
85
- }
86
- return config;
87
- };
88
-
89
- /**
90
- * Find ("find up") config file starting at `cwd`
91
- *
92
- * @param {string} [cwd] - Current working directory
93
- * @returns {string|null} Filepath to config, if found
94
- */
95
- exports.findConfig = (cwd = process.cwd()) => {
96
- const filepath = findUp.sync(exports.CONFIG_FILES, {cwd});
97
- if (filepath) {
98
- debug(`findConfig: found "${filepath}"`);
99
- }
100
- return filepath;
101
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Responsible for loading / finding Mocha's "rc" files.
5
+ * This doesn't have anything to do with `mocha.opts`.
6
+ *
7
+ * @private
8
+ * @module
9
+ */
10
+
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+ const debug = require('debug')('mocha:cli:config');
14
+ const findUp = require('find-up');
15
+
16
+ /**
17
+ * These are the valid config files, in order of precedence;
18
+ * e.g., if `.mocharc.js` is present, then `.mocharc.yaml` and the rest
19
+ * will be ignored.
20
+ * The user should still be able to explicitly specify a file.
21
+ * @private
22
+ */
23
+ exports.CONFIG_FILES = [
24
+ '.mocharc.js',
25
+ '.mocharc.yaml',
26
+ '.mocharc.yml',
27
+ '.mocharc.jsonc',
28
+ '.mocharc.json'
29
+ ];
30
+
31
+ const isModuleNotFoundError = err =>
32
+ err.code !== 'MODULE_NOT_FOUND' ||
33
+ err.message.indexOf('Cannot find module') !== -1;
34
+
35
+ /**
36
+ * Parsers for various config filetypes. Each accepts a filepath and
37
+ * returns an object (but could throw)
38
+ */
39
+ const parsers = (exports.parsers = {
40
+ yaml: filepath =>
41
+ require('js-yaml').safeLoad(fs.readFileSync(filepath, 'utf8')),
42
+ js: filepath => {
43
+ const cwdFilepath = path.resolve(filepath);
44
+ try {
45
+ debug(`parsers: load using cwd-relative path: "${cwdFilepath}"`);
46
+ return require(cwdFilepath);
47
+ } catch (err) {
48
+ if (isModuleNotFoundError(err)) {
49
+ debug(`parsers: retry load as module-relative path: "${filepath}"`);
50
+ return require(filepath);
51
+ } else {
52
+ throw err; // rethrow
53
+ }
54
+ }
55
+ },
56
+ json: filepath =>
57
+ JSON.parse(
58
+ require('strip-json-comments')(fs.readFileSync(filepath, 'utf8'))
59
+ )
60
+ });
61
+
62
+ /**
63
+ * Loads and parses, based on file extension, a config file.
64
+ * "JSON" files may have comments.
65
+ *
66
+ * @private
67
+ * @param {string} filepath - Config file path to load
68
+ * @returns {Object} Parsed config object
69
+ */
70
+ exports.loadConfig = filepath => {
71
+ let config = {};
72
+ debug(`loadConfig: "${filepath}"`);
73
+
74
+ const ext = path.extname(filepath);
75
+ try {
76
+ if (ext === '.yml' || ext === '.yaml') {
77
+ config = parsers.yaml(filepath);
78
+ } else if (ext === '.js') {
79
+ config = parsers.js(filepath);
80
+ } else {
81
+ config = parsers.json(filepath);
82
+ }
83
+ } catch (err) {
84
+ throw new Error(`failed to parse config "${filepath}": ${err}`);
85
+ }
86
+ return config;
87
+ };
88
+
89
+ /**
90
+ * Find ("find up") config file starting at `cwd`
91
+ *
92
+ * @param {string} [cwd] - Current working directory
93
+ * @returns {string|null} Filepath to config, if found
94
+ */
95
+ exports.findConfig = (cwd = process.cwd()) => {
96
+ const filepath = findUp.sync(exports.CONFIG_FILES, {cwd});
97
+ if (filepath) {
98
+ debug(`findConfig: found "${filepath}"`);
99
+ }
100
+ return filepath;
101
+ };
package/lib/cli/index.js CHANGED
@@ -1,9 +1,9 @@
1
- 'use strict';
2
-
3
- /**
4
- * Just exports {@link module:lib/cli/cli} for convenience.
5
- * @private
6
- * @module lib/cli
7
- * @exports module:lib/cli/cli
8
- */
9
- module.exports = require('./cli');
1
+ 'use strict';
2
+
3
+ /**
4
+ * Just exports {@link module:lib/cli/cli} for convenience.
5
+ * @private
6
+ * @module lib/cli
7
+ * @exports module:lib/cli/cli
8
+ */
9
+ module.exports = require('./cli');
package/lib/cli/init.js CHANGED
@@ -1,37 +1,37 @@
1
- 'use strict';
2
-
3
- /**
4
- * Command module for "init" command
5
- *
6
- * @private
7
- * @module
8
- */
9
-
10
- const fs = require('fs');
11
- const path = require('path');
12
- const mkdirp = require('mkdirp');
13
-
14
- exports.command = 'init <path>';
15
-
16
- exports.description = 'create a client-side Mocha setup at <path>';
17
-
18
- exports.builder = yargs =>
19
- yargs.positional('path', {
20
- type: 'string',
21
- normalize: true
22
- });
23
-
24
- exports.handler = argv => {
25
- const destdir = argv.path;
26
- const srcdir = path.join(__dirname, '..', '..');
27
- mkdirp.sync(destdir);
28
- const css = fs.readFileSync(path.join(srcdir, 'mocha.css'));
29
- const js = fs.readFileSync(path.join(srcdir, 'mocha.js'));
30
- const tmpl = fs.readFileSync(
31
- path.join(srcdir, 'lib', 'browser', 'template.html')
32
- );
33
- fs.writeFileSync(path.join(destdir, 'mocha.css'), css);
34
- fs.writeFileSync(path.join(destdir, 'mocha.js'), js);
35
- fs.writeFileSync(path.join(destdir, 'tests.spec.js'), '');
36
- fs.writeFileSync(path.join(destdir, 'index.html'), tmpl);
37
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Command module for "init" command
5
+ *
6
+ * @private
7
+ * @module
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ const mkdirp = require('mkdirp');
13
+
14
+ exports.command = 'init <path>';
15
+
16
+ exports.description = 'create a client-side Mocha setup at <path>';
17
+
18
+ exports.builder = yargs =>
19
+ yargs.positional('path', {
20
+ type: 'string',
21
+ normalize: true
22
+ });
23
+
24
+ exports.handler = argv => {
25
+ const destdir = argv.path;
26
+ const srcdir = path.join(__dirname, '..', '..');
27
+ mkdirp.sync(destdir);
28
+ const css = fs.readFileSync(path.join(srcdir, 'mocha.css'));
29
+ const js = fs.readFileSync(path.join(srcdir, 'mocha.js'));
30
+ const tmpl = fs.readFileSync(
31
+ path.join(srcdir, 'lib', 'browser', 'template.html')
32
+ );
33
+ fs.writeFileSync(path.join(destdir, 'mocha.css'), css);
34
+ fs.writeFileSync(path.join(destdir, 'mocha.js'), js);
35
+ fs.writeFileSync(path.join(destdir, 'tests.spec.js'), '');
36
+ fs.writeFileSync(path.join(destdir, 'index.html'), tmpl);
37
+ };
@@ -1,86 +1,86 @@
1
- 'use strict';
2
-
3
- /**
4
- * Some settings and code related to Mocha's handling of Node.js/V8 flags.
5
- * @private
6
- * @module
7
- */
8
-
9
- const nodeFlags = require('node-environment-flags');
10
- const unparse = require('yargs-unparser');
11
-
12
- /**
13
- * These flags are considered "debug" flags.
14
- * @see {@link impliesNoTimeouts}
15
- * @private
16
- */
17
- const debugFlags = new Set(['debug', 'debug-brk', 'inspect', 'inspect-brk']);
18
-
19
- /**
20
- * Mocha has historical support for various `node` and V8 flags which might not
21
- * appear in `process.allowedNodeEnvironmentFlags`.
22
- * These include:
23
- * - `--preserve-symlinks`
24
- * - `--harmony-*`
25
- * - `--gc-global`
26
- * - `--trace-*`
27
- * - `--es-staging`
28
- * - `--use-strict`
29
- * - `--v8-*` (but *not* `--v8-options`)
30
- * @summary Whether or not to pass a flag along to the `node` executable.
31
- * @param {string} flag - Flag to test
32
- * @param {boolean} [bareword=true] - If `false`, we expect `flag` to have one or two leading dashes.
33
- * @returns {boolean} If the flag is considered a "Node" flag.
34
- * @private
35
- */
36
- exports.isNodeFlag = (flag, bareword = true) => {
37
- if (!bareword) {
38
- // check if the flag begins with dashes; if not, not a node flag.
39
- if (!/^--?/.test(flag)) {
40
- return false;
41
- }
42
- // strip the leading dashes to match against subsequent checks
43
- flag = flag.replace(/^--?/, '');
44
- }
45
- return (
46
- // treat --require/-r as Mocha flag even though it's also a node flag
47
- !(flag === 'require' || flag === 'r') &&
48
- // check actual node flags from `process.allowedNodeEnvironmentFlags`,
49
- // then historical support for various V8 and non-`NODE_OPTIONS` flags
50
- // and also any V8 flags with `--v8-` prefix
51
- (nodeFlags.has(flag) ||
52
- debugFlags.has(flag) ||
53
- /(?:preserve-symlinks(?:-main)?|harmony(?:[_-]|$)|(?:trace[_-].+$)|gc(?:[_-]global)?$|es[_-]staging$|use[_-]strict$|v8[_-](?!options).+?$)/.test(
54
- flag
55
- ))
56
- );
57
- };
58
-
59
- /**
60
- * Returns `true` if the flag is a "debug-like" flag. These require timeouts
61
- * to be suppressed, or pausing the debugger on breakpoints will cause test failures.
62
- * @param {string} flag - Flag to test
63
- * @returns {boolean}
64
- * @private
65
- */
66
- exports.impliesNoTimeouts = flag => debugFlags.has(flag);
67
-
68
- /**
69
- * All non-strictly-boolean arguments to node--those with values--must specify those values using `=`, e.g., `--inspect=0.0.0.0`.
70
- * Unparse these arguments using `yargs-unparser` (which would result in `--inspect 0.0.0.0`), then supply `=` where we have values.
71
- * There's probably an easier or more robust way to do this; fixes welcome
72
- * @param {Object} opts - Arguments object
73
- * @returns {string[]} Unparsed arguments using `=` to specify values
74
- * @private
75
- */
76
- exports.unparseNodeFlags = opts => {
77
- var args = unparse(opts);
78
- return args.length
79
- ? args
80
- .join(' ')
81
- .split(/\b/)
82
- .map(arg => (arg === ' ' ? '=' : arg))
83
- .join('')
84
- .split(' ')
85
- : [];
86
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Some settings and code related to Mocha's handling of Node.js/V8 flags.
5
+ * @private
6
+ * @module
7
+ */
8
+
9
+ const nodeFlags = require('node-environment-flags');
10
+ const unparse = require('yargs-unparser');
11
+
12
+ /**
13
+ * These flags are considered "debug" flags.
14
+ * @see {@link impliesNoTimeouts}
15
+ * @private
16
+ */
17
+ const debugFlags = new Set(['debug', 'debug-brk', 'inspect', 'inspect-brk']);
18
+
19
+ /**
20
+ * Mocha has historical support for various `node` and V8 flags which might not
21
+ * appear in `process.allowedNodeEnvironmentFlags`.
22
+ * These include:
23
+ * - `--preserve-symlinks`
24
+ * - `--harmony-*`
25
+ * - `--gc-global`
26
+ * - `--trace-*`
27
+ * - `--es-staging`
28
+ * - `--use-strict`
29
+ * - `--v8-*` (but *not* `--v8-options`)
30
+ * @summary Whether or not to pass a flag along to the `node` executable.
31
+ * @param {string} flag - Flag to test
32
+ * @param {boolean} [bareword=true] - If `false`, we expect `flag` to have one or two leading dashes.
33
+ * @returns {boolean} If the flag is considered a "Node" flag.
34
+ * @private
35
+ */
36
+ exports.isNodeFlag = (flag, bareword = true) => {
37
+ if (!bareword) {
38
+ // check if the flag begins with dashes; if not, not a node flag.
39
+ if (!/^--?/.test(flag)) {
40
+ return false;
41
+ }
42
+ // strip the leading dashes to match against subsequent checks
43
+ flag = flag.replace(/^--?/, '');
44
+ }
45
+ return (
46
+ // treat --require/-r as Mocha flag even though it's also a node flag
47
+ !(flag === 'require' || flag === 'r') &&
48
+ // check actual node flags from `process.allowedNodeEnvironmentFlags`,
49
+ // then historical support for various V8 and non-`NODE_OPTIONS` flags
50
+ // and also any V8 flags with `--v8-` prefix
51
+ (nodeFlags.has(flag) ||
52
+ debugFlags.has(flag) ||
53
+ /(?:preserve-symlinks(?:-main)?|harmony(?:[_-]|$)|(?:trace[_-].+$)|gc(?:[_-]global)?$|es[_-]staging$|use[_-]strict$|v8[_-](?!options).+?$)/.test(
54
+ flag
55
+ ))
56
+ );
57
+ };
58
+
59
+ /**
60
+ * Returns `true` if the flag is a "debug-like" flag. These require timeouts
61
+ * to be suppressed, or pausing the debugger on breakpoints will cause test failures.
62
+ * @param {string} flag - Flag to test
63
+ * @returns {boolean}
64
+ * @private
65
+ */
66
+ exports.impliesNoTimeouts = flag => debugFlags.has(flag);
67
+
68
+ /**
69
+ * All non-strictly-boolean arguments to node--those with values--must specify those values using `=`, e.g., `--inspect=0.0.0.0`.
70
+ * Unparse these arguments using `yargs-unparser` (which would result in `--inspect 0.0.0.0`), then supply `=` where we have values.
71
+ * There's probably an easier or more robust way to do this; fixes welcome
72
+ * @param {Object} opts - Arguments object
73
+ * @returns {string[]} Unparsed arguments using `=` to specify values
74
+ * @private
75
+ */
76
+ exports.unparseNodeFlags = opts => {
77
+ var args = unparse(opts);
78
+ return args.length
79
+ ? args
80
+ .join(' ')
81
+ .split(/\b/)
82
+ .map(arg => (arg === ' ' ? '=' : arg))
83
+ .join('')
84
+ .split(' ')
85
+ : [];
86
+ };