mocha-compat 3.6.4 → 10.8.2
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/LICENSE +1 -1
- package/README.md +61 -110
- package/bin/_mocha +10 -0
- package/bin/mocha.js +142 -0
- package/browser-entry.js +61 -22
- package/lib/browser/highlight-tags.js +39 -0
- package/lib/browser/parse-query.js +24 -0
- package/lib/{template.html → browser/template.html} +7 -5
- package/lib/cli/cli.js +89 -0
- package/lib/cli/collect-files.js +137 -0
- package/lib/cli/commands.js +14 -0
- package/lib/cli/config.js +100 -0
- package/lib/cli/index.js +3 -0
- package/lib/cli/init.js +36 -0
- package/lib/cli/lookup-files.js +150 -0
- package/lib/cli/node-flags.js +85 -0
- package/lib/cli/one-and-dones.js +69 -0
- package/lib/cli/options.js +284 -0
- package/lib/cli/run-helpers.js +304 -0
- package/lib/cli/run-option-metadata.js +116 -0
- package/lib/cli/run.js +380 -0
- package/lib/cli/watch-run.js +377 -0
- package/lib/context.js +16 -42
- package/lib/errors.js +563 -0
- package/lib/hook.js +50 -9
- package/lib/interfaces/bdd.js +28 -29
- package/lib/interfaces/common.js +56 -21
- package/lib/interfaces/exports.js +4 -7
- package/lib/interfaces/qunit.js +10 -11
- package/lib/interfaces/tdd.js +15 -15
- package/lib/mocha.js +1073 -292
- package/lib/mocharc.json +10 -0
- package/lib/nodejs/buffered-worker-pool.js +188 -0
- package/lib/nodejs/esm-utils.js +106 -0
- package/lib/nodejs/file-unloader.js +15 -0
- package/lib/nodejs/parallel-buffered-runner.js +433 -0
- package/lib/nodejs/reporters/parallel-buffered.js +165 -0
- package/lib/nodejs/serializer.js +414 -0
- package/lib/nodejs/worker.js +151 -0
- package/lib/pending.js +3 -3
- package/lib/plugin-loader.js +286 -0
- package/lib/reporters/base.js +305 -205
- package/lib/reporters/doc.js +52 -21
- package/lib/reporters/dot.js +31 -18
- package/lib/reporters/html.js +153 -81
- package/lib/reporters/json-stream.js +53 -24
- package/lib/reporters/json.js +88 -18
- package/lib/reporters/landing.js +38 -16
- package/lib/reporters/list.js +34 -19
- package/lib/reporters/markdown.js +28 -15
- package/lib/reporters/min.js +22 -8
- package/lib/reporters/nyan.js +62 -58
- package/lib/reporters/progress.js +32 -19
- package/lib/reporters/spec.js +41 -23
- package/lib/reporters/tap.js +255 -32
- package/lib/reporters/xunit.js +89 -39
- package/lib/runnable.js +233 -148
- package/lib/runner.js +679 -380
- package/lib/stats-collector.js +83 -0
- package/lib/suite.js +376 -112
- package/lib/test.js +82 -21
- package/lib/utils.js +364 -477
- package/mocha.css +183 -54
- package/mocha.js +19840 -15846
- package/mocha.js.map +1 -0
- package/package.json +163 -336
- package/{lib/to-iso-string → vendor/serialize-javascript}/LICENSE +8 -6
- package/vendor/serialize-javascript/README.md +10 -0
- package/vendor/serialize-javascript/index.js +349 -0
- package/bin/_mocha-compat +0 -572
- package/bin/mocha-compat +0 -87
- package/bin/options.js +0 -41
- package/bower.json +0 -38
- package/images/error.png +0 -0
- package/images/ok.png +0 -0
- package/lib/browser/.eslintrc.yaml +0 -4
- package/lib/browser/debug.js +0 -7
- package/lib/browser/events.js +0 -195
- package/lib/browser/progress.js +0 -119
- package/lib/browser/tty.js +0 -13
- package/lib/ms.js +0 -130
- package/lib/to-iso-string/index.js +0 -37
- package/vendor/glob/LICENSE +0 -15
- package/vendor/glob/README.md +0 -399
- package/vendor/glob/common.js +0 -244
- package/vendor/glob/glob.js +0 -788
- package/vendor/glob/package.json +0 -55
- package/vendor/glob/sync.js +0 -486
- package/vendor/inflight/LICENSE +0 -15
- package/vendor/inflight/README.md +0 -37
- package/vendor/inflight/inflight.js +0 -54
- package/vendor/inflight/package.json +0 -29
package/lib/reporters/tap.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @module TAP
|
|
4
|
+
*/
|
|
3
5
|
/**
|
|
4
6
|
* Module dependencies.
|
|
5
7
|
*/
|
|
6
8
|
|
|
9
|
+
var util = require('util');
|
|
7
10
|
var Base = require('./base');
|
|
11
|
+
var constants = require('../runner').constants;
|
|
12
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
13
|
+
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
14
|
+
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
|
|
15
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
16
|
+
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
|
17
|
+
var EVENT_TEST_END = constants.EVENT_TEST_END;
|
|
18
|
+
var inherits = require('../utils').inherits;
|
|
19
|
+
var sprintf = util.format;
|
|
8
20
|
|
|
9
21
|
/**
|
|
10
22
|
* Expose `TAP`.
|
|
@@ -13,58 +25,269 @@ var Base = require('./base');
|
|
|
13
25
|
exports = module.exports = TAP;
|
|
14
26
|
|
|
15
27
|
/**
|
|
16
|
-
*
|
|
28
|
+
* Constructs a new `TAP` reporter instance.
|
|
17
29
|
*
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
30
|
+
* @public
|
|
31
|
+
* @class
|
|
32
|
+
* @memberof Mocha.reporters
|
|
33
|
+
* @extends Mocha.reporters.Base
|
|
34
|
+
* @param {Runner} runner - Instance triggers reporter actions.
|
|
35
|
+
* @param {Object} [options] - runner options
|
|
20
36
|
*/
|
|
21
|
-
function TAP
|
|
22
|
-
Base.call(this, runner);
|
|
37
|
+
function TAP(runner, options) {
|
|
38
|
+
Base.call(this, runner, options);
|
|
23
39
|
|
|
40
|
+
var self = this;
|
|
24
41
|
var n = 1;
|
|
25
|
-
var passes = 0;
|
|
26
|
-
var failures = 0;
|
|
27
42
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
43
|
+
var tapVersion = '12';
|
|
44
|
+
if (options && options.reporterOptions) {
|
|
45
|
+
if (options.reporterOptions.tapVersion) {
|
|
46
|
+
tapVersion = options.reporterOptions.tapVersion.toString();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this._producer = createProducer(tapVersion);
|
|
51
|
+
|
|
52
|
+
runner.once(EVENT_RUN_BEGIN, function () {
|
|
53
|
+
self._producer.writeVersion();
|
|
31
54
|
});
|
|
32
55
|
|
|
33
|
-
runner.on(
|
|
56
|
+
runner.on(EVENT_TEST_END, function () {
|
|
34
57
|
++n;
|
|
35
58
|
});
|
|
36
59
|
|
|
37
|
-
runner.on(
|
|
38
|
-
|
|
60
|
+
runner.on(EVENT_TEST_PENDING, function (test) {
|
|
61
|
+
self._producer.writePending(n, test);
|
|
39
62
|
});
|
|
40
63
|
|
|
41
|
-
runner.on(
|
|
42
|
-
|
|
43
|
-
console.log('ok %d %s', n, title(test));
|
|
64
|
+
runner.on(EVENT_TEST_PASS, function (test) {
|
|
65
|
+
self._producer.writePass(n, test);
|
|
44
66
|
});
|
|
45
67
|
|
|
46
|
-
runner.on(
|
|
47
|
-
|
|
48
|
-
console.log('not ok %d %s', n, title(test));
|
|
49
|
-
if (err.stack) {
|
|
50
|
-
console.log(err.stack.replace(/^/gm, ' '));
|
|
51
|
-
}
|
|
68
|
+
runner.on(EVENT_TEST_FAIL, function (test, err) {
|
|
69
|
+
self._producer.writeFail(n, test, err);
|
|
52
70
|
});
|
|
53
71
|
|
|
54
|
-
runner.
|
|
55
|
-
|
|
56
|
-
console.log('# pass ' + passes);
|
|
57
|
-
console.log('# fail ' + failures);
|
|
72
|
+
runner.once(EVENT_RUN_END, function () {
|
|
73
|
+
self._producer.writeEpilogue(runner.stats);
|
|
58
74
|
});
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
/**
|
|
62
|
-
*
|
|
78
|
+
* Inherit from `Base.prototype`.
|
|
79
|
+
*/
|
|
80
|
+
inherits(TAP, Base);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Returns a TAP-safe title of `test`.
|
|
63
84
|
*
|
|
64
|
-
* @
|
|
65
|
-
* @param {
|
|
66
|
-
* @return {String}
|
|
85
|
+
* @private
|
|
86
|
+
* @param {Test} test - Test instance.
|
|
87
|
+
* @return {String} title with any hash character removed
|
|
67
88
|
*/
|
|
68
|
-
function title
|
|
89
|
+
function title(test) {
|
|
69
90
|
return test.fullTitle().replace(/#/g, '');
|
|
70
91
|
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Writes newline-terminated formatted string to reporter output stream.
|
|
95
|
+
*
|
|
96
|
+
* @private
|
|
97
|
+
* @param {string} format - `printf`-like format string
|
|
98
|
+
* @param {...*} [varArgs] - Format string arguments
|
|
99
|
+
*/
|
|
100
|
+
function println(format, varArgs) {
|
|
101
|
+
var vargs = Array.from(arguments);
|
|
102
|
+
vargs[0] += '\n';
|
|
103
|
+
process.stdout.write(sprintf.apply(null, vargs));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Returns a `tapVersion`-appropriate TAP producer instance, if possible.
|
|
108
|
+
*
|
|
109
|
+
* @private
|
|
110
|
+
* @param {string} tapVersion - Version of TAP specification to produce.
|
|
111
|
+
* @returns {TAPProducer} specification-appropriate instance
|
|
112
|
+
* @throws {Error} if specification version has no associated producer.
|
|
113
|
+
*/
|
|
114
|
+
function createProducer(tapVersion) {
|
|
115
|
+
var producers = {
|
|
116
|
+
12: new TAP12Producer(),
|
|
117
|
+
13: new TAP13Producer()
|
|
118
|
+
};
|
|
119
|
+
var producer = producers[tapVersion];
|
|
120
|
+
|
|
121
|
+
if (!producer) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
'invalid or unsupported TAP version: ' + JSON.stringify(tapVersion)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return producer;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @summary
|
|
132
|
+
* Constructs a new TAPProducer.
|
|
133
|
+
*
|
|
134
|
+
* @description
|
|
135
|
+
* <em>Only</em> to be used as an abstract base class.
|
|
136
|
+
*
|
|
137
|
+
* @private
|
|
138
|
+
* @constructor
|
|
139
|
+
*/
|
|
140
|
+
function TAPProducer() {}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Writes the TAP version to reporter output stream.
|
|
144
|
+
*
|
|
145
|
+
* @abstract
|
|
146
|
+
*/
|
|
147
|
+
TAPProducer.prototype.writeVersion = function () {};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Writes the plan to reporter output stream.
|
|
151
|
+
*
|
|
152
|
+
* @abstract
|
|
153
|
+
* @param {number} ntests - Number of tests that are planned to run.
|
|
154
|
+
*/
|
|
155
|
+
TAPProducer.prototype.writePlan = function (ntests) {
|
|
156
|
+
println('%d..%d', 1, ntests);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Writes that test passed to reporter output stream.
|
|
161
|
+
*
|
|
162
|
+
* @abstract
|
|
163
|
+
* @param {number} n - Index of test that passed.
|
|
164
|
+
* @param {Test} test - Instance containing test information.
|
|
165
|
+
*/
|
|
166
|
+
TAPProducer.prototype.writePass = function (n, test) {
|
|
167
|
+
println('ok %d %s', n, title(test));
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Writes that test was skipped to reporter output stream.
|
|
172
|
+
*
|
|
173
|
+
* @abstract
|
|
174
|
+
* @param {number} n - Index of test that was skipped.
|
|
175
|
+
* @param {Test} test - Instance containing test information.
|
|
176
|
+
*/
|
|
177
|
+
TAPProducer.prototype.writePending = function (n, test) {
|
|
178
|
+
println('ok %d %s # SKIP -', n, title(test));
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Writes that test failed to reporter output stream.
|
|
183
|
+
*
|
|
184
|
+
* @abstract
|
|
185
|
+
* @param {number} n - Index of test that failed.
|
|
186
|
+
* @param {Test} test - Instance containing test information.
|
|
187
|
+
* @param {Error} err - Reason the test failed.
|
|
188
|
+
*/
|
|
189
|
+
TAPProducer.prototype.writeFail = function (n, test, err) {
|
|
190
|
+
println('not ok %d %s', n, title(test));
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Writes the summary epilogue to reporter output stream.
|
|
195
|
+
*
|
|
196
|
+
* @abstract
|
|
197
|
+
* @param {Object} stats - Object containing run statistics.
|
|
198
|
+
*/
|
|
199
|
+
TAPProducer.prototype.writeEpilogue = function (stats) {
|
|
200
|
+
// :TBD: Why is this not counting pending tests?
|
|
201
|
+
println('# tests ' + (stats.passes + stats.failures));
|
|
202
|
+
println('# pass ' + stats.passes);
|
|
203
|
+
// :TBD: Why are we not showing pending results?
|
|
204
|
+
println('# fail ' + stats.failures);
|
|
205
|
+
this.writePlan(stats.passes + stats.failures + stats.pending);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @summary
|
|
210
|
+
* Constructs a new TAP12Producer.
|
|
211
|
+
*
|
|
212
|
+
* @description
|
|
213
|
+
* Produces output conforming to the TAP12 specification.
|
|
214
|
+
*
|
|
215
|
+
* @private
|
|
216
|
+
* @constructor
|
|
217
|
+
* @extends TAPProducer
|
|
218
|
+
* @see {@link https://testanything.org/tap-specification.html|Specification}
|
|
219
|
+
*/
|
|
220
|
+
function TAP12Producer() {
|
|
221
|
+
/**
|
|
222
|
+
* Writes that test failed to reporter output stream, with error formatting.
|
|
223
|
+
* @override
|
|
224
|
+
*/
|
|
225
|
+
this.writeFail = function (n, test, err) {
|
|
226
|
+
TAPProducer.prototype.writeFail.call(this, n, test, err);
|
|
227
|
+
if (err.message) {
|
|
228
|
+
println(err.message.replace(/^/gm, ' '));
|
|
229
|
+
}
|
|
230
|
+
if (err.stack) {
|
|
231
|
+
println(err.stack.replace(/^/gm, ' '));
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Inherit from `TAPProducer.prototype`.
|
|
238
|
+
*/
|
|
239
|
+
inherits(TAP12Producer, TAPProducer);
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* @summary
|
|
243
|
+
* Constructs a new TAP13Producer.
|
|
244
|
+
*
|
|
245
|
+
* @description
|
|
246
|
+
* Produces output conforming to the TAP13 specification.
|
|
247
|
+
*
|
|
248
|
+
* @private
|
|
249
|
+
* @constructor
|
|
250
|
+
* @extends TAPProducer
|
|
251
|
+
* @see {@link https://testanything.org/tap-version-13-specification.html|Specification}
|
|
252
|
+
*/
|
|
253
|
+
function TAP13Producer() {
|
|
254
|
+
/**
|
|
255
|
+
* Writes the TAP version to reporter output stream.
|
|
256
|
+
* @override
|
|
257
|
+
*/
|
|
258
|
+
this.writeVersion = function () {
|
|
259
|
+
println('TAP version 13');
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Writes that test failed to reporter output stream, with error formatting.
|
|
264
|
+
* @override
|
|
265
|
+
*/
|
|
266
|
+
this.writeFail = function (n, test, err) {
|
|
267
|
+
TAPProducer.prototype.writeFail.call(this, n, test, err);
|
|
268
|
+
var emitYamlBlock = err.message != null || err.stack != null;
|
|
269
|
+
if (emitYamlBlock) {
|
|
270
|
+
println(indent(1) + '---');
|
|
271
|
+
if (err.message) {
|
|
272
|
+
println(indent(2) + 'message: |-');
|
|
273
|
+
println(err.message.replace(/^/gm, indent(3)));
|
|
274
|
+
}
|
|
275
|
+
if (err.stack) {
|
|
276
|
+
println(indent(2) + 'stack: |-');
|
|
277
|
+
println(err.stack.replace(/^/gm, indent(3)));
|
|
278
|
+
}
|
|
279
|
+
println(indent(1) + '...');
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
function indent(level) {
|
|
284
|
+
return Array(level + 1).join(' ');
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Inherit from `TAPProducer.prototype`.
|
|
290
|
+
*/
|
|
291
|
+
inherits(TAP13Producer, TAPProducer);
|
|
292
|
+
|
|
293
|
+
TAP.description = 'TAP-compatible output';
|
package/lib/reporters/xunit.js
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @module XUnit
|
|
4
|
+
*/
|
|
3
5
|
/**
|
|
4
6
|
* Module dependencies.
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
9
|
var Base = require('./base');
|
|
8
10
|
var utils = require('../utils');
|
|
9
|
-
var inherits = utils.inherits;
|
|
10
11
|
var fs = require('fs');
|
|
11
|
-
var escape = utils.escape;
|
|
12
|
-
var mkdirp = require('mkdirp');
|
|
13
12
|
var path = require('path');
|
|
13
|
+
var errors = require('../errors');
|
|
14
|
+
var createUnsupportedError = errors.createUnsupportedError;
|
|
15
|
+
var constants = require('../runner').constants;
|
|
16
|
+
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
|
|
17
|
+
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
|
|
18
|
+
var EVENT_RUN_END = constants.EVENT_RUN_END;
|
|
19
|
+
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
|
|
20
|
+
var STATE_FAILED = require('../runnable').constants.STATE_FAILED;
|
|
21
|
+
var inherits = utils.inherits;
|
|
22
|
+
var escape = utils.escape;
|
|
14
23
|
|
|
15
24
|
/**
|
|
16
25
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
17
26
|
*/
|
|
18
|
-
|
|
19
|
-
/* eslint-disable no-unused-vars, no-native-reassign */
|
|
20
27
|
var Date = global.Date;
|
|
21
|
-
var setTimeout = global.setTimeout;
|
|
22
|
-
var setInterval = global.setInterval;
|
|
23
|
-
var clearTimeout = global.clearTimeout;
|
|
24
|
-
var clearInterval = global.clearInterval;
|
|
25
|
-
/* eslint-enable no-unused-vars, no-native-reassign */
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Expose `XUnit`.
|
|
@@ -31,48 +33,75 @@ var clearInterval = global.clearInterval;
|
|
|
31
33
|
exports = module.exports = XUnit;
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
|
-
*
|
|
36
|
+
* Constructs a new `XUnit` reporter instance.
|
|
35
37
|
*
|
|
36
|
-
* @
|
|
37
|
-
* @
|
|
38
|
+
* @public
|
|
39
|
+
* @class
|
|
40
|
+
* @memberof Mocha.reporters
|
|
41
|
+
* @extends Mocha.reporters.Base
|
|
42
|
+
* @param {Runner} runner - Instance triggers reporter actions.
|
|
43
|
+
* @param {Object} [options] - runner options
|
|
38
44
|
*/
|
|
39
|
-
function XUnit
|
|
40
|
-
Base.call(this, runner);
|
|
45
|
+
function XUnit(runner, options) {
|
|
46
|
+
Base.call(this, runner, options);
|
|
41
47
|
|
|
42
48
|
var stats = this.stats;
|
|
43
49
|
var tests = [];
|
|
44
50
|
var self = this;
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
// the name of the test suite, as it will appear in the resulting XML file
|
|
53
|
+
var suiteName;
|
|
54
|
+
|
|
55
|
+
// the default name of the test suite if none is provided
|
|
56
|
+
var DEFAULT_SUITE_NAME = 'Mocha Tests';
|
|
57
|
+
|
|
58
|
+
if (options && options.reporterOptions) {
|
|
59
|
+
if (options.reporterOptions.output) {
|
|
60
|
+
if (!fs.createWriteStream) {
|
|
61
|
+
throw createUnsupportedError('file output not supported in browser');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fs.mkdirSync(path.dirname(options.reporterOptions.output), {
|
|
65
|
+
recursive: true
|
|
66
|
+
});
|
|
67
|
+
self.fileStream = fs.createWriteStream(options.reporterOptions.output);
|
|
49
68
|
}
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
|
|
70
|
+
// get the suite name from the reporter options (if provided)
|
|
71
|
+
suiteName = options.reporterOptions.suiteName;
|
|
52
72
|
}
|
|
53
73
|
|
|
54
|
-
|
|
74
|
+
// fall back to the default suite name
|
|
75
|
+
suiteName = suiteName || DEFAULT_SUITE_NAME;
|
|
76
|
+
|
|
77
|
+
runner.on(EVENT_TEST_PENDING, function (test) {
|
|
55
78
|
tests.push(test);
|
|
56
79
|
});
|
|
57
80
|
|
|
58
|
-
runner.on(
|
|
81
|
+
runner.on(EVENT_TEST_PASS, function (test) {
|
|
59
82
|
tests.push(test);
|
|
60
83
|
});
|
|
61
84
|
|
|
62
|
-
runner.on(
|
|
85
|
+
runner.on(EVENT_TEST_FAIL, function (test) {
|
|
63
86
|
tests.push(test);
|
|
64
87
|
});
|
|
65
88
|
|
|
66
|
-
runner.
|
|
67
|
-
self.write(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
runner.once(EVENT_RUN_END, function () {
|
|
90
|
+
self.write(
|
|
91
|
+
tag(
|
|
92
|
+
'testsuite',
|
|
93
|
+
{
|
|
94
|
+
name: suiteName,
|
|
95
|
+
tests: stats.tests,
|
|
96
|
+
failures: 0,
|
|
97
|
+
errors: stats.failures,
|
|
98
|
+
skipped: stats.tests - stats.failures - stats.passes,
|
|
99
|
+
timestamp: new Date().toUTCString(),
|
|
100
|
+
time: stats.duration / 1000 || 0
|
|
101
|
+
},
|
|
102
|
+
false
|
|
103
|
+
)
|
|
104
|
+
);
|
|
76
105
|
|
|
77
106
|
tests.forEach(function (t) {
|
|
78
107
|
self.test(t);
|
|
@@ -114,7 +143,7 @@ XUnit.prototype.write = function (line) {
|
|
|
114
143
|
} else if (typeof process === 'object' && process.stdout) {
|
|
115
144
|
process.stdout.write(line + '\n');
|
|
116
145
|
} else {
|
|
117
|
-
|
|
146
|
+
Base.consoleLog(line);
|
|
118
147
|
}
|
|
119
148
|
};
|
|
120
149
|
|
|
@@ -124,15 +153,34 @@ XUnit.prototype.write = function (line) {
|
|
|
124
153
|
* @param {Test} test
|
|
125
154
|
*/
|
|
126
155
|
XUnit.prototype.test = function (test) {
|
|
156
|
+
Base.useColors = false;
|
|
157
|
+
|
|
127
158
|
var attrs = {
|
|
128
159
|
classname: test.parent.fullTitle(),
|
|
129
160
|
name: test.title,
|
|
130
|
-
|
|
161
|
+
file: test.file,
|
|
162
|
+
time: test.duration / 1000 || 0
|
|
131
163
|
};
|
|
132
164
|
|
|
133
|
-
if (test.state ===
|
|
165
|
+
if (test.state === STATE_FAILED) {
|
|
134
166
|
var err = test.err;
|
|
135
|
-
|
|
167
|
+
var diff =
|
|
168
|
+
!Base.hideDiff && Base.showDiff(err)
|
|
169
|
+
? '\n' + Base.generateDiff(err.actual, err.expected)
|
|
170
|
+
: '';
|
|
171
|
+
this.write(
|
|
172
|
+
tag(
|
|
173
|
+
'testcase',
|
|
174
|
+
attrs,
|
|
175
|
+
false,
|
|
176
|
+
tag(
|
|
177
|
+
'failure',
|
|
178
|
+
{},
|
|
179
|
+
false,
|
|
180
|
+
escape(err.message) + escape(diff) + '\n' + escape(err.stack)
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
);
|
|
136
184
|
} else if (test.isPending()) {
|
|
137
185
|
this.write(tag('testcase', attrs, false, tag('skipped', {}, true)));
|
|
138
186
|
} else {
|
|
@@ -149,7 +197,7 @@ XUnit.prototype.test = function (test) {
|
|
|
149
197
|
* @param content
|
|
150
198
|
* @return {string}
|
|
151
199
|
*/
|
|
152
|
-
function tag
|
|
200
|
+
function tag(name, attrs, close, content) {
|
|
153
201
|
var end = close ? '/>' : '>';
|
|
154
202
|
var pairs = [];
|
|
155
203
|
var tag;
|
|
@@ -166,3 +214,5 @@ function tag (name, attrs, close, content) {
|
|
|
166
214
|
}
|
|
167
215
|
return tag;
|
|
168
216
|
}
|
|
217
|
+
|
|
218
|
+
XUnit.description = 'XUnit-compatible XML output';
|