mocha 11.1.0 → 11.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.
package/bin/mocha.js CHANGED
@@ -78,7 +78,7 @@ if (mochaArgs._) {
78
78
  }
79
79
 
80
80
  if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) {
81
- const {spawn} = require('child_process');
81
+ const {spawn} = require('node:child_process');
82
82
  const mochaPath = require.resolve('../lib/cli/cli.js');
83
83
 
84
84
  const nodeArgv =
@@ -126,7 +126,7 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) {
126
126
  // be needed.
127
127
  if (!args.parallel || args.jobs < 2) {
128
128
  // win32 does not support SIGTERM, so use next best thing.
129
- if (require('os').platform() === 'win32') {
129
+ if (require('node:os').platform() === 'win32') {
130
130
  proc.kill('SIGKILL');
131
131
  } else {
132
132
  // using SIGKILL won't cleanly close the output streams, which can result
package/lib/cli/cli.js CHANGED
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env node
2
-
3
1
  'use strict';
4
2
 
5
3
  /**
@@ -13,7 +11,7 @@
13
11
  const debug = require('debug')('mocha:cli:cli');
14
12
  const symbols = require('log-symbols');
15
13
  const yargs = require('yargs');
16
- const path = require('path');
14
+ const path = require('node:path');
17
15
  const {
18
16
  loadRc,
19
17
  loadPkgRc,
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const fs = require('fs');
4
- const path = require('path');
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
5
  const ansi = require('ansi-colors');
6
6
  const debug = require('debug')('mocha:cli:run:helpers');
7
7
  const minimatch = require('minimatch');
package/lib/cli/config.js CHANGED
@@ -7,8 +7,8 @@
7
7
  * @module
8
8
  */
9
9
 
10
- const fs = require('fs');
11
- const path = require('path');
10
+ const fs = require('node:fs');
11
+ const path = require('node:path');
12
12
  const debug = require('debug')('mocha:cli:config');
13
13
  const findUp = require('find-up');
14
14
  const {createUnparsableFileError} = require('../errors');
package/lib/cli/init.js CHANGED
@@ -7,8 +7,8 @@
7
7
  * @module
8
8
  */
9
9
 
10
- const fs = require('fs');
11
- const path = require('path');
10
+ const fs = require('node:fs');
11
+ const path = require('node:path');
12
12
 
13
13
  exports.command = 'init <path>';
14
14
 
@@ -5,8 +5,8 @@
5
5
  * @private
6
6
  */
7
7
 
8
- var fs = require('fs');
9
- var path = require('path');
8
+ var fs = require('node:fs');
9
+ var path = require('node:path');
10
10
  var glob = require('glob');
11
11
  var errors = require('../errors');
12
12
  var createNoFilesMatchPatternError = errors.createNoFilesMatchPatternError;
@@ -7,7 +7,7 @@
7
7
  * @private
8
8
  */
9
9
 
10
- const fs = require('fs');
10
+ const fs = require('node:fs');
11
11
  const ansi = require('ansi-colors');
12
12
  const yargsParser = require('yargs-parser');
13
13
  const {
@@ -7,13 +7,13 @@
7
7
  * @private
8
8
  */
9
9
 
10
- const fs = require('fs');
11
- const path = require('path');
10
+ const fs = require('node:fs');
11
+ const path = require('node:path');
12
12
  const ansi = require('ansi-colors');
13
13
  const debug = require('debug')('mocha:cli:run:helpers');
14
14
  const {watchRun, watchParallelRun} = require('./watch-run');
15
15
  const collectFiles = require('./collect-files');
16
- const {format} = require('util');
16
+ const {format} = require('node:util');
17
17
  const {createInvalidLegacyPluginError} = require('../errors');
18
18
  const {requireOrImport} = require('../nodejs/esm-utils');
19
19
  const PluginLoader = require('../plugin-loader');
@@ -2,7 +2,7 @@
2
2
 
3
3
  const logSymbols = require('log-symbols');
4
4
  const debug = require('debug')('mocha:cli:watch');
5
- const path = require('path');
5
+ const path = require('node:path');
6
6
  const chokidar = require('chokidar');
7
7
  const Context = require('../context');
8
8
  const collectFiles = require('./collect-files');
package/lib/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {format} = require('util');
3
+ const {format} = require('node:util');
4
4
 
5
5
  /**
6
6
  * Contains error codes, factory functions to create throwable error objects,
package/lib/mocha.js CHANGED
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  var escapeRe = require('escape-string-regexp');
10
- var path = require('path');
10
+ var path = require('node:path');
11
11
  var builtinReporters = require('./reporters');
12
12
  var utils = require('./utils');
13
13
  var mocharc = require('./mocharc.json');
@@ -1,5 +1,5 @@
1
- const path = require('path');
2
- const url = require('url');
1
+ const path = require('node:path');
2
+ const url = require('node:url');
3
3
 
4
4
  const forward = x => x;
5
5
 
@@ -7,8 +7,8 @@
7
7
  */
8
8
 
9
9
  var Base = require('./base');
10
- var fs = require('fs');
11
- var path = require('path');
10
+ var fs = require('node:fs');
11
+ var path = require('node:path');
12
12
  const createUnsupportedError = require('../errors').createUnsupportedError;
13
13
  const utils = require('../utils');
14
14
  var constants = require('../runner').constants;
@@ -6,7 +6,7 @@
6
6
  * Module dependencies.
7
7
  */
8
8
 
9
- var util = require('util');
9
+ var util = require('node:util');
10
10
  var Base = require('./base');
11
11
  var constants = require('../runner').constants;
12
12
  var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
@@ -8,8 +8,8 @@
8
8
 
9
9
  var Base = require('./base');
10
10
  var utils = require('../utils');
11
- var fs = require('fs');
12
- var path = require('path');
11
+ var fs = require('node:fs');
12
+ var path = require('node:path');
13
13
  var errors = require('../errors');
14
14
  var createUnsupportedError = errors.createUnsupportedError;
15
15
  var constants = require('../runner').constants;
@@ -104,7 +104,7 @@ function XUnit(runner, options) {
104
104
  );
105
105
 
106
106
  tests.forEach(function (t) {
107
- self.test(t);
107
+ self.test(t, options);
108
108
  });
109
109
 
110
110
  self.write('</testsuite>');
@@ -152,13 +152,13 @@ XUnit.prototype.write = function (line) {
152
152
  *
153
153
  * @param {Test} test
154
154
  */
155
- XUnit.prototype.test = function (test) {
155
+ XUnit.prototype.test = function (test, options) {
156
156
  Base.useColors = false;
157
157
 
158
158
  var attrs = {
159
159
  classname: test.parent.fullTitle(),
160
160
  name: test.title,
161
- file: test.file,
161
+ file: testFilePath(test.file, options),
162
162
  time: test.duration / 1000 || 0
163
163
  };
164
164
 
@@ -215,4 +215,12 @@ function tag(name, attrs, close, content) {
215
215
  return tag;
216
216
  }
217
217
 
218
+ function testFilePath(filepath, options) {
219
+ if (options && options.reporterOptions && options.reporterOptions.showRelativePaths) {
220
+ return path.relative(process.cwd(), filepath);
221
+ }
222
+
223
+ return filepath;
224
+ }
225
+
218
226
  XUnit.description = 'XUnit-compatible XML output';
package/lib/runnable.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var EventEmitter = require('events').EventEmitter;
3
+ var EventEmitter = require('node:events').EventEmitter;
4
4
  var Pending = require('./pending');
5
5
  var debug = require('debug')('mocha:runnable');
6
6
  var milliseconds = require('ms');
@@ -24,8 +24,10 @@ var MAX_TIMEOUT = Math.pow(2, 31) - 1;
24
24
 
25
25
  module.exports = Runnable;
26
26
 
27
+ // "Additional properties" doc comment added for hosted docs (mochajs.org/api)
27
28
  /**
28
29
  * Initialize a new `Runnable` with the given `title` and callback `fn`.
30
+ * Additional properties, like `getFullTitle()` and `slow()`, can be viewed in the `Runnable` source.
29
31
  *
30
32
  * @class
31
33
  * @extends external:EventEmitter
package/lib/runner.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Module dependencies.
5
5
  * @private
6
6
  */
7
- var EventEmitter = require('events').EventEmitter;
7
+ var EventEmitter = require('node:events').EventEmitter;
8
8
  var Pending = require('./pending');
9
9
  var utils = require('./utils');
10
10
  var debug = require('debug')('mocha:runner');
@@ -47,7 +47,39 @@ var globals = [
47
47
 
48
48
  var constants = utils.defineConstants(
49
49
  /**
50
- * {@link Runner}-related constants.
50
+ * {@link Runner}-related constants. Used by reporters. Each event emits the corresponding object, unless otherwise indicated.
51
+ * @example
52
+ * const Mocha = require('mocha');
53
+ * const Base = Mocha.reporters.Base;
54
+ * const {
55
+ * EVENT_HOOK_BEGIN,
56
+ * EVENT_TEST_PASS,
57
+ * EVENT_TEST_FAIL,
58
+ * EVENT_TEST_END
59
+ * } = Mocha.Runner.constants
60
+ *
61
+ * function MyReporter(runner, options) {
62
+ * Base.call(this, runner, options);
63
+ *
64
+ * runner.on(EVENT_HOOK_BEGIN, function(hook) {
65
+ * console.log('hook called: ', hook.title);
66
+ * });
67
+ *
68
+ * runner.on(EVENT_TEST_PASS, function(test) {
69
+ * console.log('pass: %s', test.fullTitle());
70
+ * });
71
+ *
72
+ * runner.on(EVENT_TEST_FAIL, function(test, err) {
73
+ * console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
74
+ * });
75
+ *
76
+ * runner.on(EVENT_TEST_END, function() {
77
+ * console.log('end: %d/%d', runner.stats.passes, runner.stats.tests);
78
+ * });
79
+ * }
80
+ *
81
+ * module.exports = MyReporter;
82
+ *
51
83
  * @public
52
84
  * @memberof Runner
53
85
  * @readonly
@@ -97,7 +129,13 @@ var constants = utils.defineConstants(
97
129
  */
98
130
  EVENT_TEST_END: 'test end',
99
131
  /**
100
- * Emitted when {@link Test} execution fails
132
+ * Emitted when {@link Test} execution fails. Includes an `err` object of type `Error`.
133
+ * @example
134
+ * runner.on(EVENT_TEST_FAIL, function(test, err) {
135
+ * console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
136
+ * });
137
+ *
138
+ *
101
139
  */
102
140
  EVENT_TEST_FAIL: 'fail',
103
141
  /**
package/lib/suite.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Module dependencies.
5
5
  * @private
6
6
  */
7
- const {EventEmitter} = require('events');
7
+ const {EventEmitter} = require('node:events');
8
8
  const Hook = require('./hook');
9
9
  var {
10
10
  assignNewMochaID,
package/lib/utils.js CHANGED
@@ -8,8 +8,8 @@
8
8
  /**
9
9
  * Module dependencies.
10
10
  */
11
- var path = require('path');
12
- var util = require('util');
11
+ var path = require('node:path');
12
+ var util = require('node:util');
13
13
  var he = require('he');
14
14
 
15
15
  const MOCHA_ID_PROP_NAME = '__mocha_id__';
package/mocha.js CHANGED
@@ -1,4 +1,4 @@
1
- // mocha@11.1.0 in javascript ES2018
1
+ // mocha@11.2.0 in javascript ES2018
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -12980,8 +12980,10 @@
12980
12980
 
12981
12981
  var runnable = Runnable$3;
12982
12982
 
12983
+ // "Additional properties" doc comment added for hosted docs (mochajs.org/api)
12983
12984
  /**
12984
12985
  * Initialize a new `Runnable` with the given `title` and callback `fn`.
12986
+ * Additional properties, like `getFullTitle()` and `slow()`, can be viewed in the `Runnable` source.
12985
12987
  *
12986
12988
  * @class
12987
12989
  * @extends external:EventEmitter
@@ -14234,7 +14236,39 @@
14234
14236
 
14235
14237
  var constants$1 = utils$1.defineConstants(
14236
14238
  /**
14237
- * {@link Runner}-related constants.
14239
+ * {@link Runner}-related constants. Used by reporters. Each event emits the corresponding object, unless otherwise indicated.
14240
+ * @example
14241
+ * const Mocha = require('mocha');
14242
+ * const Base = Mocha.reporters.Base;
14243
+ * const {
14244
+ * EVENT_HOOK_BEGIN,
14245
+ * EVENT_TEST_PASS,
14246
+ * EVENT_TEST_FAIL,
14247
+ * EVENT_TEST_END
14248
+ * } = Mocha.Runner.constants
14249
+ *
14250
+ * function MyReporter(runner, options) {
14251
+ * Base.call(this, runner, options);
14252
+ *
14253
+ * runner.on(EVENT_HOOK_BEGIN, function(hook) {
14254
+ * console.log('hook called: ', hook.title);
14255
+ * });
14256
+ *
14257
+ * runner.on(EVENT_TEST_PASS, function(test) {
14258
+ * console.log('pass: %s', test.fullTitle());
14259
+ * });
14260
+ *
14261
+ * runner.on(EVENT_TEST_FAIL, function(test, err) {
14262
+ * console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
14263
+ * });
14264
+ *
14265
+ * runner.on(EVENT_TEST_END, function() {
14266
+ * console.log('end: %d/%d', runner.stats.passes, runner.stats.tests);
14267
+ * });
14268
+ * }
14269
+ *
14270
+ * module.exports = MyReporter;
14271
+ *
14238
14272
  * @public
14239
14273
  * @memberof Runner
14240
14274
  * @readonly
@@ -14284,7 +14318,13 @@
14284
14318
  */
14285
14319
  EVENT_TEST_END: 'test end',
14286
14320
  /**
14287
- * Emitted when {@link Test} execution fails
14321
+ * Emitted when {@link Test} execution fails. Includes an `err` object of type `Error`.
14322
+ * @example
14323
+ * runner.on(EVENT_TEST_FAIL, function(test, err) {
14324
+ * console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
14325
+ * });
14326
+ *
14327
+ *
14288
14328
  */
14289
14329
  EVENT_TEST_FAIL: 'fail',
14290
14330
  /**
@@ -17745,7 +17785,7 @@
17745
17785
  );
17746
17786
 
17747
17787
  tests.forEach(function (t) {
17748
- self.test(t);
17788
+ self.test(t, options);
17749
17789
  });
17750
17790
 
17751
17791
  self.write('</testsuite>');
@@ -17793,13 +17833,13 @@
17793
17833
  *
17794
17834
  * @param {Test} test
17795
17835
  */
17796
- XUnit.prototype.test = function (test) {
17836
+ XUnit.prototype.test = function (test, options) {
17797
17837
  Base.useColors = false;
17798
17838
 
17799
17839
  var attrs = {
17800
17840
  classname: test.parent.fullTitle(),
17801
17841
  name: test.title,
17802
- file: test.file,
17842
+ file: testFilePath(test.file, options),
17803
17843
  time: test.duration / 1000 || 0
17804
17844
  };
17805
17845
 
@@ -17856,6 +17896,14 @@
17856
17896
  return tag;
17857
17897
  }
17858
17898
 
17899
+ function testFilePath(filepath, options) {
17900
+ if (options && options.reporterOptions && options.reporterOptions.showRelativePaths) {
17901
+ return path.relative(process.cwd(), filepath);
17902
+ }
17903
+
17904
+ return filepath;
17905
+ }
17906
+
17859
17907
  XUnit.description = 'XUnit-compatible XML output';
17860
17908
  }(xunit));
17861
17909
 
@@ -19208,7 +19256,7 @@
19208
19256
  };
19209
19257
 
19210
19258
  var name = "mocha";
19211
- var version = "11.1.0";
19259
+ var version = "11.2.0";
19212
19260
  var homepage = "https://mochajs.org/";
19213
19261
  var notifyLogo = "https://ibin.co/4QuRuGjXvl36.png";
19214
19262
  var require$$17 = {