mocha 9.1.2

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 (76) hide show
  1. package/CHANGELOG.md +1015 -0
  2. package/LICENSE +22 -0
  3. package/README.md +70 -0
  4. package/assets/growl/error.png +0 -0
  5. package/assets/growl/ok.png +0 -0
  6. package/bin/_mocha +10 -0
  7. package/bin/mocha +142 -0
  8. package/browser-entry.js +216 -0
  9. package/index.js +3 -0
  10. package/lib/browser/growl.js +169 -0
  11. package/lib/browser/highlight-tags.js +39 -0
  12. package/lib/browser/parse-query.js +24 -0
  13. package/lib/browser/progress.js +123 -0
  14. package/lib/browser/template.html +20 -0
  15. package/lib/cli/cli.js +89 -0
  16. package/lib/cli/collect-files.js +92 -0
  17. package/lib/cli/commands.js +13 -0
  18. package/lib/cli/config.js +105 -0
  19. package/lib/cli/index.js +3 -0
  20. package/lib/cli/init.js +36 -0
  21. package/lib/cli/lookup-files.js +145 -0
  22. package/lib/cli/node-flags.js +85 -0
  23. package/lib/cli/one-and-dones.js +69 -0
  24. package/lib/cli/options.js +261 -0
  25. package/lib/cli/run-helpers.js +243 -0
  26. package/lib/cli/run-option-metadata.js +117 -0
  27. package/lib/cli/run.js +379 -0
  28. package/lib/cli/watch-run.js +380 -0
  29. package/lib/context.js +86 -0
  30. package/lib/errors.js +563 -0
  31. package/lib/hook.js +89 -0
  32. package/lib/interfaces/bdd.js +111 -0
  33. package/lib/interfaces/common.js +193 -0
  34. package/lib/interfaces/exports.js +60 -0
  35. package/lib/interfaces/index.js +6 -0
  36. package/lib/interfaces/qunit.js +98 -0
  37. package/lib/interfaces/tdd.js +106 -0
  38. package/lib/mocha.js +1374 -0
  39. package/lib/mocharc.json +10 -0
  40. package/lib/nodejs/buffered-worker-pool.js +172 -0
  41. package/lib/nodejs/esm-utils.js +109 -0
  42. package/lib/nodejs/file-unloader.js +15 -0
  43. package/lib/nodejs/growl.js +137 -0
  44. package/lib/nodejs/parallel-buffered-runner.js +433 -0
  45. package/lib/nodejs/reporters/parallel-buffered.js +165 -0
  46. package/lib/nodejs/serializer.js +412 -0
  47. package/lib/nodejs/worker.js +151 -0
  48. package/lib/pending.js +16 -0
  49. package/lib/plugin-loader.js +286 -0
  50. package/lib/reporters/base.js +537 -0
  51. package/lib/reporters/doc.js +95 -0
  52. package/lib/reporters/dot.js +81 -0
  53. package/lib/reporters/html.js +390 -0
  54. package/lib/reporters/index.js +19 -0
  55. package/lib/reporters/json-stream.js +92 -0
  56. package/lib/reporters/json.js +162 -0
  57. package/lib/reporters/landing.js +116 -0
  58. package/lib/reporters/list.js +78 -0
  59. package/lib/reporters/markdown.js +112 -0
  60. package/lib/reporters/min.js +52 -0
  61. package/lib/reporters/nyan.js +276 -0
  62. package/lib/reporters/progress.js +104 -0
  63. package/lib/reporters/spec.js +99 -0
  64. package/lib/reporters/tap.js +293 -0
  65. package/lib/reporters/xunit.js +217 -0
  66. package/lib/runnable.js +476 -0
  67. package/lib/runner.js +1269 -0
  68. package/lib/stats-collector.js +83 -0
  69. package/lib/suite.js +695 -0
  70. package/lib/test.js +113 -0
  71. package/lib/utils.js +641 -0
  72. package/mocha-es2018.js +19816 -0
  73. package/mocha.css +325 -0
  74. package/mocha.js +30844 -0
  75. package/mocha.js.map +1 -0
  76. package/package.json +200 -0
