mocha 10.0.0 → 10.2.0

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.
@@ -86,6 +86,20 @@ Progress.prototype.update = function (n) {
86
86
  */
87
87
  Progress.prototype.draw = function (ctx) {
88
88
  try {
89
+ var darkMatcher = window.matchMedia('(prefers-color-scheme: dark)');
90
+ var isDarkMode = !!darkMatcher.matches;
91
+ var lightColors = {
92
+ outerCircle: '#9f9f9f',
93
+ innerCircle: '#eee',
94
+ text: '#000'
95
+ };
96
+ var darkColors = {
97
+ outerCircle: '#888',
98
+ innerCircle: '#444',
99
+ text: '#fff'
100
+ };
101
+ var colors = isDarkMode ? darkColors : lightColors;
102
+
89
103
  var percent = Math.min(this.percent, 100);
90
104
  var size = this._size;
91
105
  var half = size / 2;
@@ -100,13 +114,13 @@ Progress.prototype.draw = function (ctx) {
100
114
  ctx.clearRect(0, 0, size, size);
101
115
 
102
116
  // outer circle
103
- ctx.strokeStyle = '#9f9f9f';
117
+ ctx.strokeStyle = colors.outerCircle;
104
118
  ctx.beginPath();
105
119
  ctx.arc(x, y, rad, 0, angle, false);
106
120
  ctx.stroke();
107
121
 
108
122
  // inner circle
109
- ctx.strokeStyle = '#eee';
123
+ ctx.strokeStyle = colors.innerCircle;
110
124
  ctx.beginPath();
111
125
  ctx.arc(x, y, rad - 1, 0, angle, true);
112
126
  ctx.stroke();
@@ -115,6 +129,7 @@ Progress.prototype.draw = function (ctx) {
115
129
  var text = this._text || (percent | 0) + '%';
116
130
  var w = ctx.measureText(text).width;
117
131
 
132
+ ctx.fillStyle = colors.text;
118
133
  ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
119
134
  } catch (ignore) {
120
135
  // don't fail if we can't render progress
@@ -40,9 +40,9 @@ module.exports = function bddInterface(suite) {
40
40
 
41
41
  context.describe = context.context = function (title, fn) {
42
42
  return common.suite.create({
43
- title: title,
44
- file: file,
45
- fn: fn
43
+ title,
44
+ file,
45
+ fn
46
46
  });
47
47
  };
48
48
 
@@ -55,9 +55,9 @@ module.exports = function bddInterface(suite) {
55
55
  context.describe.skip =
56
56
  function (title, fn) {
57
57
  return common.suite.skip({
58
- title: title,
59
- file: file,
60
- fn: fn
58
+ title,
59
+ file,
60
+ fn
61
61
  });
62
62
  };
63
63
 
@@ -67,9 +67,9 @@ module.exports = function bddInterface(suite) {
67
67
 
68
68
  context.describe.only = function (title, fn) {
69
69
  return common.suite.only({
70
- title: title,
71
- file: file,
72
- fn: fn
70
+ title,
71
+ file,
72
+ fn
73
73
  });
74
74
  };
75
75
 
@@ -49,8 +49,8 @@ module.exports = function qUnitInterface(suite) {
49
49
  suites.shift();
50
50
  }
51
51
  return common.suite.create({
52
- title: title,
53
- file: file,
52
+ title,
53
+ file,
54
54
  fn: false
55
55
  });
56
56
  };
@@ -64,8 +64,8 @@ module.exports = function qUnitInterface(suite) {
64
64
  suites.shift();
65
65
  }
66
66
  return common.suite.only({
67
- title: title,
68
- file: file,
67
+ title,
68
+ file,
69
69
  fn: false
70
70
  });
71
71
  };
@@ -47,9 +47,9 @@ module.exports = function (suite) {
47
47
  */
48
48
  context.suite = function (title, fn) {
49
49
  return common.suite.create({
50
- title: title,
51
- file: file,
52
- fn: fn
50
+ title,
51
+ file,
52
+ fn
53
53
  });
54
54
  };
55
55
 
@@ -58,9 +58,9 @@ module.exports = function (suite) {
58
58
  */
59
59
  context.suite.skip = function (title, fn) {
60
60
  return common.suite.skip({
61
- title: title,
62
- file: file,
63
- fn: fn
61
+ title,
62
+ file,
63
+ fn
64
64
  });
65
65
  };
66
66
 
@@ -69,9 +69,9 @@ module.exports = function (suite) {
69
69
  */
70
70
  context.suite.only = function (title, fn) {
71
71
  return common.suite.only({
72
- title: title,
73
- file: file,
74
- fn: fn
72
+ title,
73
+ file,
74
+ fn
75
75
  });
76
76
  };
77
77
 
package/lib/mocha.js CHANGED
@@ -429,6 +429,8 @@ Mocha.prototype.loadFiles = function (fn) {
429
429
  * @see {@link Mocha#addFile}
430
430
  * @see {@link Mocha#run}
431
431
  * @see {@link Mocha#unloadFiles}
432
+ * @param {Object} [options] - Settings object.
433
+ * @param {Function} [options.esmDecorator] - Function invoked on esm module name right before importing it. By default will passthrough as is.
432
434
  * @returns {Promise}
433
435
  * @example
434
436
  *
@@ -437,7 +439,7 @@ Mocha.prototype.loadFiles = function (fn) {
437
439
  * .then(() => mocha.run(failures => process.exitCode = failures ? 1 : 0))
438
440
  * .catch(() => process.exitCode = 1);
439
441
  */
440
- Mocha.prototype.loadFilesAsync = function () {
442
+ Mocha.prototype.loadFilesAsync = function ({esmDecorator} = {}) {
441
443
  var self = this;
442
444
  var suite = this.suite;
443
445
  this.lazyLoadFiles(true);
@@ -450,7 +452,8 @@ Mocha.prototype.loadFilesAsync = function () {
450
452
  function (file, resultModule) {
451
453
  suite.emit(EVENT_FILE_REQUIRE, resultModule, file, self);
452
454
  suite.emit(EVENT_FILE_POST_REQUIRE, global, file, self);
453
- }
455
+ },
456
+ esmDecorator
454
457
  );
455
458
  };
456
459
 
@@ -1,10 +1,12 @@
1
1
  const path = require('path');
2
2
  const url = require('url');
3
3
 
4
- const formattedImport = async file => {
4
+ const forward = x => x;
5
+
6
+ const formattedImport = async (file, esmDecorator = forward) => {
5
7
  if (path.isAbsolute(file)) {
6
8
  try {
7
- return await import(url.pathToFileURL(file));
9
+ return await exports.doImport(esmDecorator(url.pathToFileURL(file)));
8
10
  } catch (err) {
9
11
  // This is a hack created because ESM in Node.js (at least in Node v15.5.1) does not emit
10
12
  // the location of the syntax error in the error thrown.
@@ -27,15 +29,17 @@ const formattedImport = async file => {
27
29
  throw err;
28
30
  }
29
31
  }
30
- return import(file);
32
+ return exports.doImport(esmDecorator(file));
31
33
  };
32
34
 
33
- exports.requireOrImport = async file => {
35
+ exports.doImport = async file => import(file);
36
+
37
+ exports.requireOrImport = async (file, esmDecorator) => {
34
38
  if (path.extname(file) === '.mjs') {
35
- return formattedImport(file);
39
+ return formattedImport(file, esmDecorator);
36
40
  }
37
41
  try {
38
- return dealWithExports(await formattedImport(file));
42
+ return dealWithExports(await formattedImport(file, esmDecorator));
39
43
  } catch (err) {
40
44
  if (
41
45
  err.code === 'ERR_MODULE_NOT_FOUND' ||
@@ -85,10 +89,18 @@ function dealWithExports(module) {
85
89
  }
86
90
  }
87
91
 
88
- exports.loadFilesAsync = async (files, preLoadFunc, postLoadFunc) => {
92
+ exports.loadFilesAsync = async (
93
+ files,
94
+ preLoadFunc,
95
+ postLoadFunc,
96
+ esmDecorator
97
+ ) => {
89
98
  for (const file of files) {
90
99
  preLoadFunc(file);
91
- const result = await exports.requireOrImport(path.resolve(file));
100
+ const result = await exports.requireOrImport(
101
+ path.resolve(file),
102
+ esmDecorator
103
+ );
92
104
  postLoadFunc(file, result);
93
105
  }
94
106
  };
@@ -6,7 +6,6 @@
6
6
 
7
7
  'use strict';
8
8
 
9
- const allSettled = require('@ungap/promise-all-settled').bind(Promise);
10
9
  const Runner = require('../runner');
11
10
  const {EVENT_RUN_BEGIN, EVENT_RUN_END} = Runner.constants;
12
11
  const debug = require('debug')('mocha:parallel:parallel-buffered-runner');
@@ -322,7 +321,7 @@ class ParallelBufferedRunner extends Runner {
322
321
  delete options[opt];
323
322
  });
324
323
 
325
- const results = await allSettled(
324
+ const results = await Promise.allSettled(
326
325
  files.map(this._createFileRunner(pool, options))
327
326
  );
328
327
 
@@ -36,7 +36,7 @@ function JSONStream(runner, options) {
36
36
  var total = runner.total;
37
37
 
38
38
  runner.once(EVENT_RUN_BEGIN, function () {
39
- writeEvent(['start', {total: total}]);
39
+ writeEvent(['start', {total}]);
40
40
  });
41
41
 
42
42
  runner.on(EVENT_TEST_PASS, function (test) {
@@ -50,7 +50,7 @@ function Markdown(runner, options) {
50
50
  var ret = obj;
51
51
  var key = SUITE_PREFIX + suite.title;
52
52
 
53
- obj = obj[key] = obj[key] || {suite: suite};
53
+ obj = obj[key] = obj[key] || {suite};
54
54
  suite.suites.forEach(function (suite) {
55
55
  mapTOC(suite, obj);
56
56
  });
package/lib/utils.js CHANGED
@@ -76,7 +76,7 @@ exports.clean = function (str) {
76
76
  .replace(/^\uFEFF/, '')
77
77
  // (traditional)-> space/name parameters body (lambda)-> parameters body multi-statement/single keep body content
78
78
  .replace(
79
- /^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/,
79
+ /^function(?:\s*|\s[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\}|((?:.|\n)*))$/,
80
80
  '$1$2$3'
81
81
  );
82
82
 
package/mocha.css CHANGED
@@ -1,7 +1,73 @@
1
1
  @charset "utf-8";
2
2
 
3
+ :root {
4
+ --mocha-color: #000;
5
+ --mocha-bg-color: #fff;
6
+ --mocha-pass-icon-color: #00d6b2;
7
+ --mocha-pass-color: #fff;
8
+ --mocha-pass-shadow-color: rgba(0,0,0,.2);
9
+ --mocha-pass-mediump-color: #c09853;
10
+ --mocha-pass-slow-color: #b94a48;
11
+ --mocha-test-pending-color: #0b97c4;
12
+ --mocha-test-pending-icon-color: #0b97c4;
13
+ --mocha-test-fail-color: #c00;
14
+ --mocha-test-fail-icon-color: #c00;
15
+ --mocha-test-fail-pre-color: #000;
16
+ --mocha-test-fail-pre-error-color: #c00;
17
+ --mocha-test-html-error-color: #000;
18
+ --mocha-box-shadow-color: #eee;
19
+ --mocha-box-bottom-color: #ddd;
20
+ --mocha-test-replay-color: #000;
21
+ --mocha-test-replay-bg-color: #eee;
22
+ --mocha-stats-color: #888;
23
+ --mocha-stats-em-color: #000;
24
+ --mocha-stats-hover-color: #eee;
25
+ --mocha-error-color: #c00;
26
+
27
+ --mocha-code-comment: #ddd;
28
+ --mocha-code-init: #2f6fad;
29
+ --mocha-code-string: #5890ad;
30
+ --mocha-code-keyword: #8a6343;
31
+ --mocha-code-number: #2f6fad;
32
+ }
33
+
34
+ @media (prefers-color-scheme: dark) {
35
+ :root {
36
+ --mocha-color: #fff;
37
+ --mocha-bg-color: #222;
38
+ --mocha-pass-icon-color: #00d6b2;
39
+ --mocha-pass-color: #222;
40
+ --mocha-pass-shadow-color: rgba(255,255,255,.2);
41
+ --mocha-pass-mediump-color: #f1be67;
42
+ --mocha-pass-slow-color: #f49896;
43
+ --mocha-test-pending-color: #0b97c4;
44
+ --mocha-test-pending-icon-color: #0b97c4;
45
+ --mocha-test-fail-color: #f44;
46
+ --mocha-test-fail-icon-color: #f44;
47
+ --mocha-test-fail-pre-color: #fff;
48
+ --mocha-test-fail-pre-error-color: #f44;
49
+ --mocha-test-html-error-color: #fff;
50
+ --mocha-box-shadow-color: #444;
51
+ --mocha-box-bottom-color: #555;
52
+ --mocha-test-replay-color: #fff;
53
+ --mocha-test-replay-bg-color: #444;
54
+ --mocha-stats-color: #aaa;
55
+ --mocha-stats-em-color: #fff;
56
+ --mocha-stats-hover-color: #444;
57
+ --mocha-error-color: #f44;
58
+
59
+ --mocha-code-comment: #ddd;
60
+ --mocha-code-init: #9cc7f1;
61
+ --mocha-code-string: #80d4ff;
62
+ --mocha-code-keyword: #e3a470;
63
+ --mocha-code-number: #4ca7ff;
64
+ }
65
+ }
66
+
3
67
  body {
4
68
  margin:0;
69
+ background-color: var(--mocha-bg-color);
70
+ color: var(--mocha-color);
5
71
  }
6
72
 
7
73
  #mocha {
@@ -69,11 +135,11 @@ body {
69
135
  }
70
136
 
71
137
  #mocha .test.pass.medium .duration {
72
- background: #c09853;
138
+ background: var(--mocha-pass-mediump-color);
73
139
  }
74
140
 
75
141
  #mocha .test.pass.slow .duration {
76
- background: #b94a48;
142
+ background: var(--mocha-pass-slow-color);
77
143
  }
78
144
 
79
145
  #mocha .test.pass::before {
@@ -82,17 +148,17 @@ body {
82
148
  display: block;
83
149
  float: left;
84
150
  margin-right: 5px;
85
- color: #00d6b2;
151
+ color: var(--mocha-pass-icon-color);
86
152
  }
87
153
 
88
154
  #mocha .test.pass .duration {
89
155
  font-size: 9px;
90
156
  margin-left: 5px;
91
157
  padding: 2px 5px;
92
- color: #fff;
93
- -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
94
- -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
95
- box-shadow: inset 0 1px 1px rgba(0,0,0,.2);
158
+ color: var(--mocha-pass-color);
159
+ -webkit-box-shadow: inset 0 1px 1px var(--mocha-pass-shadow-color);
160
+ -moz-box-shadow: inset 0 1px 1px var(--mocha-pass-shadow-color);
161
+ box-shadow: inset 0 1px 1px var(--mocha-pass-shadow-color);
96
162
  -webkit-border-radius: 5px;
97
163
  -moz-border-radius: 5px;
98
164
  -ms-border-radius: 5px;
@@ -105,20 +171,20 @@ body {
105
171
  }
106
172
 
107
173
  #mocha .test.pending {
108
- color: #0b97c4;
174
+ color: var(--mocha-test-pending-color);
109
175
  }
110
176
 
111
177
  #mocha .test.pending::before {
112
178
  content: '◦';
113
- color: #0b97c4;
179
+ color: var(--mocha-test-pending-icon-color);
114
180
  }
115
181
 
116
182
  #mocha .test.fail {
117
- color: #c00;
183
+ color: var(--mocha-test-fail-color);
118
184
  }
119
185
 
120
186
  #mocha .test.fail pre {
121
- color: black;
187
+ color: var(--mocha-test-fail-pre-color);
122
188
  }
123
189
 
124
190
  #mocha .test.fail::before {
@@ -127,35 +193,35 @@ body {
127
193
  display: block;
128
194
  float: left;
129
195
  margin-right: 5px;
130
- color: #c00;
196
+ color: var(--mocha-test-fail-icon-color);
131
197
  }
132
198
 
133
199
  #mocha .test pre.error {
134
- color: #c00;
200
+ color: var(--mocha-test-fail-pre-error-color);
135
201
  max-height: 300px;
136
202
  overflow: auto;
137
203
  }
138
204
 
139
205
  #mocha .test .html-error {
140
206
  overflow: auto;
141
- color: black;
207
+ color: var(--mocha-test-html-error-color);
142
208
  display: block;
143
209
  float: left;
144
210
  clear: left;
145
211
  font: 12px/1.5 monaco, monospace;
146
212
  margin: 5px;
147
213
  padding: 15px;
148
- border: 1px solid #eee;
214
+ border: 1px solid var(--mocha-box-shadow-color);
149
215
  max-width: 85%; /*(1)*/
150
216
  max-width: -webkit-calc(100% - 42px);
151
217
  max-width: -moz-calc(100% - 42px);
152
218
  max-width: calc(100% - 42px); /*(2)*/
153
219
  max-height: 300px;
154
220
  word-wrap: break-word;
155
- border-bottom-color: #ddd;
156
- -webkit-box-shadow: 0 1px 3px #eee;
157
- -moz-box-shadow: 0 1px 3px #eee;
158
- box-shadow: 0 1px 3px #eee;
221
+ border-bottom-color: var(--mocha-box-bottom-color);
222
+ -webkit-box-shadow: 0 1px 3px var(--mocha-box-shadow-color);
223
+ -moz-box-shadow: 0 1px 3px var(--mocha-box-shadow-color);
224
+ box-shadow: 0 1px 3px var(--mocha-box-shadow-color);
159
225
  -webkit-border-radius: 3px;
160
226
  -moz-border-radius: 3px;
161
227
  border-radius: 3px;
@@ -187,16 +253,16 @@ body {
187
253
  font: 12px/1.5 monaco, monospace;
188
254
  margin: 5px;
189
255
  padding: 15px;
190
- border: 1px solid #eee;
256
+ border: 1px solid var(--mocha-box-shadow-color);
191
257
  max-width: 85%; /*(1)*/
192
258
  max-width: -webkit-calc(100% - 42px);
193
259
  max-width: -moz-calc(100% - 42px);
194
260
  max-width: calc(100% - 42px); /*(2)*/
195
261
  word-wrap: break-word;
196
- border-bottom-color: #ddd;
197
- -webkit-box-shadow: 0 1px 3px #eee;
198
- -moz-box-shadow: 0 1px 3px #eee;
199
- box-shadow: 0 1px 3px #eee;
262
+ border-bottom-color: var(--mocha-box-bottom-color);
263
+ -webkit-box-shadow: 0 1px 3px var(--mocha-box-shadow-color);
264
+ -moz-box-shadow: 0 1px 3px var(--mocha-box-shadow-color);
265
+ box-shadow: 0 1px 3px var(--mocha-box-shadow-color);
200
266
  -webkit-border-radius: 3px;
201
267
  -moz-border-radius: 3px;
202
268
  border-radius: 3px;
@@ -217,7 +283,7 @@ body {
217
283
  height: 15px;
218
284
  line-height: 15px;
219
285
  text-align: center;
220
- background: #eee;
286
+ background: var(--mocha-test-replay-bg-color);
221
287
  font-size: 15px;
222
288
  -webkit-border-radius: 15px;
223
289
  -moz-border-radius: 15px;
@@ -226,11 +292,12 @@ body {
226
292
  -moz-transition:opacity 200ms;
227
293
  -o-transition:opacity 200ms;
228
294
  transition: opacity 200ms;
229
- opacity: 0.3;
230
- color: #888;
295
+ opacity: 0.7;
296
+ color: var(--mocha-test-replay-color);
231
297
  }
232
298
 
233
299
  #mocha .test:hover a.replay {
300
+ box-shadow: 0 0 1px inset var(--mocha-test-replay-color);
234
301
  opacity: 1;
235
302
  }
236
303
 
@@ -251,7 +318,7 @@ body {
251
318
  }
252
319
 
253
320
  #mocha-error {
254
- color: #c00;
321
+ color: var(--mocha-error-color);
255
322
  font-size: 1.5em;
256
323
  font-weight: 100;
257
324
  letter-spacing: 1px;
@@ -263,7 +330,7 @@ body {
263
330
  right: 10px;
264
331
  font-size: 12px;
265
332
  margin: 0;
266
- color: #888;
333
+ color: var(--mocha-stats-color);
267
334
  z-index: 1;
268
335
  }
269
336
 
@@ -284,7 +351,7 @@ body {
284
351
  }
285
352
 
286
353
  #mocha-stats em {
287
- color: black;
354
+ color: var(--mocha-stats-em-color);
288
355
  }
289
356
 
290
357
  #mocha-stats a {
@@ -293,7 +360,7 @@ body {
293
360
  }
294
361
 
295
362
  #mocha-stats a:hover {
296
- border-bottom: 1px solid #eee;
363
+ border-bottom: 1px solid var(--mocha-stats-hover-color);
297
364
  }
298
365
 
299
366
  #mocha-stats li {
@@ -308,11 +375,11 @@ body {
308
375
  height: 40px;
309
376
  }
310
377
 
311
- #mocha code .comment { color: #ddd; }
312
- #mocha code .init { color: #2f6fad; }
313
- #mocha code .string { color: #5890ad; }
314
- #mocha code .keyword { color: #8a6343; }
315
- #mocha code .number { color: #2f6fad; }
378
+ #mocha code .comment { color: var(--mocha-code-comment); }
379
+ #mocha code .init { color: var(--mocha-code-init); }
380
+ #mocha code .string { color: var(--mocha-code-string); }
381
+ #mocha code .keyword { color: var(--mocha-code-keyword); }
382
+ #mocha code .number { color: var(--mocha-code-number); }
316
383
 
317
384
  @media screen and (max-device-width: 480px) {
318
385
  #mocha {