1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | 'use strict';
|
17 |
|
18 | function run(argv, options) {
|
19 | const utils = require('./utils');
|
20 |
|
21 | const mochaOpts = argv.slice(2);
|
22 |
|
23 | const setMochaOpts =
|
24 | !utils.isOptionSet(
|
25 | mochaOpts,
|
26 | '--config',
|
27 | '--package',
|
28 | '--no-config',
|
29 | ) && !utils.mochaConfiguredForProject();
|
30 |
|
31 |
|
32 |
|
33 | if (typeof options === 'boolean') options = {dryRun: options};
|
34 | options = options || {};
|
35 | if (setMochaOpts) {
|
36 |
|
37 | const mochaOptsFile = utils.getConfigFile('.mocharc.json');
|
38 | mochaOpts.unshift('--config', mochaOptsFile);
|
39 | }
|
40 |
|
41 | const allowConsoleLogsIx = mochaOpts.indexOf('--allow-console-logs');
|
42 | if (allowConsoleLogsIx === -1) {
|
43 |
|
44 | mochaOpts.unshift(
|
45 | '--no-warnings',
|
46 | '--require',
|
47 | require.resolve('../src/fail-on-console-logs'),
|
48 | );
|
49 | } else {
|
50 |
|
51 | mochaOpts.splice(allowConsoleLogsIx, 1);
|
52 | }
|
53 |
|
54 |
|
55 | const lang = mochaOpts.indexOf('--lang');
|
56 | if (lang !== -1) {
|
57 | process.env.LANG = mochaOpts[lang + 1];
|
58 | mochaOpts.splice(lang, 2);
|
59 | }
|
60 |
|
61 | const args = [...mochaOpts];
|
62 |
|
63 | return utils.runCLI('mocha/bin/mocha', args, options);
|
64 | }
|
65 |
|
66 | module.exports = run;
|
67 | if (require.main === module) run(process.argv);
|