@@ -0,0 +1,111 @@
1
+ 'use strict';
2
+
3
+ var Test = require('../test');
4
+ var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
5
+ .EVENT_FILE_PRE_REQUIRE;
6
+
7
+ /**
8
+ * BDD-style interface:
9
+ *
10
+ * describe('Array', function() {
11
+ * describe('#indexOf()', function() {
12
+ * it('should return -1 when not present', function() {
13
+ * // ...
14
+ * });
15
+ *
16
+ * it('should return the index when present', function() {
17
+ * // ...
18
+ * });
19
+ * });
20
+ * });
21
+ *
22
+ * @param {Suite} suite Root suite.
23
+ */
24
+ module.exports = function bddInterface(suite) {
25
+ var suites = [suite];
26
+
27
+ suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
28
+ var common = require('./common')(suites, context, mocha);
29
+
30
+ context.before = common.before;
31
+ context.after = common.after;
32
+ context.beforeEach = common.beforeEach;
33
+ context.afterEach = common.afterEach;
34
+ context.run = mocha.options.delay && common.runWithSuite(suite);
35
+ /**
36
+ * Describe a "suite" with the given `title`
37
+ * and callback `fn` containing nested suites
38
+ * and/or tests.
39
+ */
40
+
41
+ context.describe = context.context = function(title, fn) {
42
+ return common.suite.create({
43
+ title: title,
44
+ file: file,
45
+ fn: fn
46
+ });
47
+ };
48
+
49
+ /**
50
+ * Pending describe.
51
+ */
52
+
53
+ context.xdescribe = context.xcontext = context.describe.skip = function(
54
+ title,
55
+ fn
56
+ ) {
57
+ return common.suite.skip({
58
+ title: title,
59
+ file: file,
60
+ fn: fn
61
+ });
62
+ };
63
+
64
+ /**
65
+ * Exclusive suite.
66
+ */
67
+
68
+ context.describe.only = function(title, fn) {
69
+ return common.suite.only({
70
+ title: title,
71
+ file: file,
72
+ fn: fn
73
+ });
74
+ };
75
+
76
+ /**
77
+ * Describe a specification or test-case
78
+ * with the given `title` and callback `fn`
79
+ * acting as a thunk.
80
+ */
81
+
82
+ context.it = context.specify = function(title, fn) {
83
+ var suite = suites[0];
84
+ if (suite.isPending()) {
85
+ fn = null;
86
+ }
87
+ var test = new Test(title, fn);
88
+ test.file = file;
89
+ suite.addTest(test);
90
+ return test;
91
+ };
92
+
93
+ /**
94
+ * Exclusive test-case.
95
+ */
96
+
97
+ context.it.only = function(title, fn) {
98
+ return common.test.only(mocha, context.it(title, fn));
99
+ };
100
+
101
+ /**
102
+ * Pending test case.
103
+ */
104
+
105
+ context.xit = context.xspecify = context.it.skip = function(title) {
106
+ return context.it(title);
107
+ };
108
+ });
109
+ };
110
+
111
+ module.exports.description = 'BDD or RSpec style [default]';
@@ -0,0 +1,193 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ @module interfaces/common
5
+ */
6
+
7
+ var Suite = require('../suite');
8
+ var errors = require('../errors');
9
+ var createMissingArgumentError = errors.createMissingArgumentError;
10
+ var createUnsupportedError = errors.createUnsupportedError;
11
+ var createForbiddenExclusivityError = errors.createForbiddenExclusivityError;
12
+
13
+ /**
14
+ * Functions common to more than one interface.
15
+ *
16
+ * @private
17
+ * @param {Suite[]} suites
18
+ * @param {Context} context
19
+ * @param {Mocha} mocha
20
+ * @return {Object} An object containing common functions.
21
+ */
22
+ module.exports = function(suites, context, mocha) {
23
+ /**
24
+ * Check if the suite should be tested.
25
+ *
26
+ * @private
27
+ * @param {Suite} suite - suite to check
28
+ * @returns {boolean}
29
+ */
30
+ function shouldBeTested(suite) {
31
+ return (
32
+ !mocha.options.grep ||
33
+ (mocha.options.grep &&
34
+ mocha.options.grep.test(suite.fullTitle()) &&
35
+ !mocha.options.invert)
36
+ );
37
+ }
38
+
39
+ return {
40
+ /**
41
+ * This is only present if flag --delay is passed into Mocha. It triggers
42
+ * root suite execution.
43
+ *
44
+ * @param {Suite} suite The root suite.
45
+ * @return {Function} A function which runs the root suite
46
+ */
47
+ runWithSuite: function runWithSuite(suite) {
48
+ return function run() {
49
+ suite.run();
50
+ };
51
+ },
52
+
53
+ /**
54
+ * Execute before running tests.
55
+ *
56
+ * @param {string} name
57
+ * @param {Function} fn
58
+ */
59
+ before: function(name, fn) {
60
+ suites[0].beforeAll(name, fn);
61
+ },
62
+
63
+ /**
64
+ * Execute after running tests.
65
+ *
66
+ * @param {string} name
67
+ * @param {Function} fn
68
+ */
69
+ after: function(name, fn) {
70
+ suites[0].afterAll(name, fn);
71
+ },
72
+
73
+ /**
74
+ * Execute before each test case.
75
+ *
76
+ * @param {string} name
77
+ * @param {Function} fn
78
+ */
79
+ beforeEach: function(name, fn) {
80
+ suites[0].beforeEach(name, fn);
81
+ },
82
+
83
+ /**
84
+ * Execute after each test case.
85
+ *
86
+ * @param {string} name
87
+ * @param {Function} fn
88
+ */
89
+ afterEach: function(name, fn) {
90
+ suites[0].afterEach(name, fn);
91
+ },
92
+
93
+ suite: {
94
+ /**
95
+ * Create an exclusive Suite; convenience function
96
+ * See docstring for create() below.
97
+ *
98
+ * @param {Object} opts
99
+ * @returns {Suite}
100
+ */
101
+ only: function only(opts) {
102
+ if (mocha.options.forbidOnly) {
103
+ throw createForbiddenExclusivityError(mocha);
104
+ }
105
+ opts.isOnly = true;
106
+ return this.create(opts);
107
+ },
108
+
109
+ /**
110
+ * Create a Suite, but skip it; convenience function
111
+ * See docstring for create() below.
112
+ *
113
+ * @param {Object} opts
114
+ * @returns {Suite}
115
+ */
116
+ skip: function skip(opts) {
117
+ opts.pending = true;
118
+ return this.create(opts);
119
+ },
120
+
121
+ /**
122
+ * Creates a suite.
123
+ *
124
+ * @param {Object} opts Options
125
+ * @param {string} opts.title Title of Suite
126
+ * @param {Function} [opts.fn] Suite Function (not always applicable)
127
+ * @param {boolean} [opts.pending] Is Suite pending?
128
+ * @param {string} [opts.file] Filepath where this Suite resides
129
+ * @param {boolean} [opts.isOnly] Is Suite exclusive?
130
+ * @returns {Suite}
131
+ */
132
+ create: function create(opts) {
133
+ var suite = Suite.create(suites[0], opts.title);
134
+ suite.pending = Boolean(opts.pending);
135
+ suite.file = opts.file;
136
+ suites.unshift(suite);
137
+ if (opts.isOnly) {
138
+ suite.markOnly();
139
+ }
140
+ if (
141
+ suite.pending &&
142
+ mocha.options.forbidPending &&
143
+ shouldBeTested(suite)
144
+ ) {
145
+ throw createUnsupportedError('Pending test forbidden');
146
+ }
147
+ if (typeof opts.fn === 'function') {
148
+ opts.fn.call(suite);
149
+ suites.shift();
150
+ } else if (typeof opts.fn === 'undefined' && !suite.pending) {
151
+ throw createMissingArgumentError(
152
+ 'Suite "' +
153
+ suite.fullTitle() +
154
+ '" was defined but no callback was supplied. ' +
155
+ 'Supply a callback or explicitly skip the suite.',
156
+ 'callback',
157
+ 'function'
158
+ );
159
+ } else if (!opts.fn && suite.pending) {
160
+ suites.shift();
161
+ }
162
+
163
+ return suite;
164
+ }
165
+ },
166
+
167
+ test: {
168
+ /**
169
+ * Exclusive test-case.
170
+ *
171
+ * @param {Object} mocha
172
+ * @param {Function} test
173
+ * @returns {*}
174
+ */
175
+ only: function(mocha, test) {
176
+ if (mocha.options.forbidOnly) {
177
+ throw createForbiddenExclusivityError(mocha);
178
+ }
179
+ test.markOnly();
180
+ return test;
181
+ },
182
+
183
+ /**
184
+ * Pending test case.
185
+ *
186
+ * @param {string} title
187
+ */
188
+ skip: function(title) {
189
+ context.test(title);
190
+ }
191
+ }
192
+ };
193
+ };
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+ var Suite = require('../suite');
3
+ var Test = require('../test');
4
+
5
+ /**
6
+ * Exports-style (as Node.js module) interface:
7
+ *
8
+ * exports.Array = {
9
+ * '#indexOf()': {
10
+ * 'should return -1 when the value is not present': function() {
11
+ *
12
+ * },
13
+ *
14
+ * 'should return the correct index when the value is present': function() {
15
+ *
16
+ * }
17
+ * }
18
+ * };
19
+ *
20
+ * @param {Suite} suite Root suite.
21
+ */
22
+ module.exports = function(suite) {
23
+ var suites = [suite];
24
+
25
+ suite.on(Suite.constants.EVENT_FILE_REQUIRE, visit);
26
+
27
+ function visit(obj, file) {
28
+ var suite;
29
+ for (var key in obj) {
30
+ if (typeof obj[key] === 'function') {
31
+ var fn = obj[key];
32
+ switch (key) {
33
+ case 'before':
34
+ suites[0].beforeAll(fn);
35
+ break;
36
+ case 'after':
37
+ suites[0].afterAll(fn);
38
+ break;
39
+ case 'beforeEach':
40
+ suites[0].beforeEach(fn);
41
+ break;
42
+ case 'afterEach':
43
+ suites[0].afterEach(fn);
44
+ break;
45
+ default:
46
+ var test = new Test(key, fn);
47
+ test.file = file;
48
+ suites[0].addTest(test);
49
+ }
50
+ } else {
51
+ suite = Suite.create(suites[0], key);
52
+ suites.unshift(suite);
53
+ visit(obj[key], file);
54
+ suites.shift();
55
+ }
56
+ }
57
+ }
58
+ };
59
+
60
+ module.exports.description = 'Node.js module ("exports") style';
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ exports.bdd = require('./bdd');
4
+ exports.tdd = require('./tdd');
5
+ exports.qunit = require('./qunit');
6
+ exports.exports = require('./exports');
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ var Test = require('../test');
4
+ var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
5
+ .EVENT_FILE_PRE_REQUIRE;
6
+
7
+ /**
8
+ * QUnit-style interface:
9
+ *
10
+ * suite('Array');
11
+ *
12
+ * test('#length', function() {
13
+ * var arr = [1,2,3];
14
+ * ok(arr.length == 3);
15
+ * });
16
+ *
17
+ * test('#indexOf()', function() {
18
+ * var arr = [1,2,3];
19
+ * ok(arr.indexOf(1) == 0);
20
+ * ok(arr.indexOf(2) == 1);
21
+ * ok(arr.indexOf(3) == 2);
22
+ * });
23
+ *
24
+ * suite('String');
25
+ *
26
+ * test('#length', function() {
27
+ * ok('foo'.length == 3);
28
+ * });
29
+ *
30
+ * @param {Suite} suite Root suite.
31
+ */
32
+ module.exports = function qUnitInterface(suite) {
33
+ var suites = [suite];
34
+
35
+ suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
36
+ var common = require('./common')(suites, context, mocha);
37
+
38
+ context.before = common.before;
39
+ context.after = common.after;
40
+ context.beforeEach = common.beforeEach;
41
+ context.afterEach = common.afterEach;
42
+ context.run = mocha.options.delay && common.runWithSuite(suite);
43
+ /**
44
+ * Describe a "suite" with the given `title`.
45
+ */
46
+
47
+ context.suite = function(title) {
48
+ if (suites.length > 1) {
49
+ suites.shift();
50
+ }
51
+ return common.suite.create({
52
+ title: title,
53
+ file: file,
54
+ fn: false
55
+ });
56
+ };
57
+
58
+ /**
59
+ * Exclusive Suite.
60
+ */
61
+
62
+ context.suite.only = function(title) {
63
+ if (suites.length > 1) {
64
+ suites.shift();
65
+ }
66
+ return common.suite.only({
67
+ title: title,
68
+ file: file,
69
+ fn: false
70
+ });
71
+ };
72
+
73
+ /**
74
+ * Describe a specification or test-case
75
+ * with the given `title` and callback `fn`
76
+ * acting as a thunk.
77
+ */
78
+
79
+ context.test = function(title, fn) {
80
+ var test = new Test(title, fn);
81
+ test.file = file;
82
+ suites[0].addTest(test);
83
+ return test;
84
+ };
85
+
86
+ /**
87
+ * Exclusive test-case.
88
+ */
89
+
90
+ context.test.only = function(title, fn) {
91
+ return common.test.only(mocha, context.test(title, fn));
92
+ };
93
+
94
+ context.test.skip = common.test.skip;
95
+ });
96
+ };
97
+
98
+ module.exports.description = 'QUnit style';
@@ -0,0 +1,106 @@
1
+ 'use strict';
2
+
3
+ var Test = require('../test');
4
+ var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
5
+ .EVENT_FILE_PRE_REQUIRE;
6
+
7
+ /**
8
+ * TDD-style interface:
9
+ *
10
+ * suite('Array', function() {
11
+ * suite('#indexOf()', function() {
12
+ * suiteSetup(function() {
13
+ *
14
+ * });
15
+ *
16
+ * test('should return -1 when not present', function() {
17
+ *
18
+ * });
19
+ *
20
+ * test('should return the index when present', function() {
21
+ *
22
+ * });
23
+ *
24
+ * suiteTeardown(function() {
25
+ *
26
+ * });
27
+ * });
28
+ * });
29
+ *
30
+ * @param {Suite} suite Root suite.
31
+ */
32
+ module.exports = function(suite) {
33
+ var suites = [suite];
34
+
35
+ suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
36
+ var common = require('./common')(suites, context, mocha);
37
+
38
+ context.setup = common.beforeEach;
39
+ context.teardown = common.afterEach;
40
+ context.suiteSetup = common.before;
41
+ context.suiteTeardown = common.after;
42
+ context.run = mocha.options.delay && common.runWithSuite(suite);
43
+
44
+ /**
45
+ * Describe a "suite" with the given `title` and callback `fn` containing
46
+ * nested suites and/or tests.
47
+ */
48
+ context.suite = function(title, fn) {
49
+ return common.suite.create({
50
+ title: title,
51
+ file: file,
52
+ fn: fn
53
+ });
54
+ };
55
+
56
+ /**
57
+ * Pending suite.
58
+ */
59
+ context.suite.skip = function(title, fn) {
60
+ return common.suite.skip({
61
+ title: title,
62
+ file: file,
63
+ fn: fn
64
+ });
65
+ };
66
+
67
+ /**
68
+ * Exclusive test-case.
69
+ */
70
+ context.suite.only = function(title, fn) {
71
+ return common.suite.only({
72
+ title: title,
73
+ file: file,
74
+ fn: fn
75
+ });
76
+ };
77
+
78
+ /**
79
+ * Describe a specification or test-case with the given `title` and
80
+ * callback `fn` acting as a thunk.
81
+ */
82
+ context.test = function(title, fn) {
83
+ var suite = suites[0];
84
+ if (suite.isPending()) {
85
+ fn = null;
86
+ }
87
+ var test = new Test(title, fn);
88
+ test.file = file;
89
+ suite.addTest(test);
90
+ return test;
91
+ };
92
+
93
+ /**
94
+ * Exclusive test-case.
95
+ */
96
+
97
+ context.test.only = function(title, fn) {
98
+ return common.test.only(mocha, context.test(title, fn));
99
+ };
100
+
101
+ context.test.skip = common.test.skip;
102
+ });
103
+ };
104
+
105
+ module.exports.description =
106
+ 'traditional "suite"/"test" instead of BDD\'s "describe"/"it"';