ScuttleBot

Source Blame History 144 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 markdown_exports = {};
f7eb47b… lmata 30 __export(markdown_exports, {
f7eb47b… lmata 31 default: () => markdown_default
f7eb47b… lmata 32 });
f7eb47b… lmata 33 module.exports = __toCommonJS(markdown_exports);
f7eb47b… lmata 34 var import_fs = __toESM(require("fs"));
f7eb47b… lmata 35 var import_path = __toESM(require("path"));
f7eb47b… lmata 36 class MarkdownReporter {
f7eb47b… lmata 37 constructor(options) {
f7eb47b… lmata 38 this._fatalErrors = [];
f7eb47b… lmata 39 this._options = options;
f7eb47b… lmata 40 }
f7eb47b… lmata 41 printsToStdio() {
f7eb47b… lmata 42 return false;
f7eb47b… lmata 43 }
f7eb47b… lmata 44 onBegin(config, suite) {
f7eb47b… lmata 45 this._config = config;
f7eb47b… lmata 46 this._suite = suite;
f7eb47b… lmata 47 }
f7eb47b… lmata 48 onError(error) {
f7eb47b… lmata 49 this._fatalErrors.push(error);
f7eb47b… lmata 50 }
f7eb47b… lmata 51 async onEnd(result) {
f7eb47b… lmata 52 const summary = this._generateSummary();
f7eb47b… lmata 53 const lines = [];
f7eb47b… lmata 54 if (this._fatalErrors.length)
f7eb47b… lmata 55 lines.push(`**${this._fatalErrors.length} fatal errors, not part of any test**`);
f7eb47b… lmata 56 if (summary.unexpected.length) {
f7eb47b… lmata 57 lines.push(`**${summary.unexpected.length} failed**`);
f7eb47b… lmata 58 this._printTestList(":x:", summary.unexpected, lines);
f7eb47b… lmata 59 }
f7eb47b… lmata 60 if (summary.flaky.length) {
f7eb47b… lmata 61 lines.push(`<details>`);
f7eb47b… lmata 62 lines.push(`<summary><b>${summary.flaky.length} flaky</b></summary>`);
f7eb47b… lmata 63 this._printTestList(":warning:", summary.flaky, lines, " <br/>");
f7eb47b… lmata 64 lines.push(`</details>`);
f7eb47b… lmata 65 lines.push(``);
f7eb47b… lmata 66 }
f7eb47b… lmata 67 if (summary.interrupted.length) {
f7eb47b… lmata 68 lines.push(`<details>`);
f7eb47b… lmata 69 lines.push(`<summary><b>${summary.interrupted.length} interrupted</b></summary>`);
f7eb47b… lmata 70 this._printTestList(":warning:", summary.interrupted, lines, " <br/>");
f7eb47b… lmata 71 lines.push(`</details>`);
f7eb47b… lmata 72 lines.push(``);
f7eb47b… lmata 73 }
f7eb47b… lmata 74 const skipped = summary.skipped ? `, ${summary.skipped} skipped` : "";
f7eb47b… lmata 75 const didNotRun = summary.didNotRun ? `, ${summary.didNotRun} did not run` : "";
f7eb47b… lmata 76 lines.push(`**${summary.expected} passed${skipped}${didNotRun}**`);
f7eb47b… lmata 77 lines.push(``);
f7eb47b… lmata 78 await this.publishReport(lines.join("\n"));
f7eb47b… lmata 79 }
f7eb47b… lmata 80 async publishReport(report) {
f7eb47b… lmata 81 const maybeRelativeFile = this._options.outputFile || "report.md";
f7eb47b… lmata 82 const reportFile = import_path.default.resolve(this._options.configDir, maybeRelativeFile);
f7eb47b… lmata 83 await import_fs.default.promises.mkdir(import_path.default.dirname(reportFile), { recursive: true });
f7eb47b… lmata 84 await import_fs.default.promises.writeFile(reportFile, report);
f7eb47b… lmata 85 }
f7eb47b… lmata 86 _generateSummary() {
f7eb47b… lmata 87 let didNotRun = 0;
f7eb47b… lmata 88 let skipped = 0;
f7eb47b… lmata 89 let expected = 0;
f7eb47b… lmata 90 const interrupted = [];
f7eb47b… lmata 91 const interruptedToPrint = [];
f7eb47b… lmata 92 const unexpected = [];
f7eb47b… lmata 93 const flaky = [];
f7eb47b… lmata 94 this._suite.allTests().forEach((test) => {
f7eb47b… lmata 95 switch (test.outcome()) {
f7eb47b… lmata 96 case "skipped": {
f7eb47b… lmata 97 if (test.results.some((result) => result.status === "interrupted")) {
f7eb47b… lmata 98 if (test.results.some((result) => !!result.error))
f7eb47b… lmata 99 interruptedToPrint.push(test);
f7eb47b… lmata 100 interrupted.push(test);
f7eb47b… lmata 101 } else if (!test.results.length || test.expectedStatus !== "skipped") {
f7eb47b… lmata 102 ++didNotRun;
f7eb47b… lmata 103 } else {
f7eb47b… lmata 104 ++skipped;
f7eb47b… lmata 105 }
f7eb47b… lmata 106 break;
f7eb47b… lmata 107 }
f7eb47b… lmata 108 case "expected":
f7eb47b… lmata 109 ++expected;
f7eb47b… lmata 110 break;
f7eb47b… lmata 111 case "unexpected":
f7eb47b… lmata 112 unexpected.push(test);
f7eb47b… lmata 113 break;
f7eb47b… lmata 114 case "flaky":
f7eb47b… lmata 115 flaky.push(test);
f7eb47b… lmata 116 break;
f7eb47b… lmata 117 }
f7eb47b… lmata 118 });
f7eb47b… lmata 119 return {
f7eb47b… lmata 120 didNotRun,
f7eb47b… lmata 121 skipped,
f7eb47b… lmata 122 expected,
f7eb47b… lmata 123 interrupted,
f7eb47b… lmata 124 unexpected,
f7eb47b… lmata 125 flaky
f7eb47b… lmata 126 };
f7eb47b… lmata 127 }
f7eb47b… lmata 128 _printTestList(prefix, tests, lines, suffix) {
f7eb47b… lmata 129 for (const test of tests)
f7eb47b… lmata 130 lines.push(`${prefix} ${formatTestTitle(this._config.rootDir, test)}${suffix || ""}`);
f7eb47b… lmata 131 lines.push(``);
f7eb47b… lmata 132 }
f7eb47b… lmata 133 }
f7eb47b… lmata 134 function formatTestTitle(rootDir, test) {
f7eb47b… lmata 135 const [, projectName, , ...titles] = test.titlePath();
f7eb47b… lmata 136 const relativeTestPath = import_path.default.relative(rootDir, test.location.file);
f7eb47b… lmata 137 const location = `${relativeTestPath}:${test.location.line}`;
f7eb47b… lmata 138 const projectTitle = projectName ? `[${projectName}] \u203A ` : "";
f7eb47b… lmata 139 const testTitle = `${projectTitle}${location} \u203A ${titles.join(" \u203A ")}`;
f7eb47b… lmata 140 const extraTags = test.tags.filter((t) => !testTitle.includes(t));
f7eb47b… lmata 141 const formattedTags = extraTags.map((t) => `\`${t}\``).join(" ");
f7eb47b… lmata 142 return `${testTitle}${extraTags.length ? " " + formattedTags : ""}`;
f7eb47b… lmata 143 }
f7eb47b… lmata 144 var markdown_default = MarkdownReporter;

Keyboard Shortcuts

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