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
@@ -1,19 +1,19 @@
1
- 'use strict';
2
-
3
- // Alias exports to a their normalized format Mocha#reporter to prevent a need
4
- // for dynamic (try/catch) requires, which Browserify doesn't handle.
5
- exports.Base = exports.base = require('./base');
6
- exports.Dot = exports.dot = require('./dot');
7
- exports.Doc = exports.doc = require('./doc');
8
- exports.TAP = exports.tap = require('./tap');
9
- exports.JSON = exports.json = require('./json');
10
- exports.HTML = exports.html = require('./html');
11
- exports.List = exports.list = require('./list');
12
- exports.Min = exports.min = require('./min');
13
- exports.Spec = exports.spec = require('./spec');
14
- exports.Nyan = exports.nyan = require('./nyan');
15
- exports.XUnit = exports.xunit = require('./xunit');
16
- exports.Markdown = exports.markdown = require('./markdown');
17
- exports.Progress = exports.progress = require('./progress');
18
- exports.Landing = exports.landing = require('./landing');
19
- exports.JSONStream = exports['json-stream'] = require('./json-stream');
1
+ 'use strict';
2
+
3
+ // Alias exports to a their normalized format Mocha#reporter to prevent a need
4
+ // for dynamic (try/catch) requires, which Browserify doesn't handle.
5
+ exports.Base = exports.base = require('./base');
6
+ exports.Dot = exports.dot = require('./dot');
7
+ exports.Doc = exports.doc = require('./doc');
8
+ exports.TAP = exports.tap = require('./tap');
9
+ exports.JSON = exports.json = require('./json');
10
+ exports.HTML = exports.html = require('./html');
11
+ exports.List = exports.list = require('./list');
12
+ exports.Min = exports.min = require('./min');
13
+ exports.Spec = exports.spec = require('./spec');
14
+ exports.Nyan = exports.nyan = require('./nyan');
15
+ exports.XUnit = exports.xunit = require('./xunit');
16
+ exports.Markdown = exports.markdown = require('./markdown');
17
+ exports.Progress = exports.progress = require('./progress');
18
+ exports.Landing = exports.landing = require('./landing');
19
+ exports.JSONStream = exports['json-stream'] = require('./json-stream');
@@ -1,90 +1,90 @@
1
- 'use strict';
2
- /**
3
- * @module JSONStream
4
- */
5
- /**
6
- * Module dependencies.
7
- */
8
-
9
- var Base = require('./base');
10
- var constants = require('../runner').constants;
11
- var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
12
- var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
13
- var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
14
- var EVENT_RUN_END = constants.EVENT_RUN_END;
15
-
16
- /**
17
- * Expose `JSONStream`.
18
- */
19
-
20
- exports = module.exports = JSONStream;
21
-
22
- /**
23
- * Constructs a new `JSONStream` reporter instance.
24
- *
25
- * @public
26
- * @class
27
- * @memberof Mocha.reporters
28
- * @extends Mocha.reporters.Base
29
- * @param {Runner} runner - Instance triggers reporter actions.
30
- * @param {Object} [options] - runner options
31
- */
32
- function JSONStream(runner, options) {
33
- Base.call(this, runner, options);
34
-
35
- var self = this;
36
- var total = runner.total;
37
-
38
- runner.once(EVENT_RUN_BEGIN, function() {
39
- writeEvent(['start', {total: total}]);
40
- });
41
-
42
- runner.on(EVENT_TEST_PASS, function(test) {
43
- writeEvent(['pass', clean(test)]);
44
- });
45
-
46
- runner.on(EVENT_TEST_FAIL, function(test, err) {
47
- test = clean(test);
48
- test.err = err.message;
49
- test.stack = err.stack || null;
50
- writeEvent(['fail', test]);
51
- });
52
-
53
- runner.once(EVENT_RUN_END, function() {
54
- writeEvent(['end', self.stats]);
55
- });
56
- }
57
-
58
- /**
59
- * Mocha event to be written to the output stream.
60
- * @typedef {Array} JSONStream~MochaEvent
61
- */
62
-
63
- /**
64
- * Writes Mocha event to reporter output stream.
65
- *
66
- * @private
67
- * @param {JSONStream~MochaEvent} event - Mocha event to be output.
68
- */
69
- function writeEvent(event) {
70
- process.stdout.write(JSON.stringify(event) + '\n');
71
- }
72
-
73
- /**
74
- * Returns an object literal representation of `test`
75
- * free of cyclic properties, etc.
76
- *
77
- * @private
78
- * @param {Test} test - Instance used as data source.
79
- * @return {Object} object containing pared-down test instance data
80
- */
81
- function clean(test) {
82
- return {
83
- title: test.title,
84
- fullTitle: test.fullTitle(),
85
- duration: test.duration,
86
- currentRetry: test.currentRetry()
87
- };
88
- }
89
-
90
- JSONStream.description = 'newline delimited JSON events';
1
+ 'use strict';
2
+ /**
3
+ * @module JSONStream
4
+ */
5
+ /**
6
+ * Module dependencies.
7
+ */
8
+
9
+ var Base = require('./base');
10
+ var constants = require('../runner').constants;
11
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
12
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
13
+ var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
14
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
15
+
16
+ /**
17
+ * Expose `JSONStream`.
18
+ */
19
+
20
+ exports = module.exports = JSONStream;
21
+
22
+ /**
23
+ * Constructs a new `JSONStream` reporter instance.
24
+ *
25
+ * @public
26
+ * @class
27
+ * @memberof Mocha.reporters
28
+ * @extends Mocha.reporters.Base
29
+ * @param {Runner} runner - Instance triggers reporter actions.
30
+ * @param {Object} [options] - runner options
31
+ */
32
+ function JSONStream(runner, options) {
33
+ Base.call(this, runner, options);
34
+
35
+ var self = this;
36
+ var total = runner.total;
37
+
38
+ runner.once(EVENT_RUN_BEGIN, function() {
39
+ writeEvent(['start', {total: total}]);
40
+ });
41
+
42
+ runner.on(EVENT_TEST_PASS, function(test) {
43
+ writeEvent(['pass', clean(test)]);
44
+ });
45
+
46
+ runner.on(EVENT_TEST_FAIL, function(test, err) {
47
+ test = clean(test);
48
+ test.err = err.message;
49
+ test.stack = err.stack || null;
50
+ writeEvent(['fail', test]);
51
+ });
52
+
53
+ runner.once(EVENT_RUN_END, function() {
54
+ writeEvent(['end', self.stats]);
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Mocha event to be written to the output stream.
60
+ * @typedef {Array} JSONStream~MochaEvent
61
+ */
62
+
63
+ /**
64
+ * Writes Mocha event to reporter output stream.
65
+ *
66
+ * @private
67
+ * @param {JSONStream~MochaEvent} event - Mocha event to be output.
68
+ */
69
+ function writeEvent(event) {
70
+ process.stdout.write(JSON.stringify(event) + '\n');
71
+ }
72
+
73
+ /**
74
+ * Returns an object literal representation of `test`
75
+ * free of cyclic properties, etc.
76
+ *
77
+ * @private
78
+ * @param {Test} test - Instance used as data source.
79
+ * @return {Object} object containing pared-down test instance data
80
+ */
81
+ function clean(test) {
82
+ return {
83
+ title: test.title,
84
+ fullTitle: test.fullTitle(),
85
+ duration: test.duration,
86
+ currentRetry: test.currentRetry()
87
+ };
88
+ }
89
+
90
+ JSONStream.description = 'newline delimited JSON events';
@@ -1,135 +1,135 @@
1
- 'use strict';
2
- /**
3
- * @module JSON
4
- */
5
- /**
6
- * Module dependencies.
7
- */
8
-
9
- var Base = require('./base');
10
- var constants = require('../runner').constants;
11
- var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
12
- var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
13
- var EVENT_TEST_END = constants.EVENT_TEST_END;
14
- var EVENT_RUN_END = constants.EVENT_RUN_END;
15
- var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
16
-
17
- /**
18
- * Expose `JSON`.
19
- */
20
-
21
- exports = module.exports = JSONReporter;
22
-
23
- /**
24
- * Constructs a new `JSON` reporter instance.
25
- *
26
- * @public
27
- * @class JSON
28
- * @memberof Mocha.reporters
29
- * @extends Mocha.reporters.Base
30
- * @param {Runner} runner - Instance triggers reporter actions.
31
- * @param {Object} [options] - runner options
32
- */
33
- function JSONReporter(runner, options) {
34
- Base.call(this, runner, options);
35
-
36
- var self = this;
37
- var tests = [];
38
- var pending = [];
39
- var failures = [];
40
- var passes = [];
41
-
42
- runner.on(EVENT_TEST_END, function(test) {
43
- tests.push(test);
44
- });
45
-
46
- runner.on(EVENT_TEST_PASS, function(test) {
47
- passes.push(test);
48
- });
49
-
50
- runner.on(EVENT_TEST_FAIL, function(test) {
51
- failures.push(test);
52
- });
53
-
54
- runner.on(EVENT_TEST_PENDING, function(test) {
55
- pending.push(test);
56
- });
57
-
58
- runner.once(EVENT_RUN_END, function() {
59
- var obj = {
60
- stats: self.stats,
61
- tests: tests.map(clean),
62
- pending: pending.map(clean),
63
- failures: failures.map(clean),
64
- passes: passes.map(clean)
65
- };
66
-
67
- runner.testResults = obj;
68
-
69
- process.stdout.write(JSON.stringify(obj, null, 2));
70
- });
71
- }
72
-
73
- /**
74
- * Return a plain-object representation of `test`
75
- * free of cyclic properties etc.
76
- *
77
- * @private
78
- * @param {Object} test
79
- * @return {Object}
80
- */
81
- function clean(test) {
82
- var err = test.err || {};
83
- if (err instanceof Error) {
84
- err = errorJSON(err);
85
- }
86
-
87
- return {
88
- title: test.title,
89
- fullTitle: test.fullTitle(),
90
- duration: test.duration,
91
- currentRetry: test.currentRetry(),
92
- err: cleanCycles(err)
93
- };
94
- }
95
-
96
- /**
97
- * Replaces any circular references inside `obj` with '[object Object]'
98
- *
99
- * @private
100
- * @param {Object} obj
101
- * @return {Object}
102
- */
103
- function cleanCycles(obj) {
104
- var cache = [];
105
- return JSON.parse(
106
- JSON.stringify(obj, function(key, value) {
107
- if (typeof value === 'object' && value !== null) {
108
- if (cache.indexOf(value) !== -1) {
109
- // Instead of going in a circle, we'll print [object Object]
110
- return '' + value;
111
- }
112
- cache.push(value);
113
- }
114
-
115
- return value;
116
- })
117
- );
118
- }
119
-
120
- /**
121
- * Transform an Error object into a JSON object.
122
- *
123
- * @private
124
- * @param {Error} err
125
- * @return {Object}
126
- */
127
- function errorJSON(err) {
128
- var res = {};
129
- Object.getOwnPropertyNames(err).forEach(function(key) {
130
- res[key] = err[key];
131
- }, err);
132
- return res;
133
- }
134
-
135
- JSONReporter.description = 'single JSON object';
1
+ 'use strict';
2
+ /**
3
+ * @module JSON
4
+ */
5
+ /**
6
+ * Module dependencies.
7
+ */
8
+
9
+ var Base = require('./base');
10
+ var constants = require('../runner').constants;
11
+ var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
12
+ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
13
+ var EVENT_TEST_END = constants.EVENT_TEST_END;
14
+ var EVENT_RUN_END = constants.EVENT_RUN_END;
15
+ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
16
+
17
+ /**
18
+ * Expose `JSON`.
19
+ */
20
+
21
+ exports = module.exports = JSONReporter;
22
+
23
+ /**
24
+ * Constructs a new `JSON` reporter instance.
25
+ *
26
+ * @public
27
+ * @class JSON
28
+ * @memberof Mocha.reporters
29
+ * @extends Mocha.reporters.Base
30
+ * @param {Runner} runner - Instance triggers reporter actions.
31
+ * @param {Object} [options] - runner options
32
+ */
33
+ function JSONReporter(runner, options) {
34
+ Base.call(this, runner, options);
35
+
36
+ var self = this;
37
+ var tests = [];
38
+ var pending = [];
39
+ var failures = [];
40
+ var passes = [];
41
+
42
+ runner.on(EVENT_TEST_END, function(test) {
43
+ tests.push(test);
44
+ });
45
+
46
+ runner.on(EVENT_TEST_PASS, function(test) {
47
+ passes.push(test);
48
+ });
49
+
50
+ runner.on(EVENT_TEST_FAIL, function(test) {
51
+ failures.push(test);
52
+ });
53
+
54
+ runner.on(EVENT_TEST_PENDING, function(test) {
55
+ pending.push(test);
56
+ });
57
+
58
+ runner.once(EVENT_RUN_END, function() {
59
+ var obj = {
60
+ stats: self.stats,
61
+ tests: tests.map(clean),
62
+ pending: pending.map(clean),
63
+ failures: failures.map(clean),
64
+ passes: passes.map(clean)
65
+ };
66
+
67
+ runner.testResults = obj;
68
+
69
+ process.stdout.write(JSON.stringify(obj, null, 2));
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Return a plain-object representation of `test`
75
+ * free of cyclic properties etc.
76
+ *
77
+ * @private
78
+ * @param {Object} test
79
+ * @return {Object}
80
+ */
81
+ function clean(test) {
82
+ var err = test.err || {};
83
+ if (err instanceof Error) {
84
+ err = errorJSON(err);
85
+ }
86
+
87
+ return {
88
+ title: test.title,
89
+ fullTitle: test.fullTitle(),
90
+ duration: test.duration,
91
+ currentRetry: test.currentRetry(),
92
+ err: cleanCycles(err)
93
+ };
94
+ }
95
+
96
+ /**
97
+ * Replaces any circular references inside `obj` with '[object Object]'
98
+ *
99
+ * @private
100
+ * @param {Object} obj
101
+ * @return {Object}
102
+ */
103
+ function cleanCycles(obj) {
104
+ var cache = [];
105
+ return JSON.parse(
106
+ JSON.stringify(obj, function(key, value) {
107
+ if (typeof value === 'object' && value !== null) {
108
+ if (cache.indexOf(value) !== -1) {
109
+ // Instead of going in a circle, we'll print [object Object]
110
+ return '' + value;
111
+ }
112
+ cache.push(value);
113
+ }
114
+
115
+ return value;
116
+ })
117
+ );
118
+ }
119
+
120
+ /**
121
+ * Transform an Error object into a JSON object.
122
+ *
123
+ * @private
124
+ * @param {Error} err
125
+ * @return {Object}
126
+ */
127
+ function errorJSON(err) {
128
+ var res = {};
129
+ Object.getOwnPropertyNames(err).forEach(function(key) {
130
+ res[key] = err[key];
131
+ }, err);
132
+ return res;
133
+ }
134
+
135
+ JSONReporter.description = 'single JSON object';