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,168 +1,168 @@
1
- 'use strict';
2
-
3
- /**
4
- * Web Notifications module.
5
- * @module Growl
6
- */
7
-
8
- /**
9
- * Save timer references to avoid Sinon interfering (see GH-237).
10
- */
11
- var Date = global.Date;
12
- var setTimeout = global.setTimeout;
13
- var EVENT_RUN_END = require('../runner').constants.EVENT_RUN_END;
14
-
15
- /**
16
- * Checks if browser notification support exists.
17
- *
18
- * @public
19
- * @see {@link https://caniuse.com/#feat=notifications|Browser support (notifications)}
20
- * @see {@link https://caniuse.com/#feat=promises|Browser support (promises)}
21
- * @see {@link Mocha#growl}
22
- * @see {@link Mocha#isGrowlCapable}
23
- * @return {boolean} whether browser notification support exists
24
- */
25
- exports.isCapable = function() {
26
- var hasNotificationSupport = 'Notification' in window;
27
- var hasPromiseSupport = typeof Promise === 'function';
28
- return process.browser && hasNotificationSupport && hasPromiseSupport;
29
- };
30
-
31
- /**
32
- * Implements browser notifications as a pseudo-reporter.
33
- *
34
- * @public
35
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/notification|Notification API}
36
- * @see {@link https://developers.google.com/web/fundamentals/push-notifications/display-a-notification|Displaying a Notification}
37
- * @see {@link Growl#isPermitted}
38
- * @see {@link Mocha#_growl}
39
- * @param {Runner} runner - Runner instance.
40
- */
41
- exports.notify = function(runner) {
42
- var promise = isPermitted();
43
-
44
- /**
45
- * Attempt notification.
46
- */
47
- var sendNotification = function() {
48
- // If user hasn't responded yet... "No notification for you!" (Seinfeld)
49
- Promise.race([promise, Promise.resolve(undefined)])
50
- .then(canNotify)
51
- .then(function() {
52
- display(runner);
53
- })
54
- .catch(notPermitted);
55
- };
56
-
57
- runner.once(EVENT_RUN_END, sendNotification);
58
- };
59
-
60
- /**
61
- * Checks if browser notification is permitted by user.
62
- *
63
- * @private
64
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Notification/permission|Notification.permission}
65
- * @see {@link Mocha#growl}
66
- * @see {@link Mocha#isGrowlPermitted}
67
- * @returns {Promise<boolean>} promise determining if browser notification
68
- * permissible when fulfilled.
69
- */
70
- function isPermitted() {
71
- var permitted = {
72
- granted: function allow() {
73
- return Promise.resolve(true);
74
- },
75
- denied: function deny() {
76
- return Promise.resolve(false);
77
- },
78
- default: function ask() {
79
- return Notification.requestPermission().then(function(permission) {
80
- return permission === 'granted';
81
- });
82
- }
83
- };
84
-
85
- return permitted[Notification.permission]();
86
- }
87
-
88
- /**
89
- * @summary
90
- * Determines if notification should proceed.
91
- *
92
- * @description
93
- * Notification shall <strong>not</strong> proceed unless `value` is true.
94
- *
95
- * `value` will equal one of:
96
- * <ul>
97
- * <li><code>true</code> (from `isPermitted`)</li>
98
- * <li><code>false</code> (from `isPermitted`)</li>
99
- * <li><code>undefined</code> (from `Promise.race`)</li>
100
- * </ul>
101
- *
102
- * @private
103
- * @param {boolean|undefined} value - Determines if notification permissible.
104
- * @returns {Promise<undefined>} Notification can proceed
105
- */
106
- function canNotify(value) {
107
- if (!value) {
108
- var why = value === false ? 'blocked' : 'unacknowledged';
109
- var reason = 'not permitted by user (' + why + ')';
110
- return Promise.reject(new Error(reason));
111
- }
112
- return Promise.resolve();
113
- }
114
-
115
- /**
116
- * Displays the notification.
117
- *
118
- * @private
119
- * @param {Runner} runner - Runner instance.
120
- */
121
- function display(runner) {
122
- var stats = runner.stats;
123
- var symbol = {
124
- cross: '\u274C',
125
- tick: '\u2705'
126
- };
127
- var logo = require('../../package').notifyLogo;
128
- var _message;
129
- var message;
130
- var title;
131
-
132
- if (stats.failures) {
133
- _message = stats.failures + ' of ' + stats.tests + ' tests failed';
134
- message = symbol.cross + ' ' + _message;
135
- title = 'Failed';
136
- } else {
137
- _message = stats.passes + ' tests passed in ' + stats.duration + 'ms';
138
- message = symbol.tick + ' ' + _message;
139
- title = 'Passed';
140
- }
141
-
142
- // Send notification
143
- var options = {
144
- badge: logo,
145
- body: message,
146
- dir: 'ltr',
147
- icon: logo,
148
- lang: 'en-US',
149
- name: 'mocha',
150
- requireInteraction: false,
151
- timestamp: Date.now()
152
- };
153
- var notification = new Notification(title, options);
154
-
155
- // Autoclose after brief delay (makes various browsers act same)
156
- var FORCE_DURATION = 4000;
157
- setTimeout(notification.close.bind(notification), FORCE_DURATION);
158
- }
159
-
160
- /**
161
- * As notifications are tangential to our purpose, just log the error.
162
- *
163
- * @private
164
- * @param {Error} err - Why notification didn't happen.
165
- */
166
- function notPermitted(err) {
167
- console.error('notification error:', err.message);
168
- }
1
+ 'use strict';
2
+
3
+ /**
4
+ * Web Notifications module.
5
+ * @module Growl
6
+ */
7
+
8
+ /**
9
+ * Save timer references to avoid Sinon interfering (see GH-237).
10
+ */
11
+ var Date = global.Date;
12
+ var setTimeout = global.setTimeout;
13
+ var EVENT_RUN_END = require('../runner').constants.EVENT_RUN_END;
14
+
15
+ /**
16
+ * Checks if browser notification support exists.
17
+ *
18
+ * @public
19
+ * @see {@link https://caniuse.com/#feat=notifications|Browser support (notifications)}
20
+ * @see {@link https://caniuse.com/#feat=promises|Browser support (promises)}
21
+ * @see {@link Mocha#growl}
22
+ * @see {@link Mocha#isGrowlCapable}
23
+ * @return {boolean} whether browser notification support exists
24
+ */
25
+ exports.isCapable = function() {
26
+ var hasNotificationSupport = 'Notification' in window;
27
+ var hasPromiseSupport = typeof Promise === 'function';
28
+ return process.browser && hasNotificationSupport && hasPromiseSupport;
29
+ };
30
+
31
+ /**
32
+ * Implements browser notifications as a pseudo-reporter.
33
+ *
34
+ * @public
35
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/notification|Notification API}
36
+ * @see {@link https://developers.google.com/web/fundamentals/push-notifications/display-a-notification|Displaying a Notification}
37
+ * @see {@link Growl#isPermitted}
38
+ * @see {@link Mocha#_growl}
39
+ * @param {Runner} runner - Runner instance.
40
+ */
41
+ exports.notify = function(runner) {
42
+ var promise = isPermitted();
43
+
44
+ /**
45
+ * Attempt notification.
46
+ */
47
+ var sendNotification = function() {
48
+ // If user hasn't responded yet... "No notification for you!" (Seinfeld)
49
+ Promise.race([promise, Promise.resolve(undefined)])
50
+ .then(canNotify)
51
+ .then(function() {
52
+ display(runner);
53
+ })
54
+ .catch(notPermitted);
55
+ };
56
+
57
+ runner.once(EVENT_RUN_END, sendNotification);
58
+ };
59
+
60
+ /**
61
+ * Checks if browser notification is permitted by user.
62
+ *
63
+ * @private
64
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Notification/permission|Notification.permission}
65
+ * @see {@link Mocha#growl}
66
+ * @see {@link Mocha#isGrowlPermitted}
67
+ * @returns {Promise<boolean>} promise determining if browser notification
68
+ * permissible when fulfilled.
69
+ */
70
+ function isPermitted() {
71
+ var permitted = {
72
+ granted: function allow() {
73
+ return Promise.resolve(true);
74
+ },
75
+ denied: function deny() {
76
+ return Promise.resolve(false);
77
+ },
78
+ default: function ask() {
79
+ return Notification.requestPermission().then(function(permission) {
80
+ return permission === 'granted';
81
+ });
82
+ }
83
+ };
84
+
85
+ return permitted[Notification.permission]();
86
+ }
87
+
88
+ /**
89
+ * @summary
90
+ * Determines if notification should proceed.
91
+ *
92
+ * @description
93
+ * Notification shall <strong>not</strong> proceed unless `value` is true.
94
+ *
95
+ * `value` will equal one of:
96
+ * <ul>
97
+ * <li><code>true</code> (from `isPermitted`)</li>
98
+ * <li><code>false</code> (from `isPermitted`)</li>
99
+ * <li><code>undefined</code> (from `Promise.race`)</li>
100
+ * </ul>
101
+ *
102
+ * @private
103
+ * @param {boolean|undefined} value - Determines if notification permissible.
104
+ * @returns {Promise<undefined>} Notification can proceed
105
+ */
106
+ function canNotify(value) {
107
+ if (!value) {
108
+ var why = value === false ? 'blocked' : 'unacknowledged';
109
+ var reason = 'not permitted by user (' + why + ')';
110
+ return Promise.reject(new Error(reason));
111
+ }
112
+ return Promise.resolve();
113
+ }
114
+
115
+ /**
116
+ * Displays the notification.
117
+ *
118
+ * @private
119
+ * @param {Runner} runner - Runner instance.
120
+ */
121
+ function display(runner) {
122
+ var stats = runner.stats;
123
+ var symbol = {
124
+ cross: '\u274C',
125
+ tick: '\u2705'
126
+ };
127
+ var logo = require('../../package').notifyLogo;
128
+ var _message;
129
+ var message;
130
+ var title;
131
+
132
+ if (stats.failures) {
133
+ _message = stats.failures + ' of ' + stats.tests + ' tests failed';
134
+ message = symbol.cross + ' ' + _message;
135
+ title = 'Failed';
136
+ } else {
137
+ _message = stats.passes + ' tests passed in ' + stats.duration + 'ms';
138
+ message = symbol.tick + ' ' + _message;
139
+ title = 'Passed';
140
+ }
141
+
142
+ // Send notification
143
+ var options = {
144
+ badge: logo,
145
+ body: message,
146
+ dir: 'ltr',
147
+ icon: logo,
148
+ lang: 'en-US',
149
+ name: 'mocha',
150
+ requireInteraction: false,
151
+ timestamp: Date.now()
152
+ };
153
+ var notification = new Notification(title, options);
154
+
155
+ // Autoclose after brief delay (makes various browsers act same)
156
+ var FORCE_DURATION = 4000;
157
+ setTimeout(notification.close.bind(notification), FORCE_DURATION);
158
+ }
159
+
160
+ /**
161
+ * As notifications are tangential to our purpose, just log the error.
162
+ *
163
+ * @private
164
+ * @param {Error} err - Why notification didn't happen.
165
+ */
166
+ function notPermitted(err) {
167
+ console.error('notification error:', err.message);
168
+ }
@@ -1,119 +1,119 @@
1
- 'use strict';
2
-
3
- /**
4
- * Expose `Progress`.
5
- */
6
-
7
- module.exports = Progress;
8
-
9
- /**
10
- * Initialize a new `Progress` indicator.
11
- */
12
- function Progress() {
13
- this.percent = 0;
14
- this.size(0);
15
- this.fontSize(11);
16
- this.font('helvetica, arial, sans-serif');
17
- }
18
-
19
- /**
20
- * Set progress size to `size`.
21
- *
22
- * @public
23
- * @param {number} size
24
- * @return {Progress} Progress instance.
25
- */
26
- Progress.prototype.size = function(size) {
27
- this._size = size;
28
- return this;
29
- };
30
-
31
- /**
32
- * Set text to `text`.
33
- *
34
- * @public
35
- * @param {string} text
36
- * @return {Progress} Progress instance.
37
- */
38
- Progress.prototype.text = function(text) {
39
- this._text = text;
40
- return this;
41
- };
42
-
43
- /**
44
- * Set font size to `size`.
45
- *
46
- * @public
47
- * @param {number} size
48
- * @return {Progress} Progress instance.
49
- */
50
- Progress.prototype.fontSize = function(size) {
51
- this._fontSize = size;
52
- return this;
53
- };
54
-
55
- /**
56
- * Set font to `family`.
57
- *
58
- * @param {string} family
59
- * @return {Progress} Progress instance.
60
- */
61
- Progress.prototype.font = function(family) {
62
- this._font = family;
63
- return this;
64
- };
65
-
66
- /**
67
- * Update percentage to `n`.
68
- *
69
- * @param {number} n
70
- * @return {Progress} Progress instance.
71
- */
72
- Progress.prototype.update = function(n) {
73
- this.percent = n;
74
- return this;
75
- };
76
-
77
- /**
78
- * Draw on `ctx`.
79
- *
80
- * @param {CanvasRenderingContext2d} ctx
81
- * @return {Progress} Progress instance.
82
- */
83
- Progress.prototype.draw = function(ctx) {
84
- try {
85
- var percent = Math.min(this.percent, 100);
86
- var size = this._size;
87
- var half = size / 2;
88
- var x = half;
89
- var y = half;
90
- var rad = half - 1;
91
- var fontSize = this._fontSize;
92
-
93
- ctx.font = fontSize + 'px ' + this._font;
94
-
95
- var angle = Math.PI * 2 * (percent / 100);
96
- ctx.clearRect(0, 0, size, size);
97
-
98
- // outer circle
99
- ctx.strokeStyle = '#9f9f9f';
100
- ctx.beginPath();
101
- ctx.arc(x, y, rad, 0, angle, false);
102
- ctx.stroke();
103
-
104
- // inner circle
105
- ctx.strokeStyle = '#eee';
106
- ctx.beginPath();
107
- ctx.arc(x, y, rad - 1, 0, angle, true);
108
- ctx.stroke();
109
-
110
- // text
111
- var text = this._text || (percent | 0) + '%';
112
- var w = ctx.measureText(text).width;
113
-
114
- ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
115
- } catch (ignore) {
116
- // don't fail if we can't render progress
117
- }
118
- return this;
119
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Expose `Progress`.
5
+ */
6
+
7
+ module.exports = Progress;
8
+
9
+ /**
10
+ * Initialize a new `Progress` indicator.
11
+ */
12
+ function Progress() {
13
+ this.percent = 0;
14
+ this.size(0);
15
+ this.fontSize(11);
16
+ this.font('helvetica, arial, sans-serif');
17
+ }
18
+
19
+ /**
20
+ * Set progress size to `size`.
21
+ *
22
+ * @public
23
+ * @param {number} size
24
+ * @return {Progress} Progress instance.
25
+ */
26
+ Progress.prototype.size = function(size) {
27
+ this._size = size;
28
+ return this;
29
+ };
30
+
31
+ /**
32
+ * Set text to `text`.
33
+ *
34
+ * @public
35
+ * @param {string} text
36
+ * @return {Progress} Progress instance.
37
+ */
38
+ Progress.prototype.text = function(text) {
39
+ this._text = text;
40
+ return this;
41
+ };
42
+
43
+ /**
44
+ * Set font size to `size`.
45
+ *
46
+ * @public
47
+ * @param {number} size
48
+ * @return {Progress} Progress instance.
49
+ */
50
+ Progress.prototype.fontSize = function(size) {
51
+ this._fontSize = size;
52
+ return this;
53
+ };
54
+
55
+ /**
56
+ * Set font to `family`.
57
+ *
58
+ * @param {string} family
59
+ * @return {Progress} Progress instance.
60
+ */
61
+ Progress.prototype.font = function(family) {
62
+ this._font = family;
63
+ return this;
64
+ };
65
+
66
+ /**
67
+ * Update percentage to `n`.
68
+ *
69
+ * @param {number} n
70
+ * @return {Progress} Progress instance.
71
+ */
72
+ Progress.prototype.update = function(n) {
73
+ this.percent = n;
74
+ return this;
75
+ };
76
+
77
+ /**
78
+ * Draw on `ctx`.
79
+ *
80
+ * @param {CanvasRenderingContext2d} ctx
81
+ * @return {Progress} Progress instance.
82
+ */
83
+ Progress.prototype.draw = function(ctx) {
84
+ try {
85
+ var percent = Math.min(this.percent, 100);
86
+ var size = this._size;
87
+ var half = size / 2;
88
+ var x = half;
89
+ var y = half;
90
+ var rad = half - 1;
91
+ var fontSize = this._fontSize;
92
+
93
+ ctx.font = fontSize + 'px ' + this._font;
94
+
95
+ var angle = Math.PI * 2 * (percent / 100);
96
+ ctx.clearRect(0, 0, size, size);
97
+
98
+ // outer circle
99
+ ctx.strokeStyle = '#9f9f9f';
100
+ ctx.beginPath();
101
+ ctx.arc(x, y, rad, 0, angle, false);
102
+ ctx.stroke();
103
+
104
+ // inner circle
105
+ ctx.strokeStyle = '#eee';
106
+ ctx.beginPath();
107
+ ctx.arc(x, y, rad - 1, 0, angle, true);
108
+ ctx.stroke();
109
+
110
+ // text
111
+ var text = this._text || (percent | 0) + '%';
112
+ var w = ctx.measureText(text).width;
113
+
114
+ ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
115
+ } catch (ignore) {
116
+ // don't fail if we can't render progress
117
+ }
118
+ return this;
119
+ };
@@ -1,18 +1,18 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Mocha</title>
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <link rel="stylesheet" href="mocha.css">
8
- </head>
9
- <body>
10
- <div id="mocha"></div>
11
- <script src="mocha.js"></script>
12
- <script>mocha.setup('bdd');</script>
13
- <script src="tests.js"></script>
14
- <script>
15
- mocha.run();
16
- </script>
17
- </body>
18
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Mocha</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <link rel="stylesheet" href="mocha.css">
8
+ </head>
9
+ <body>
10
+ <div id="mocha"></div>
11
+ <script src="mocha.js"></script>
12
+ <script>mocha.setup('bdd');</script>
13
+ <script src="tests.js"></script>
14
+ <script>
15
+ mocha.run();
16
+ </script>
17
+ </body>
18
+ </html>
@@ -1,13 +1,13 @@
1
- 'use strict';
2
-
3
- exports.isatty = function isatty() {
4
- return true;
5
- };
6
-
7
- exports.getWindowSize = function getWindowSize() {
8
- if ('innerHeight' in global) {
9
- return [global.innerHeight, global.innerWidth];
10
- }
11
- // In a Web Worker, the DOM Window is not available.
12
- return [640, 480];
13
- };
1
+ 'use strict';
2
+
3
+ exports.isatty = function isatty() {
4
+ return true;
5
+ };
6
+
7
+ exports.getWindowSize = function getWindowSize() {
8
+ if ('innerHeight' in global) {
9
+ return [global.innerHeight, global.innerWidth];
10
+ }
11
+ // In a Web Worker, the DOM Window is not available.
12
+ return [640, 480];
13
+ };