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/growl.js CHANGED
@@ -1,136 +1,136 @@
1
- 'use strict';
2
-
3
- /**
4
- * Desktop Notifications module.
5
- * @module Growl
6
- */
7
-
8
- const os = require('os');
9
- const path = require('path');
10
- const {sync: which} = require('which');
11
- const {EVENT_RUN_END} = require('./runner').constants;
12
-
13
- /**
14
- * @summary
15
- * Checks if Growl notification support seems likely.
16
- *
17
- * @description
18
- * Glosses over the distinction between an unsupported platform
19
- * and one that lacks prerequisite software installations.
20
- *
21
- * @public
22
- * @see {@link https://github.com/tj/node-growl/blob/master/README.md|Prerequisite Installs}
23
- * @see {@link Mocha#growl}
24
- * @see {@link Mocha#isGrowlCapable}
25
- * @return {boolean} whether Growl notification support can be expected
26
- */
27
- exports.isCapable = () => {
28
- if (!process.browser) {
29
- return getSupportBinaries().reduce(
30
- (acc, binary) => acc || Boolean(which(binary, {nothrow: true})),
31
- false
32
- );
33
- }
34
- return false;
35
- };
36
-
37
- /**
38
- * Implements desktop notifications as a pseudo-reporter.
39
- *
40
- * @public
41
- * @see {@link Mocha#_growl}
42
- * @param {Runner} runner - Runner instance.
43
- */
44
- exports.notify = runner => {
45
- runner.once(EVENT_RUN_END, () => {
46
- display(runner);
47
- });
48
- };
49
-
50
- /**
51
- * Displays the notification.
52
- *
53
- * @private
54
- * @param {Runner} runner - Runner instance.
55
- */
56
- const display = runner => {
57
- const growl = require('growl');
58
- const stats = runner.stats;
59
- const symbol = {
60
- cross: '\u274C',
61
- tick: '\u2705'
62
- };
63
- let _message;
64
- let message;
65
- let title;
66
-
67
- if (stats.failures) {
68
- _message = `${stats.failures} of ${stats.tests} tests failed`;
69
- message = `${symbol.cross} ${_message}`;
70
- title = 'Failed';
71
- } else {
72
- _message = `${stats.passes} tests passed in ${stats.duration}ms`;
73
- message = `${symbol.tick} ${_message}`;
74
- title = 'Passed';
75
- }
76
-
77
- // Send notification
78
- const options = {
79
- image: logo(),
80
- name: 'mocha',
81
- title
82
- };
83
- growl(message, options, onCompletion);
84
- };
85
-
86
- /**
87
- * @summary
88
- * Callback for result of attempted Growl notification.
89
- *
90
- * @description
91
- * Despite its appearance, this is <strong>not</strong> an Error-first
92
- * callback -- all parameters are populated regardless of success.
93
- *
94
- * @private
95
- * @callback Growl~growlCB
96
- * @param {*} err - Error object, or <code>null</code> if successful.
97
- */
98
- function onCompletion(err) {
99
- if (err) {
100
- // As notifications are tangential to our purpose, just log the error.
101
- const message =
102
- err.code === 'ENOENT' ? 'prerequisite software not found' : err.message;
103
- console.error('notification error:', message);
104
- }
105
- }
106
-
107
- /**
108
- * Returns Mocha logo image path.
109
- *
110
- * @private
111
- * @return {string} Pathname of Mocha logo
112
- */
113
- const logo = () => {
114
- return path.join(__dirname, '..', 'assets', 'mocha-logo-96.png');
115
- };
116
-
117
- /**
118
- * @summary
119
- * Gets platform-specific Growl support binaries.
120
- *
121
- * @description
122
- * Somewhat brittle dependency on `growl` package implementation, but it
123
- * rarely changes.
124
- *
125
- * @private
126
- * @see {@link https://github.com/tj/node-growl/blob/master/lib/growl.js#L28-L126|setupCmd}
127
- * @return {string[]} names of Growl support binaries
128
- */
129
- const getSupportBinaries = () => {
130
- const binaries = {
131
- Darwin: ['terminal-notifier', 'growlnotify'],
132
- Linux: ['notify-send', 'growl'],
133
- Windows_NT: ['growlnotify.exe']
134
- };
135
- return binaries[os.type()] || [];
136
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Desktop Notifications module.
5
+ * @module Growl
6
+ */
7
+
8
+ const os = require('os');
9
+ const path = require('path');
10
+ const {sync: which} = require('which');
11
+ const {EVENT_RUN_END} = require('./runner').constants;
12
+
13
+ /**
14
+ * @summary
15
+ * Checks if Growl notification support seems likely.
16
+ *
17
+ * @description
18
+ * Glosses over the distinction between an unsupported platform
19
+ * and one that lacks prerequisite software installations.
20
+ *
21
+ * @public
22
+ * @see {@link https://github.com/tj/node-growl/blob/master/README.md|Prerequisite Installs}
23
+ * @see {@link Mocha#growl}
24
+ * @see {@link Mocha#isGrowlCapable}
25
+ * @return {boolean} whether Growl notification support can be expected
26
+ */
27
+ exports.isCapable = () => {
28
+ if (!process.browser) {
29
+ return getSupportBinaries().reduce(
30
+ (acc, binary) => acc || Boolean(which(binary, {nothrow: true})),
31
+ false
32
+ );
33
+ }
34
+ return false;
35
+ };
36
+
37
+ /**
38
+ * Implements desktop notifications as a pseudo-reporter.
39
+ *
40
+ * @public
41
+ * @see {@link Mocha#_growl}
42
+ * @param {Runner} runner - Runner instance.
43
+ */
44
+ exports.notify = runner => {
45
+ runner.once(EVENT_RUN_END, () => {
46
+ display(runner);
47
+ });
48
+ };
49
+
50
+ /**
51
+ * Displays the notification.
52
+ *
53
+ * @private
54
+ * @param {Runner} runner - Runner instance.
55
+ */
56
+ const display = runner => {
57
+ const growl = require('growl');
58
+ const stats = runner.stats;
59
+ const symbol = {
60
+ cross: '\u274C',
61
+ tick: '\u2705'
62
+ };
63
+ let _message;
64
+ let message;
65
+ let title;
66
+
67
+ if (stats.failures) {
68
+ _message = `${stats.failures} of ${stats.tests} tests failed`;
69
+ message = `${symbol.cross} ${_message}`;
70
+ title = 'Failed';
71
+ } else {
72
+ _message = `${stats.passes} tests passed in ${stats.duration}ms`;
73
+ message = `${symbol.tick} ${_message}`;
74
+ title = 'Passed';
75
+ }
76
+
77
+ // Send notification
78
+ const options = {
79
+ image: logo(),
80
+ name: 'mocha',
81
+ title
82
+ };
83
+ growl(message, options, onCompletion);
84
+ };
85
+
86
+ /**
87
+ * @summary
88
+ * Callback for result of attempted Growl notification.
89
+ *
90
+ * @description
91
+ * Despite its appearance, this is <strong>not</strong> an Error-first
92
+ * callback -- all parameters are populated regardless of success.
93
+ *
94
+ * @private
95
+ * @callback Growl~growlCB
96
+ * @param {*} err - Error object, or <code>null</code> if successful.
97
+ */
98
+ function onCompletion(err) {
99
+ if (err) {
100
+ // As notifications are tangential to our purpose, just log the error.
101
+ const message =
102
+ err.code === 'ENOENT' ? 'prerequisite software not found' : err.message;
103
+ console.error('notification error:', message);
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Returns Mocha logo image path.
109
+ *
110
+ * @private
111
+ * @return {string} Pathname of Mocha logo
112
+ */
113
+ const logo = () => {
114
+ return path.join(__dirname, '..', 'assets', 'mocha-logo-96.png');
115
+ };
116
+
117
+ /**
118
+ * @summary
119
+ * Gets platform-specific Growl support binaries.
120
+ *
121
+ * @description
122
+ * Somewhat brittle dependency on `growl` package implementation, but it
123
+ * rarely changes.
124
+ *
125
+ * @private
126
+ * @see {@link https://github.com/tj/node-growl/blob/master/lib/growl.js#L28-L126|setupCmd}
127
+ * @return {string[]} names of Growl support binaries
128
+ */
129
+ const getSupportBinaries = () => {
130
+ const binaries = {
131
+ Darwin: ['terminal-notifier', 'growlnotify'],
132
+ Linux: ['notify-send', 'growl'],
133
+ Windows_NT: ['growlnotify.exe']
134
+ };
135
+ return binaries[os.type()] || [];
136
+ };
package/lib/hook.js CHANGED
@@ -1,46 +1,46 @@
1
- 'use strict';
2
-
3
- var Runnable = require('./runnable');
4
- var inherits = require('./utils').inherits;
5
-
6
- /**
7
- * Expose `Hook`.
8
- */
9
-
10
- module.exports = Hook;
11
-
12
- /**
13
- * Initialize a new `Hook` with the given `title` and callback `fn`
14
- *
15
- * @class
16
- * @extends Runnable
17
- * @param {String} title
18
- * @param {Function} fn
19
- */
20
- function Hook(title, fn) {
21
- Runnable.call(this, title, fn);
22
- this.type = 'hook';
23
- }
24
-
25
- /**
26
- * Inherit from `Runnable.prototype`.
27
- */
28
- inherits(Hook, Runnable);
29
-
30
- /**
31
- * Get or set the test `err`.
32
- *
33
- * @memberof Hook
34
- * @public
35
- * @param {Error} err
36
- * @return {Error}
37
- */
38
- Hook.prototype.error = function(err) {
39
- if (!arguments.length) {
40
- err = this._error;
41
- this._error = null;
42
- return err;
43
- }
44
-
45
- this._error = err;
46
- };
1
+ 'use strict';
2
+
3
+ var Runnable = require('./runnable');
4
+ var inherits = require('./utils').inherits;
5
+
6
+ /**
7
+ * Expose `Hook`.
8
+ */
9
+
10
+ module.exports = Hook;
11
+
12
+ /**
13
+ * Initialize a new `Hook` with the given `title` and callback `fn`
14
+ *
15
+ * @class
16
+ * @extends Runnable
17
+ * @param {String} title
18
+ * @param {Function} fn
19
+ */
20
+ function Hook(title, fn) {
21
+ Runnable.call(this, title, fn);
22
+ this.type = 'hook';
23
+ }
24
+
25
+ /**
26
+ * Inherit from `Runnable.prototype`.
27
+ */
28
+ inherits(Hook, Runnable);
29
+
30
+ /**
31
+ * Get or set the test `err`.
32
+ *
33
+ * @memberof Hook
34
+ * @public
35
+ * @param {Error} err
36
+ * @return {Error}
37
+ */
38
+ Hook.prototype.error = function(err) {
39
+ if (!arguments.length) {
40
+ err = this._error;
41
+ this._error = null;
42
+ return err;
43
+ }
44
+
45
+ this._error = err;
46
+ };
@@ -1,118 +1,118 @@
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
- * Number of attempts to retry.
111
- */
112
- context.it.retries = function(n) {
113
- context.retries(n);
114
- };
115
- });
116
- };
117
-
118
- module.exports.description = 'BDD or RSpec style [default]';
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
+ * Number of attempts to retry.
111
+ */
112
+ context.it.retries = function(n) {
113
+ context.retries(n);
114
+ };
115
+ });
116
+ };
117
+
118
+ module.exports.description = 'BDD or RSpec style [default]';