Debian Codegraph @

lib/reporters/xunit.js

raw symbols SCIP
1 "use strict";
2
3 /**
4 * @typedef {import('../runner.js')} Runner
5 * @typedef {import('../test.js')} Test
6 */
7
8 /**
9 * @module XUnit
10 */
11 /**
12 * Module dependencies.
13 */
14
15 var Basescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/Base. = require("./base"scip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/);
16 var utilsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/utils. = require("../utils"scip-typescript npm mocha 11.7.7 lib/`utils.js`/);
17 var fsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/fs. = require("node:fs");
18 var pathscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/path. = require("node:path");
19 var errorsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/errors. = require("../errors"scip-typescript npm mocha 11.7.7 lib/`errors.js`/);
20 var createUnsupportedErrorscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/createUnsupportedError. = errorsscip-typescript npm mocha 11.7.7 lib/`errors.js`/.createUnsupportedErrorscip-typescript npm mocha 11.7.7 lib/`errors.js`/createUnsupportedError0:;
21 var constantsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/constants. = require("../runner"scip-typescript npm mocha 11.7.7 lib/`runner.js`/).constants;
22 var EVENT_TEST_PASSscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/EVENT_TEST_PASS. = constants.EVENT_TEST_PASS;
23 var EVENT_TEST_FAILscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/EVENT_TEST_FAIL. = constants.EVENT_TEST_FAIL;
24 var EVENT_RUN_ENDscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/EVENT_RUN_END. = constants.EVENT_RUN_END;
25 var EVENT_TEST_PENDINGscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/EVENT_TEST_PENDING. = constants.EVENT_TEST_PENDING;
26 var STATE_FAILEDscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/STATE_FAILED. = require("../runnable"scip-typescript npm mocha 11.7.7 lib/`runnable.js`/).constants.STATE_FAILED;
27 var inheritsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/inherits. = utilsscip-typescript npm mocha 11.7.7 lib/`utils.js`/.inherits;
28 var escapescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/escape. = utilsscip-typescript npm mocha 11.7.7 lib/`utils.js`/.escape;
29
30 /**
31 * Save timer references to avoid Sinon interfering (see GH-237).
32 */
33 var Datescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/Date. = global.Date;
34
35 /**
36 * Expose `XUnit`.
37 */
38
39 exportsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/ = module.exports = XUnitscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().;
40
41 /**
42 * Constructs a new `XUnit` reporter instance.
43 *
44 * @public
45 * @class
46 * @memberof Mocha.reporters
47 * @extends Mocha.reporters.Base
48 * @param {Runner} runner - Instance triggers reporter actions.
49 * @param {Object} [options] - runner options
50 */
51 function XUnitscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(runnerscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(runner), optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(options)) {
52 Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..callscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#call().(this, runnerscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(runner), optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(options));
53
54 var stats = this.stats;
55 var tests = [];
56 var self = this;
57
58 // the name of the test suite, as it will appear in the resulting XML file
59 var suiteName;
60
61 // the default name of the test suite if none is provided
62 var DEFAULT_SUITE_NAME = "Mocha Tests";
63
64 if (optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(options) && optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(options).reporterOptions) {
65 if (optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(options).reporterOptions.output) {
66 if (!fsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/fs..createWriteStream) {
67 throw createUnsupportedErrorscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/createUnsupportedError.("file output not supported in browser");
68 }
69
70 fsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/fs..mkdirSync(pathscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/path..dirname(optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(options).reporterOptions.output), {
71 recursivescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/recursive0:: true,
72 });
73 self.fileStream = fsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/fs..createWriteStream(optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(options).reporterOptions.output);
74 }
75
76 // get the suite name from the reporter options (if provided)
77 suiteName = optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(options).reporterOptions.suiteName;
78 }
79
80 // fall back to the default suite name
81 suiteName = suiteName || DEFAULT_SUITE_NAME;
82
83 runnerscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(runner).on(EVENT_TEST_PENDINGscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/EVENT_TEST_PENDING., function (test) {
84 tests.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(test);
85 });
86
87 runnerscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(runner).on(EVENT_TEST_PASSscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/EVENT_TEST_PASS., function (test) {
88 tests.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(test);
89 });
90
91 runnerscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(runner).on(EVENT_TEST_FAILscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/EVENT_TEST_FAIL., function (test) {
92 tests.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(test);
93 });
94
95 runnerscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(runner).once(EVENT_RUN_ENDscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/EVENT_RUN_END., function () {
96 self.write(
97 tagscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(
98 "testsuite",
99 {
100 namescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/name0:: suiteName,
101 testsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tests0:: stats.tests,
102 failuresscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/failures0:: 0,
103 errorsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/errors0:: stats.failures,
104 skippedscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/skipped0:: stats.tests - stats.failures - stats.passes,
105 timestampscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/timestamp0:: new Datescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/Date.().toUTCString(),
106 timescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/time0:: stats.duration / 1000 || 0,
107 },
108 false,
109 ),
110 );
111
112 tests.forEachscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#forEach().(function (t) {
113 self.test(t, optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit().(options));
114 });
115
116 self.write("</testsuite>");
117 });
118 }
119
120 /**
121 * Inherit from `Base.prototype`.
122 */
123 inheritsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/inherits.(XUnitscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit()., Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base().);
124
125 /**
126 * Override done to close the stream (if it's a file).
127 *
128 * @param failures
129 * @param {Function} fn
130 */
131 XUnitscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..done = function (failures, fn) {
132 if (this.fileStream) {
133 this.fileStream.end(function () {
134 fn(failures);
135 });
136 } else {
137 fn(failures);
138 }
139 };
140
141 /**
142 * Write out the given line.
143 *
144 * @param {string} line
145 */
146 XUnitscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..write = function (line) {
147 if (this.fileStream) {
148 this.fileStream.write(line + "\n");
149 } else if (typeof process === "object" && process.stdout) {
150 process.stdout.write(line + "\n");
151 } else {
152 Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..consoleLog(line);
153 }
154 };
155
156 /**
157 * Output tag for the given `test.`
158 *
159 * @param {Test} test
160 */
161 XUnitscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit()..prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#prototype..test = function (test, options) {
162 Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..useColors = false;
163
164 var attrs = {
165 classnamescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/classname0:: test.parent.fullTitle(),
166 namescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/name1:: test.title,
167 filescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/file0:: testFilePathscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/testFilePath().(test.file, options),
168 timescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/time1:: test.duration / 1000 || 0,
169 };
170
171 if (test.state === STATE_FAILEDscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/STATE_FAILED.) {
172 var err = test.err;
173 var diff =
174 !Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..hideDiff && Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..showDiff(err)
175 ? "\n" + Basescip-typescript npm mocha 11.7.7 lib/reporters/`base.js`/Base()..generateDiff(err.actual, err.expected)
176 : "";
177 this.write(
178 tagscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(
179 "testcase",
180 attrs,
181 false,
182 tagscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(
183 "failure",
184 {},
185 false,
186 escapescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/escape.(err.message) + escapescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/escape.(diff) + "\n" + escapescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/escape.(err.stack),
187 ),
188 ),
189 );
190 } else if (test.isPending()) {
191 this.write(tagscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().("testcase", attrs, false, tagscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().("skipped", {}, true)));
192 } else {
193 this.write(tagscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().("testcase", attrs, true));
194 }
195 };
196
197 /**
198 * HTML tag helper.
199 *
200 * @param name
201 * @param attrs
202 * @param close
203 * @param content
204 * @return {string}
205 */
206 function tagscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(namescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(name), attrsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(attrs), closescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(close), contentscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(content)) {
207 var end = closescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(close) ? "/>" : ">";
208 var pairs = [];
209 var tag;
210
211 for (var key in attrsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(attrs)) {
212 if (Objectscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#.prototypescip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/ObjectConstructor#prototype..hasOwnPropertyscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Object#hasOwnProperty()..callscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Function#call().(attrsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(attrs), key)) {
213 pairs.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(key + '="' + escapescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/escape.(attrsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(attrs)[key]) + '"');
214 }
215 }
216
217 tag = "<" + namescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(name) + (pairs.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. ? " " + pairs.joinscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#join().(" ") : "") + end;
218 if (contentscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(content)) {
219 tag += contentscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(content) + "</" + namescip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/tag().(name) + end;
220 }
221 return tag;
222 }
223
224 function testFilePathscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/testFilePath().(filepathscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/testFilePath().(filepath), optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/testFilePath().(options)) {
225 if (
226 optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/testFilePath().(options) &&
227 optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/testFilePath().(options).reporterOptions &&
228 optionsscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/testFilePath().(options).reporterOptions.showRelativePaths
229 ) {
230 return pathscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/path..relative(process.cwd(), filepathscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/testFilePath().(filepath));
231 }
232
233 return filepathscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/testFilePath().(filepath);
234 }
235
236 XUnitscip-typescript npm mocha 11.7.7 lib/reporters/`xunit.js`/XUnit()..description = "XUnit-compatible XML output";