ScuttleBot

Source Blame History 232 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __create = Object.create;
f7eb47b… lmata 3 var __defProp = Object.defineProperty;
f7eb47b… lmata 4 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 5 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 6 var __getProtoOf = Object.getPrototypeOf;
f7eb47b… lmata 7 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 8 var __export = (target, all) => {
f7eb47b… lmata 9 for (var name in all)
f7eb47b… lmata 10 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 11 };
f7eb47b… lmata 12 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 13 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 14 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 15 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 17 }
f7eb47b… lmata 18 return to;
f7eb47b… lmata 19 };
f7eb47b… lmata 20 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
f7eb47b… lmata 21 // If the importer is in node compatibility mode or this is not an ESM
f7eb47b… lmata 22 // file that has been converted to a CommonJS file using a Babel-
f7eb47b… lmata 23 // compatible transform (i.e. "__esModule" has not been set), then set
f7eb47b… lmata 24 // "default" to the CommonJS "module.exports" for node compatibility.
f7eb47b… lmata 25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
f7eb47b… lmata 26 mod
f7eb47b… lmata 27 ));
f7eb47b… lmata 28 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 29 var junit_exports = {};
f7eb47b… lmata 30 __export(junit_exports, {
f7eb47b… lmata 31 default: () => junit_default
f7eb47b… lmata 32 });
f7eb47b… lmata 33 module.exports = __toCommonJS(junit_exports);
f7eb47b… lmata 34 var import_fs = __toESM(require("fs"));
f7eb47b… lmata 35 var import_path = __toESM(require("path"));
f7eb47b… lmata 36 var import_utils = require("playwright-core/lib/utils");
f7eb47b… lmata 37 var import_base = require("./base");
f7eb47b… lmata 38 var import_util = require("../util");
f7eb47b… lmata 39 class JUnitReporter {
f7eb47b… lmata 40 constructor(options) {
f7eb47b… lmata 41 this.totalTests = 0;
f7eb47b… lmata 42 this.totalFailures = 0;
f7eb47b… lmata 43 this.totalSkipped = 0;
f7eb47b… lmata 44 this.stripANSIControlSequences = false;
f7eb47b… lmata 45 this.includeProjectInTestName = false;
f7eb47b… lmata 46 this.stripANSIControlSequences = (0, import_utils.getAsBooleanFromENV)("PLAYWRIGHT_JUNIT_STRIP_ANSI", !!options.stripANSIControlSequences);
f7eb47b… lmata 47 this.includeProjectInTestName = (0, import_utils.getAsBooleanFromENV)("PLAYWRIGHT_JUNIT_INCLUDE_PROJECT_IN_TEST_NAME", !!options.includeProjectInTestName);
f7eb47b… lmata 48 this.configDir = options.configDir;
f7eb47b… lmata 49 this.resolvedOutputFile = (0, import_base.resolveOutputFile)("JUNIT", options)?.outputFile;
f7eb47b… lmata 50 }
f7eb47b… lmata 51 version() {
f7eb47b… lmata 52 return "v2";
f7eb47b… lmata 53 }
f7eb47b… lmata 54 printsToStdio() {
f7eb47b… lmata 55 return !this.resolvedOutputFile;
f7eb47b… lmata 56 }
f7eb47b… lmata 57 onConfigure(config) {
f7eb47b… lmata 58 this.config = config;
f7eb47b… lmata 59 }
f7eb47b… lmata 60 onBegin(suite) {
f7eb47b… lmata 61 this.suite = suite;
f7eb47b… lmata 62 this.timestamp = /* @__PURE__ */ new Date();
f7eb47b… lmata 63 }
f7eb47b… lmata 64 async onEnd(result) {
f7eb47b… lmata 65 const children = [];
f7eb47b… lmata 66 for (const projectSuite of this.suite.suites) {
f7eb47b… lmata 67 for (const fileSuite of projectSuite.suites)
f7eb47b… lmata 68 children.push(await this._buildTestSuite(projectSuite.title, fileSuite));
f7eb47b… lmata 69 }
f7eb47b… lmata 70 const tokens = [];
f7eb47b… lmata 71 const self = this;
f7eb47b… lmata 72 const root = {
f7eb47b… lmata 73 name: "testsuites",
f7eb47b… lmata 74 attributes: {
f7eb47b… lmata 75 id: process.env[`PLAYWRIGHT_JUNIT_SUITE_ID`] || "",
f7eb47b… lmata 76 name: process.env[`PLAYWRIGHT_JUNIT_SUITE_NAME`] || "",
f7eb47b… lmata 77 tests: self.totalTests,
f7eb47b… lmata 78 failures: self.totalFailures,
f7eb47b… lmata 79 skipped: self.totalSkipped,
f7eb47b… lmata 80 errors: 0,
f7eb47b… lmata 81 time: result.duration / 1e3
f7eb47b… lmata 82 },
f7eb47b… lmata 83 children
f7eb47b… lmata 84 };
f7eb47b… lmata 85 serializeXML(root, tokens, this.stripANSIControlSequences);
f7eb47b… lmata 86 const reportString = tokens.join("\n");
f7eb47b… lmata 87 if (this.resolvedOutputFile) {
f7eb47b… lmata 88 await import_fs.default.promises.mkdir(import_path.default.dirname(this.resolvedOutputFile), { recursive: true });
f7eb47b… lmata 89 await import_fs.default.promises.writeFile(this.resolvedOutputFile, reportString);
f7eb47b… lmata 90 } else {
f7eb47b… lmata 91 console.log(reportString);
f7eb47b… lmata 92 }
f7eb47b… lmata 93 }
f7eb47b… lmata 94 async _buildTestSuite(projectName, suite) {
f7eb47b… lmata 95 let tests = 0;
f7eb47b… lmata 96 let skipped = 0;
f7eb47b… lmata 97 let failures = 0;
f7eb47b… lmata 98 let duration = 0;
f7eb47b… lmata 99 const children = [];
f7eb47b… lmata 100 const testCaseNamePrefix = projectName && this.includeProjectInTestName ? `[${projectName}] ` : "";
f7eb47b… lmata 101 for (const test of suite.allTests()) {
f7eb47b… lmata 102 ++tests;
f7eb47b… lmata 103 if (test.outcome() === "skipped")
f7eb47b… lmata 104 ++skipped;
f7eb47b… lmata 105 if (!test.ok())
f7eb47b… lmata 106 ++failures;
f7eb47b… lmata 107 for (const result of test.results)
f7eb47b… lmata 108 duration += result.duration;
f7eb47b… lmata 109 await this._addTestCase(suite.title, testCaseNamePrefix, test, children);
f7eb47b… lmata 110 }
f7eb47b… lmata 111 this.totalTests += tests;
f7eb47b… lmata 112 this.totalSkipped += skipped;
f7eb47b… lmata 113 this.totalFailures += failures;
f7eb47b… lmata 114 const entry = {
f7eb47b… lmata 115 name: "testsuite",
f7eb47b… lmata 116 attributes: {
f7eb47b… lmata 117 name: suite.title,
f7eb47b… lmata 118 timestamp: this.timestamp.toISOString(),
f7eb47b… lmata 119 hostname: projectName,
f7eb47b… lmata 120 tests,
f7eb47b… lmata 121 failures,
f7eb47b… lmata 122 skipped,
f7eb47b… lmata 123 time: duration / 1e3,
f7eb47b… lmata 124 errors: 0
f7eb47b… lmata 125 },
f7eb47b… lmata 126 children
f7eb47b… lmata 127 };
f7eb47b… lmata 128 return entry;
f7eb47b… lmata 129 }
f7eb47b… lmata 130 async _addTestCase(suiteName, namePrefix, test, entries) {
f7eb47b… lmata 131 const entry = {
f7eb47b… lmata 132 name: "testcase",
f7eb47b… lmata 133 attributes: {
f7eb47b… lmata 134 // Skip root, project, file
f7eb47b… lmata 135 name: namePrefix + test.titlePath().slice(3).join(" \u203A "),
f7eb47b… lmata 136 // filename
f7eb47b… lmata 137 classname: suiteName,
f7eb47b… lmata 138 time: test.results.reduce((acc, value) => acc + value.duration, 0) / 1e3
f7eb47b… lmata 139 },
f7eb47b… lmata 140 children: []
f7eb47b… lmata 141 };
f7eb47b… lmata 142 entries.push(entry);
f7eb47b… lmata 143 const properties = {
f7eb47b… lmata 144 name: "properties",
f7eb47b… lmata 145 children: []
f7eb47b… lmata 146 };
f7eb47b… lmata 147 for (const annotation of test.annotations) {
f7eb47b… lmata 148 const property = {
f7eb47b… lmata 149 name: "property",
f7eb47b… lmata 150 attributes: {
f7eb47b… lmata 151 name: annotation.type,
f7eb47b… lmata 152 value: annotation?.description ? annotation.description : ""
f7eb47b… lmata 153 }
f7eb47b… lmata 154 };
f7eb47b… lmata 155 properties.children?.push(property);
f7eb47b… lmata 156 }
f7eb47b… lmata 157 if (properties.children?.length)
f7eb47b… lmata 158 entry.children.push(properties);
f7eb47b… lmata 159 if (test.outcome() === "skipped") {
f7eb47b… lmata 160 entry.children.push({ name: "skipped" });
f7eb47b… lmata 161 return;
f7eb47b… lmata 162 }
f7eb47b… lmata 163 if (!test.ok()) {
f7eb47b… lmata 164 entry.children.push({
f7eb47b… lmata 165 name: "failure",
f7eb47b… lmata 166 attributes: {
f7eb47b… lmata 167 message: `${import_path.default.basename(test.location.file)}:${test.location.line}:${test.location.column} ${test.title}`,
f7eb47b… lmata 168 type: "FAILURE"
f7eb47b… lmata 169 },
f7eb47b… lmata 170 text: (0, import_util.stripAnsiEscapes)((0, import_base.formatFailure)(import_base.nonTerminalScreen, this.config, test))
f7eb47b… lmata 171 });
f7eb47b… lmata 172 }
f7eb47b… lmata 173 const systemOut = [];
f7eb47b… lmata 174 const systemErr = [];
f7eb47b… lmata 175 for (const result of test.results) {
f7eb47b… lmata 176 for (const item of result.stdout)
f7eb47b… lmata 177 systemOut.push(item.toString());
f7eb47b… lmata 178 for (const item of result.stderr)
f7eb47b… lmata 179 systemErr.push(item.toString());
f7eb47b… lmata 180 for (const attachment of result.attachments) {
f7eb47b… lmata 181 if (!attachment.path)
f7eb47b… lmata 182 continue;
f7eb47b… lmata 183 let attachmentPath = import_path.default.relative(this.configDir, attachment.path);
f7eb47b… lmata 184 try {
f7eb47b… lmata 185 if (this.resolvedOutputFile)
f7eb47b… lmata 186 attachmentPath = import_path.default.relative(import_path.default.dirname(this.resolvedOutputFile), attachment.path);
f7eb47b… lmata 187 } catch {
f7eb47b… lmata 188 systemOut.push(`
f7eb47b… lmata 189 Warning: Unable to make attachment path ${attachment.path} relative to report output file ${this.resolvedOutputFile}`);
f7eb47b… lmata 190 }
f7eb47b… lmata 191 try {
f7eb47b… lmata 192 await import_fs.default.promises.access(attachment.path);
f7eb47b… lmata 193 systemOut.push(`
f7eb47b… lmata 194 [[ATTACHMENT|${attachmentPath}]]
f7eb47b… lmata 195 `);
f7eb47b… lmata 196 } catch {
f7eb47b… lmata 197 systemErr.push(`
f7eb47b… lmata 198 Warning: attachment ${attachmentPath} is missing`);
f7eb47b… lmata 199 }
f7eb47b… lmata 200 }
f7eb47b… lmata 201 }
f7eb47b… lmata 202 if (systemOut.length)
f7eb47b… lmata 203 entry.children.push({ name: "system-out", text: systemOut.join("") });
f7eb47b… lmata 204 if (systemErr.length)
f7eb47b… lmata 205 entry.children.push({ name: "system-err", text: systemErr.join("") });
f7eb47b… lmata 206 }
f7eb47b… lmata 207 }
f7eb47b… lmata 208 function serializeXML(entry, tokens, stripANSIControlSequences) {
f7eb47b… lmata 209 const attrs = [];
f7eb47b… lmata 210 for (const [name, value] of Object.entries(entry.attributes || {}))
f7eb47b… lmata 211 attrs.push(`${name}="${escape(String(value), stripANSIControlSequences, false)}"`);
f7eb47b… lmata 212 tokens.push(`<${entry.name}${attrs.length ? " " : ""}${attrs.join(" ")}>`);
f7eb47b… lmata 213 for (const child of entry.children || [])
f7eb47b… lmata 214 serializeXML(child, tokens, stripANSIControlSequences);
f7eb47b… lmata 215 if (entry.text)
f7eb47b… lmata 216 tokens.push(escape(entry.text, stripANSIControlSequences, true));
f7eb47b… lmata 217 tokens.push(`</${entry.name}>`);
f7eb47b… lmata 218 }
f7eb47b… lmata 219 const discouragedXMLCharacters = /[\u0000-\u0008\u000b-\u000c\u000e-\u001f\u007f-\u0084\u0086-\u009f]/g;
f7eb47b… lmata 220 function escape(text, stripANSIControlSequences, isCharacterData) {
f7eb47b… lmata 221 if (stripANSIControlSequences)
f7eb47b… lmata 222 text = (0, import_util.stripAnsiEscapes)(text);
f7eb47b… lmata 223 if (isCharacterData) {
f7eb47b… lmata 224 text = "<![CDATA[" + text.replace(/]]>/g, "]]&gt;") + "]]>";
f7eb47b… lmata 225 } else {
f7eb47b… lmata 226 const escapeRe = /[&"'<>]/g;
f7eb47b… lmata 227 text = text.replace(escapeRe, (c) => ({ "&": "&amp;", '"': "&quot;", "'": "&apos;", "<": "&lt;", ">": "&gt;" })[c]);
f7eb47b… lmata 228 }
f7eb47b… lmata 229 text = text.replace(discouragedXMLCharacters, "");
f7eb47b… lmata 230 return text;
f7eb47b… lmata 231 }
f7eb47b… lmata 232 var junit_default = JUnitReporter;

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button