1 | const Mocha = require('mocha');
|
2 | const {
|
3 | each
|
4 | } = require('macaca-utils');
|
5 | const {
|
6 | join,
|
7 | resolve
|
8 | } = require('path');
|
9 |
|
10 | module.exports = (args, callback) => {
|
11 | const utils = Mocha.utils;
|
12 | const mocha = new Mocha();
|
13 |
|
14 | mocha.reporter(args.reporter, args.reporterOptions);
|
15 | mocha.ui(args.ui);
|
16 | if (args.inlineDiffs) {
|
17 | mocha.useInlineDiffs(true);
|
18 | }
|
19 | if (args.slow) {
|
20 | mocha.suite.slow(args.slow);
|
21 | }
|
22 | if (!args.timeouts) {
|
23 | mocha.enableTimeouts(false);
|
24 | }
|
25 | if (args.timeout) {
|
26 | mocha.suite.timeout(args.timeout);
|
27 | }
|
28 | if (args.bail) {
|
29 | mocha.bail(args.bail);
|
30 | }
|
31 | if (args.grep) {
|
32 | mocha.grep(new RegExp(args.grep));
|
33 | }
|
34 | if (args.fgrep) {
|
35 | mocha.grep(args.fgrep);
|
36 | }
|
37 | if (args.invert) {
|
38 | mocha.invert();
|
39 | }
|
40 | if (args.checkLeaks) {
|
41 | mocha.checkLeaks();
|
42 | }
|
43 | mocha.globals(args.globals);
|
44 | mocha.useColors(args.colors);
|
45 |
|
46 |
|
47 | let files = [];
|
48 | const extensions = [ 'js' ];
|
49 |
|
50 | if (!args.files.length) {
|
51 | args.files.push('test');
|
52 | }
|
53 | each(args.files, arg => {
|
54 | files = files.concat(utils.lookupFiles(arg, extensions, args.recursive));
|
55 | });
|
56 |
|
57 | each(args.compilers, compilers => {
|
58 | let [ ext, mod ] = compilers.split(':');
|
59 |
|
60 | if (mod[0] === '.') {
|
61 | mod = join(process.cwd(), mod);
|
62 | }
|
63 | require(mod);
|
64 | extensions.push(ext);
|
65 | });
|
66 |
|
67 | each(args.require, mod => {
|
68 | require(mod);
|
69 | });
|
70 |
|
71 | if (args.domGlobalLoose) {
|
72 | require('./domGlobalLoose');
|
73 | } else if (args.domGlobal) {
|
74 | require('jsdom-global/register');
|
75 | }
|
76 |
|
77 | files = files.map(file => resolve(file));
|
78 |
|
79 | if (args.sort) {
|
80 | files.sort();
|
81 | }
|
82 |
|
83 | mocha.files = files;
|
84 | mocha.run(callback);
|
85 | };
|