@dloizides/frontend-devtools 1.5.0 → 1.7.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/CHANGELOG.md +122 -106
- package/dist/eslint/index.d.mts +4 -1
- package/dist/eslint/index.d.ts +4 -1
- package/dist/eslint/index.js +159 -14
- package/dist/eslint/index.js.map +1 -1
- package/dist/eslint/index.mjs +158 -15
- package/dist/eslint/index.mjs.map +1 -1
- package/dist/test-results/index.d.mts +82 -0
- package/dist/test-results/index.d.ts +82 -0
- package/dist/test-results/index.js +498 -0
- package/dist/test-results/index.js.map +1 -0
- package/dist/test-results/index.mjs +482 -0
- package/dist/test-results/index.mjs.map +1 -0
- package/dist/test-results/jestReporter.d.mts +30 -0
- package/dist/test-results/jestReporter.d.ts +30 -0
- package/dist/test-results/jestReporter.js +310 -0
- package/dist/test-results/jestReporter.js.map +1 -0
- package/dist/test-results/jestReporter.mjs +305 -0
- package/dist/test-results/jestReporter.mjs.map +1 -0
- package/dist/test-results/vitestReporter.d.mts +44 -0
- package/dist/test-results/vitestReporter.d.ts +44 -0
- package/dist/test-results/vitestReporter.js +292 -0
- package/dist/test-results/vitestReporter.js.map +1 -0
- package/dist/test-results/vitestReporter.mjs +286 -0
- package/dist/test-results/vitestReporter.mjs.map +1 -0
- package/dist/types-9BQtbdcF.d.mts +60 -0
- package/dist/types-9BQtbdcF.d.ts +60 -0
- package/package.json +33 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { S as SourceReader, R as RunInfo, T as TestdocResults, a as TestStatus, b as RequirementRecord } from '../types-9BQtbdcF.mjs';
|
|
2
|
+
export { F as Framework, c as ReporterOptions, d as TestRecord } from '../types-9BQtbdcF.mjs';
|
|
3
|
+
export { JestAssertion, JestFileResult, JestRunResults, default as TestdocJestReporter, convertJestResults } from './jestReporter.mjs';
|
|
4
|
+
export { default as TestdocVitestReporter, VitestFile, VitestTask, convertVitestFiles, vitestStatus } from './vitestReporter.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Declares the requirements a test file proves; the testdoc adapters read the literal call from source.
|
|
8
|
+
* @param map requirement id to its one-line text, string literals only
|
|
9
|
+
* @returns the same map, frozen
|
|
10
|
+
*/
|
|
11
|
+
declare function requirements(map: Record<string, string>): Readonly<Record<string, string>>;
|
|
12
|
+
|
|
13
|
+
declare const SCHEMA_ID = "testdoc-results.v1";
|
|
14
|
+
declare const DEFAULT_OUTPUT_FILE = "reports/testdoc-results.json";
|
|
15
|
+
|
|
16
|
+
interface PlaywrightResult {
|
|
17
|
+
status?: string;
|
|
18
|
+
duration?: number;
|
|
19
|
+
error?: {
|
|
20
|
+
message?: string;
|
|
21
|
+
stack?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface PlaywrightTest {
|
|
25
|
+
expectedStatus: string;
|
|
26
|
+
projectName?: string;
|
|
27
|
+
results: PlaywrightResult[];
|
|
28
|
+
}
|
|
29
|
+
interface PlaywrightSpec {
|
|
30
|
+
title: string;
|
|
31
|
+
file: string;
|
|
32
|
+
tags?: string[];
|
|
33
|
+
tests: PlaywrightTest[];
|
|
34
|
+
}
|
|
35
|
+
interface PlaywrightSuite {
|
|
36
|
+
title: string;
|
|
37
|
+
file: string;
|
|
38
|
+
specs?: PlaywrightSpec[];
|
|
39
|
+
suites?: PlaywrightSuite[];
|
|
40
|
+
}
|
|
41
|
+
interface PlaywrightReport {
|
|
42
|
+
config?: {
|
|
43
|
+
rootDir?: string;
|
|
44
|
+
};
|
|
45
|
+
stats?: {
|
|
46
|
+
startTime?: string;
|
|
47
|
+
duration?: number;
|
|
48
|
+
};
|
|
49
|
+
suites: PlaywrightSuite[];
|
|
50
|
+
}
|
|
51
|
+
interface PlaywrightConvertOptions {
|
|
52
|
+
rootDir?: string;
|
|
53
|
+
readSource?: SourceReader;
|
|
54
|
+
set?: string;
|
|
55
|
+
run?: Partial<RunInfo>;
|
|
56
|
+
}
|
|
57
|
+
declare function playwrightStatus(expectedStatus: string, actual: string | undefined): TestStatus;
|
|
58
|
+
/**
|
|
59
|
+
* Converts a Playwright JSON-reporter report into `testdoc-results.v1`.
|
|
60
|
+
* @returns the results document; requirements come from literal `requirements({...})` calls in each spec
|
|
61
|
+
*/
|
|
62
|
+
declare function convertPlaywrightReport(report: PlaywrightReport, options?: PlaywrightConvertOptions): TestdocResults;
|
|
63
|
+
declare function convertPlaywrightFile(inputFile: string, outputFile: string, options?: PlaywrightConvertOptions): TestdocResults;
|
|
64
|
+
|
|
65
|
+
interface RequirementProblem {
|
|
66
|
+
file: string;
|
|
67
|
+
line: number;
|
|
68
|
+
text: string;
|
|
69
|
+
}
|
|
70
|
+
interface ParsedRequirements {
|
|
71
|
+
requirements: RequirementRecord[];
|
|
72
|
+
problems: RequirementProblem[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reads every literal `requirements({...})` call in a source file.
|
|
76
|
+
* @returns the requirements in declaration order, plus every entry that is not a string literal
|
|
77
|
+
*/
|
|
78
|
+
declare function parseRequirements(source: string, file: string): ParsedRequirements;
|
|
79
|
+
|
|
80
|
+
declare function writeResults(outputFile: string, doc: TestdocResults): void;
|
|
81
|
+
|
|
82
|
+
export { DEFAULT_OUTPUT_FILE, type PlaywrightConvertOptions, type PlaywrightReport, type PlaywrightResult, type PlaywrightSpec, type PlaywrightSuite, type PlaywrightTest, RequirementRecord, RunInfo, SCHEMA_ID, SourceReader, TestStatus, TestdocResults, convertPlaywrightFile, convertPlaywrightReport, parseRequirements, playwrightStatus, requirements, writeResults };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { S as SourceReader, R as RunInfo, T as TestdocResults, a as TestStatus, b as RequirementRecord } from '../types-9BQtbdcF.js';
|
|
2
|
+
export { F as Framework, c as ReporterOptions, d as TestRecord } from '../types-9BQtbdcF.js';
|
|
3
|
+
export { JestAssertion, JestFileResult, JestRunResults, default as TestdocJestReporter, convertJestResults } from './jestReporter.js';
|
|
4
|
+
export { default as TestdocVitestReporter, VitestFile, VitestTask, convertVitestFiles, vitestStatus } from './vitestReporter.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Declares the requirements a test file proves; the testdoc adapters read the literal call from source.
|
|
8
|
+
* @param map requirement id to its one-line text, string literals only
|
|
9
|
+
* @returns the same map, frozen
|
|
10
|
+
*/
|
|
11
|
+
declare function requirements(map: Record<string, string>): Readonly<Record<string, string>>;
|
|
12
|
+
|
|
13
|
+
declare const SCHEMA_ID = "testdoc-results.v1";
|
|
14
|
+
declare const DEFAULT_OUTPUT_FILE = "reports/testdoc-results.json";
|
|
15
|
+
|
|
16
|
+
interface PlaywrightResult {
|
|
17
|
+
status?: string;
|
|
18
|
+
duration?: number;
|
|
19
|
+
error?: {
|
|
20
|
+
message?: string;
|
|
21
|
+
stack?: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface PlaywrightTest {
|
|
25
|
+
expectedStatus: string;
|
|
26
|
+
projectName?: string;
|
|
27
|
+
results: PlaywrightResult[];
|
|
28
|
+
}
|
|
29
|
+
interface PlaywrightSpec {
|
|
30
|
+
title: string;
|
|
31
|
+
file: string;
|
|
32
|
+
tags?: string[];
|
|
33
|
+
tests: PlaywrightTest[];
|
|
34
|
+
}
|
|
35
|
+
interface PlaywrightSuite {
|
|
36
|
+
title: string;
|
|
37
|
+
file: string;
|
|
38
|
+
specs?: PlaywrightSpec[];
|
|
39
|
+
suites?: PlaywrightSuite[];
|
|
40
|
+
}
|
|
41
|
+
interface PlaywrightReport {
|
|
42
|
+
config?: {
|
|
43
|
+
rootDir?: string;
|
|
44
|
+
};
|
|
45
|
+
stats?: {
|
|
46
|
+
startTime?: string;
|
|
47
|
+
duration?: number;
|
|
48
|
+
};
|
|
49
|
+
suites: PlaywrightSuite[];
|
|
50
|
+
}
|
|
51
|
+
interface PlaywrightConvertOptions {
|
|
52
|
+
rootDir?: string;
|
|
53
|
+
readSource?: SourceReader;
|
|
54
|
+
set?: string;
|
|
55
|
+
run?: Partial<RunInfo>;
|
|
56
|
+
}
|
|
57
|
+
declare function playwrightStatus(expectedStatus: string, actual: string | undefined): TestStatus;
|
|
58
|
+
/**
|
|
59
|
+
* Converts a Playwright JSON-reporter report into `testdoc-results.v1`.
|
|
60
|
+
* @returns the results document; requirements come from literal `requirements({...})` calls in each spec
|
|
61
|
+
*/
|
|
62
|
+
declare function convertPlaywrightReport(report: PlaywrightReport, options?: PlaywrightConvertOptions): TestdocResults;
|
|
63
|
+
declare function convertPlaywrightFile(inputFile: string, outputFile: string, options?: PlaywrightConvertOptions): TestdocResults;
|
|
64
|
+
|
|
65
|
+
interface RequirementProblem {
|
|
66
|
+
file: string;
|
|
67
|
+
line: number;
|
|
68
|
+
text: string;
|
|
69
|
+
}
|
|
70
|
+
interface ParsedRequirements {
|
|
71
|
+
requirements: RequirementRecord[];
|
|
72
|
+
problems: RequirementProblem[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reads every literal `requirements({...})` call in a source file.
|
|
76
|
+
* @returns the requirements in declaration order, plus every entry that is not a string literal
|
|
77
|
+
*/
|
|
78
|
+
declare function parseRequirements(source: string, file: string): ParsedRequirements;
|
|
79
|
+
|
|
80
|
+
declare function writeResults(outputFile: string, doc: TestdocResults): void;
|
|
81
|
+
|
|
82
|
+
export { DEFAULT_OUTPUT_FILE, type PlaywrightConvertOptions, type PlaywrightReport, type PlaywrightResult, type PlaywrightSpec, type PlaywrightSuite, type PlaywrightTest, RequirementRecord, RunInfo, SCHEMA_ID, SourceReader, TestStatus, TestdocResults, convertPlaywrightFile, convertPlaywrightReport, parseRequirements, playwrightStatus, requirements, writeResults };
|
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
// src/test-results/requirements.ts
|
|
7
|
+
function requirements(map) {
|
|
8
|
+
return Object.freeze({ ...map });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/test-results/TestStatus.ts
|
|
12
|
+
var TestStatus = /* @__PURE__ */ ((TestStatus2) => {
|
|
13
|
+
TestStatus2["Pass"] = "pass";
|
|
14
|
+
TestStatus2["Fail"] = "fail";
|
|
15
|
+
TestStatus2["Skip"] = "skip";
|
|
16
|
+
TestStatus2["XFail"] = "xfail";
|
|
17
|
+
TestStatus2["XPass"] = "xpass";
|
|
18
|
+
return TestStatus2;
|
|
19
|
+
})(TestStatus || {});
|
|
20
|
+
|
|
21
|
+
// src/test-results/Framework.ts
|
|
22
|
+
var Framework = /* @__PURE__ */ ((Framework2) => {
|
|
23
|
+
Framework2["Playwright"] = "playwright";
|
|
24
|
+
Framework2["Jest"] = "jest";
|
|
25
|
+
Framework2["Vitest"] = "vitest";
|
|
26
|
+
return Framework2;
|
|
27
|
+
})(Framework || {});
|
|
28
|
+
|
|
29
|
+
// src/test-results/constants.ts
|
|
30
|
+
var SCHEMA_ID = "testdoc-results.v1";
|
|
31
|
+
var DEFAULT_OUTPUT_FILE = "reports/testdoc-results.json";
|
|
32
|
+
var DEFAULT_SET = "baseline";
|
|
33
|
+
var MS_PER_SECOND = 1e3;
|
|
34
|
+
var REQUIREMENT_ID = "[A-Za-z][A-Za-z0-9_.-]*";
|
|
35
|
+
var RUN_NAME_LENGTH = 19;
|
|
36
|
+
var JSON_INDENT = 2;
|
|
37
|
+
function runName(startedAt) {
|
|
38
|
+
return startedAt.toISOString().slice(0, RUN_NAME_LENGTH).split(":").join("-");
|
|
39
|
+
}
|
|
40
|
+
function buildDocument(run, requirements2, tests) {
|
|
41
|
+
return { schema: SCHEMA_ID, run, requirements: requirements2, tests };
|
|
42
|
+
}
|
|
43
|
+
function runInfo(startedAt, finishedAt, overrides) {
|
|
44
|
+
return {
|
|
45
|
+
name: runName(startedAt),
|
|
46
|
+
startedAt: startedAt.toISOString(),
|
|
47
|
+
finishedAt: finishedAt.toISOString(),
|
|
48
|
+
...overrides
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function writeResults(outputFile, doc) {
|
|
52
|
+
fs.mkdirSync(path.dirname(outputFile), { recursive: true });
|
|
53
|
+
fs.writeFileSync(outputFile, `${JSON.stringify(doc, null, JSON_INDENT)}
|
|
54
|
+
`, "utf8");
|
|
55
|
+
}
|
|
56
|
+
var BACKSLASH = /\\/g;
|
|
57
|
+
function relativePath(rootDir, file) {
|
|
58
|
+
const rel = path.isAbsolute(file) ? path.relative(rootDir, file) : file;
|
|
59
|
+
return rel.replace(BACKSLASH, "/");
|
|
60
|
+
}
|
|
61
|
+
function fileReader(rootDir) {
|
|
62
|
+
return (file) => {
|
|
63
|
+
try {
|
|
64
|
+
return fs.readFileSync(path.isAbsolute(file) ? file : path.resolve(rootDir, file), "utf8");
|
|
65
|
+
} catch {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function defaultProject(rootDir) {
|
|
71
|
+
return path.basename(path.resolve(rootDir));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/test-results/utils/record.ts
|
|
75
|
+
var COVER_RE = new RegExp(`@(${REQUIREMENT_ID})`, "g");
|
|
76
|
+
var TAG_RE = new RegExp(`\\s*@${REQUIREMENT_ID}`, "g");
|
|
77
|
+
var SCENARIO_SEPARATOR = ", ";
|
|
78
|
+
var TRAILING_PUNCTUATION_RE = /[._-]+$/;
|
|
79
|
+
var UNDECLARED_REQUIREMENT_RE = /^[A-Z][A-Z0-9]*-\d+$/;
|
|
80
|
+
function extractCovers(texts, declared) {
|
|
81
|
+
const ids = texts.flatMap(
|
|
82
|
+
(text) => [...text.matchAll(COVER_RE)].map((match) => (match[1] ?? "").replace(TRAILING_PUNCTUATION_RE, ""))
|
|
83
|
+
);
|
|
84
|
+
return [...new Set(ids)].filter((id) => declared.has(id) || UNDECLARED_REQUIREMENT_RE.test(id));
|
|
85
|
+
}
|
|
86
|
+
function splitTitle(title) {
|
|
87
|
+
const at = title.indexOf(SCENARIO_SEPARATOR);
|
|
88
|
+
if (at < 0) {
|
|
89
|
+
return { scenario: title, expected: "" };
|
|
90
|
+
}
|
|
91
|
+
return { scenario: title.slice(0, at), expected: title.slice(at + SCENARIO_SEPARATOR.length) };
|
|
92
|
+
}
|
|
93
|
+
function buildRecord(input) {
|
|
94
|
+
const method = input.title.replace(TAG_RE, "").trim();
|
|
95
|
+
const describes = input.describePath.map((title) => title.replace(TAG_RE, "").trim());
|
|
96
|
+
const suffix = input.framework === "playwright" /* Playwright */ ? ` [${input.project}]` : "";
|
|
97
|
+
return {
|
|
98
|
+
id: [input.file, ...describes, method].join(" > ") + suffix,
|
|
99
|
+
framework: input.framework,
|
|
100
|
+
project: input.project,
|
|
101
|
+
set: input.set,
|
|
102
|
+
expectRed: input.expectRed,
|
|
103
|
+
feature: describes[0] ?? input.file,
|
|
104
|
+
class: describes[describes.length - 1] ?? input.file,
|
|
105
|
+
method,
|
|
106
|
+
description: [...describes, method].join(" "),
|
|
107
|
+
...splitTitle(method),
|
|
108
|
+
covers: extractCovers([...input.tags ?? [], ...input.describePath, input.title], input.declared),
|
|
109
|
+
status: input.status,
|
|
110
|
+
seconds: input.durationMs / MS_PER_SECOND,
|
|
111
|
+
message: input.message ?? "",
|
|
112
|
+
stack: input.stack ?? ""
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/test-results/utils/sourceRequirements.ts
|
|
117
|
+
var CALL_RE = /\brequirements\(\s*\{/g;
|
|
118
|
+
var KEY_RE = new RegExp(`^(['"\`]?)(${REQUIREMENT_ID})\\1$`);
|
|
119
|
+
var QUOTES = "'\"`";
|
|
120
|
+
var ESCAPE_RE = /\\(.)/g;
|
|
121
|
+
var TEMPLATE_HOLE = "${";
|
|
122
|
+
function skipString(src, start) {
|
|
123
|
+
const quote = src[start];
|
|
124
|
+
let i = start + 1;
|
|
125
|
+
while (i < src.length && src[i] !== quote) {
|
|
126
|
+
i += src[i] === "\\" ? 2 : 1;
|
|
127
|
+
}
|
|
128
|
+
return i + 1;
|
|
129
|
+
}
|
|
130
|
+
function splitTopLevel(src, from, offsetBase) {
|
|
131
|
+
const pieces = [];
|
|
132
|
+
let depth = 0;
|
|
133
|
+
let pieceStart = from;
|
|
134
|
+
let i = from;
|
|
135
|
+
while (i < src.length) {
|
|
136
|
+
const ch = src[i] ?? "";
|
|
137
|
+
if (QUOTES.includes(ch)) {
|
|
138
|
+
i = skipString(src, i);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const closesCall = ch === "}" && depth === 0;
|
|
142
|
+
if (closesCall || ch === "," && depth === 0) {
|
|
143
|
+
pieces.push({ text: src.slice(pieceStart, i), offset: offsetBase + pieceStart });
|
|
144
|
+
pieceStart = i + 1;
|
|
145
|
+
}
|
|
146
|
+
if (closesCall) {
|
|
147
|
+
return { pieces, end: i };
|
|
148
|
+
}
|
|
149
|
+
depth += "{[(".includes(ch) ? 1 : 0;
|
|
150
|
+
depth -= "}])".includes(ch) ? 1 : 0;
|
|
151
|
+
i += 1;
|
|
152
|
+
}
|
|
153
|
+
return { pieces, end: src.length };
|
|
154
|
+
}
|
|
155
|
+
function literal(value) {
|
|
156
|
+
const quote = value[0] ?? "";
|
|
157
|
+
const isSingleString = QUOTES.includes(quote) && value.length >= 2 && skipString(value, 0) === value.length;
|
|
158
|
+
if (!isSingleString || quote === "`" && value.includes(TEMPLATE_HOLE)) {
|
|
159
|
+
return void 0;
|
|
160
|
+
}
|
|
161
|
+
return value.slice(1, -1).replace(ESCAPE_RE, "$1");
|
|
162
|
+
}
|
|
163
|
+
function entryOf(piece, file) {
|
|
164
|
+
const text = piece.text.trim();
|
|
165
|
+
const colon = text.search(/:(?=(?:[^'"`]|['"`][^'"`]*['"`])*$)/);
|
|
166
|
+
const key = KEY_RE.exec(text.slice(0, Math.max(colon, 0)).trim());
|
|
167
|
+
const title = colon < 0 ? void 0 : literal(text.slice(colon + 1).trim());
|
|
168
|
+
return key !== null && title !== void 0 ? { id: key[2] ?? "", title, source: file } : void 0;
|
|
169
|
+
}
|
|
170
|
+
function lineAt(source, offset) {
|
|
171
|
+
return source.slice(0, offset).split("\n").length;
|
|
172
|
+
}
|
|
173
|
+
function parseRequirements(source, file) {
|
|
174
|
+
const parsed = { requirements: [], problems: [] };
|
|
175
|
+
for (const call of source.matchAll(CALL_RE)) {
|
|
176
|
+
const bodyStart = (call.index ?? 0) + call[0].length;
|
|
177
|
+
for (const piece of splitTopLevel(source, bodyStart, 0).pieces) {
|
|
178
|
+
if (piece.text.trim() === "") {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const entry = entryOf(piece, file);
|
|
182
|
+
const offset = piece.offset + (piece.text.length - piece.text.trimStart().length);
|
|
183
|
+
if (entry === void 0) {
|
|
184
|
+
parsed.problems.push({ file, line: lineAt(source, offset), text: piece.text.trim() });
|
|
185
|
+
} else {
|
|
186
|
+
parsed.requirements.push(entry);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return parsed;
|
|
191
|
+
}
|
|
192
|
+
function warn(problem) {
|
|
193
|
+
process.stderr.write(`testdoc: ${problem.file}:${problem.line} requirement skipped, not a literal: ${problem.text}
|
|
194
|
+
`);
|
|
195
|
+
}
|
|
196
|
+
var NONE = /* @__PURE__ */ new Set();
|
|
197
|
+
function requirementsFromFiles(files, readSource, rootDir) {
|
|
198
|
+
const byId = /* @__PURE__ */ new Map();
|
|
199
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
200
|
+
for (const file of new Set(files)) {
|
|
201
|
+
const source = readSource(file);
|
|
202
|
+
if (source === void 0) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const parsed = parseRequirements(source, relativePath(rootDir, file));
|
|
206
|
+
parsed.problems.forEach(warn);
|
|
207
|
+
byFile.set(file, new Set(parsed.requirements.map((requirement) => requirement.id)));
|
|
208
|
+
for (const requirement of parsed.requirements) {
|
|
209
|
+
if (!byId.has(requirement.id)) {
|
|
210
|
+
byId.set(requirement.id, requirement);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return { requirements: [...byId.values()], declaredIn: (file) => byFile.get(file) ?? NONE };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/test-results/playwright.ts
|
|
218
|
+
var EXPECTED_FAILED = "failed";
|
|
219
|
+
var SKIPPED = "skipped";
|
|
220
|
+
var PASSED = "passed";
|
|
221
|
+
function playwrightStatus(expectedStatus, actual) {
|
|
222
|
+
if (expectedStatus === SKIPPED || actual === SKIPPED || actual === void 0) {
|
|
223
|
+
return "skip" /* Skip */;
|
|
224
|
+
}
|
|
225
|
+
const passed = actual === PASSED;
|
|
226
|
+
if (expectedStatus === EXPECTED_FAILED) {
|
|
227
|
+
return passed ? "xpass" /* XPass */ : "xfail" /* XFail */;
|
|
228
|
+
}
|
|
229
|
+
return passed ? "pass" /* Pass */ : "fail" /* Fail */;
|
|
230
|
+
}
|
|
231
|
+
function placeSpecs(suite, path, out) {
|
|
232
|
+
const isDescribe = suite.title !== "" && suite.title !== suite.file;
|
|
233
|
+
const describePath = isDescribe ? [...path, suite.title] : path;
|
|
234
|
+
for (const spec of suite.specs ?? []) {
|
|
235
|
+
out.push({ spec, describePath });
|
|
236
|
+
}
|
|
237
|
+
for (const child of suite.suites ?? []) {
|
|
238
|
+
placeSpecs(child, describePath, out);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function toRecords({ spec, describePath }, set, declared) {
|
|
242
|
+
return spec.tests.map((test) => {
|
|
243
|
+
const last = test.results[test.results.length - 1];
|
|
244
|
+
return buildRecord({
|
|
245
|
+
framework: "playwright" /* Playwright */,
|
|
246
|
+
file: spec.file,
|
|
247
|
+
describePath,
|
|
248
|
+
title: spec.title,
|
|
249
|
+
tags: spec.tags,
|
|
250
|
+
status: playwrightStatus(test.expectedStatus, last?.status),
|
|
251
|
+
expectRed: test.expectedStatus === EXPECTED_FAILED,
|
|
252
|
+
durationMs: last?.duration ?? 0,
|
|
253
|
+
message: last?.error?.message,
|
|
254
|
+
stack: last?.error?.stack,
|
|
255
|
+
project: test.projectName !== void 0 && test.projectName !== "" ? test.projectName : "playwright" /* Playwright */,
|
|
256
|
+
set,
|
|
257
|
+
declared
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function convertPlaywrightReport(report, options = {}) {
|
|
262
|
+
const rootDir = options.rootDir ?? report.config?.rootDir ?? process.cwd();
|
|
263
|
+
const placed = [];
|
|
264
|
+
for (const suite of report.suites) {
|
|
265
|
+
placeSpecs(suite, [], placed);
|
|
266
|
+
}
|
|
267
|
+
const startedAt = new Date(report.stats?.startTime ?? Date.now());
|
|
268
|
+
const finishedAt = new Date(startedAt.getTime() + (report.stats?.duration ?? 0));
|
|
269
|
+
const files = placed.map(({ spec }) => spec.file);
|
|
270
|
+
const found = requirementsFromFiles(files, options.readSource ?? fileReader(rootDir), rootDir);
|
|
271
|
+
const set = options.set ?? DEFAULT_SET;
|
|
272
|
+
return buildDocument(
|
|
273
|
+
runInfo(startedAt, finishedAt, options.run),
|
|
274
|
+
found.requirements,
|
|
275
|
+
placed.flatMap((entry) => toRecords(entry, set, found.declaredIn(entry.spec.file)))
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
function convertPlaywrightFile(inputFile, outputFile, options = {}) {
|
|
279
|
+
const report = JSON.parse(fs.readFileSync(inputFile, "utf8"));
|
|
280
|
+
const doc = convertPlaywrightReport(report, options);
|
|
281
|
+
writeResults(outputFile, doc);
|
|
282
|
+
return doc;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/test-results/utils/failingTests.ts
|
|
286
|
+
var BLOCK_RE = /\b(describe(?:\.\w+)?|(?:it|test)\.failing)\(\s*(['"`])((?:\\.|(?!\2)[^\\])*)\2/g;
|
|
287
|
+
var DESCRIBE = "describe";
|
|
288
|
+
var KEY_SEPARATOR = " > ";
|
|
289
|
+
function closeBlocks(open, depth) {
|
|
290
|
+
while (open.length > 0 && (open[open.length - 1]?.depth ?? -1) >= depth) {
|
|
291
|
+
open.pop();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function failingKeys(source) {
|
|
295
|
+
const text = source ?? "";
|
|
296
|
+
const matches = [...text.matchAll(BLOCK_RE)];
|
|
297
|
+
const keys = /* @__PURE__ */ new Set();
|
|
298
|
+
const open = [];
|
|
299
|
+
let next = 0;
|
|
300
|
+
let depth = 0;
|
|
301
|
+
let i = 0;
|
|
302
|
+
while (i < text.length) {
|
|
303
|
+
while (next < matches.length && (matches[next]?.index ?? 0) < i) {
|
|
304
|
+
next += 1;
|
|
305
|
+
}
|
|
306
|
+
const match = matches[next];
|
|
307
|
+
if (match !== void 0 && match.index === i) {
|
|
308
|
+
const title = match[3] ?? "";
|
|
309
|
+
if ((match[1] ?? "").startsWith(DESCRIBE)) {
|
|
310
|
+
open.push({ title, depth });
|
|
311
|
+
} else {
|
|
312
|
+
keys.add([...open.map((block) => block.title), title].join(KEY_SEPARATOR));
|
|
313
|
+
}
|
|
314
|
+
i += match[0].length;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const ch = text[i] ?? "";
|
|
318
|
+
if (QUOTES.includes(ch)) {
|
|
319
|
+
i = skipString(text, i);
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
depth += ch === "{" ? 1 : 0;
|
|
323
|
+
if (ch === "}") {
|
|
324
|
+
depth -= 1;
|
|
325
|
+
closeBlocks(open, depth);
|
|
326
|
+
}
|
|
327
|
+
i += 1;
|
|
328
|
+
}
|
|
329
|
+
return keys;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// src/test-results/jestReporter.ts
|
|
333
|
+
var PASSED2 = "passed";
|
|
334
|
+
var FAILED = "failed";
|
|
335
|
+
var LINE_BREAK = "\n";
|
|
336
|
+
var ANSI_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
337
|
+
function jestStatus(status, failing) {
|
|
338
|
+
if (status !== PASSED2 && status !== FAILED) {
|
|
339
|
+
return "skip" /* Skip */;
|
|
340
|
+
}
|
|
341
|
+
if (failing) {
|
|
342
|
+
return status === PASSED2 ? "xfail" /* XFail */ : "xpass" /* XPass */;
|
|
343
|
+
}
|
|
344
|
+
return status === PASSED2 ? "pass" /* Pass */ : "fail" /* Fail */;
|
|
345
|
+
}
|
|
346
|
+
function toRecord(scope, assertion) {
|
|
347
|
+
const failure = (assertion.failureMessages?.[0] ?? "").replace(ANSI_RE, "");
|
|
348
|
+
const lineEnd = failure.indexOf(LINE_BREAK);
|
|
349
|
+
const failing = scope.failing.has([...assertion.ancestorTitles, assertion.title].join(KEY_SEPARATOR));
|
|
350
|
+
return buildRecord({
|
|
351
|
+
framework: "jest" /* Jest */,
|
|
352
|
+
file: scope.file,
|
|
353
|
+
describePath: assertion.ancestorTitles,
|
|
354
|
+
title: assertion.title,
|
|
355
|
+
status: jestStatus(assertion.status, failing),
|
|
356
|
+
expectRed: failing,
|
|
357
|
+
durationMs: assertion.duration ?? 0,
|
|
358
|
+
message: lineEnd < 0 ? failure : failure.slice(0, lineEnd),
|
|
359
|
+
stack: lineEnd < 0 ? "" : failure.slice(lineEnd + 1),
|
|
360
|
+
project: scope.project,
|
|
361
|
+
set: scope.set,
|
|
362
|
+
declared: scope.declared
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
function convertJestResults(results, options = {}, readSource) {
|
|
366
|
+
const rootDir = options.rootDir ?? process.cwd();
|
|
367
|
+
const read = readSource ?? fileReader(rootDir);
|
|
368
|
+
const project = options.project ?? defaultProject(rootDir);
|
|
369
|
+
const set = options.set ?? DEFAULT_SET;
|
|
370
|
+
const found = requirementsFromFiles(results.testResults.map((result) => result.testFilePath), read, rootDir);
|
|
371
|
+
const tests = results.testResults.flatMap((result) => {
|
|
372
|
+
const scope = {
|
|
373
|
+
file: relativePath(rootDir, result.testFilePath),
|
|
374
|
+
project,
|
|
375
|
+
set,
|
|
376
|
+
failing: failingKeys(read(result.testFilePath)),
|
|
377
|
+
declared: found.declaredIn(result.testFilePath)
|
|
378
|
+
};
|
|
379
|
+
return result.testResults.map((assertion) => toRecord(scope, assertion));
|
|
380
|
+
});
|
|
381
|
+
return buildDocument(runInfo(new Date(results.startTime), /* @__PURE__ */ new Date(), options.run), found.requirements, tests);
|
|
382
|
+
}
|
|
383
|
+
var TestdocJestReporter = class {
|
|
384
|
+
constructor(_globalConfig, options = {}) {
|
|
385
|
+
this.options = options;
|
|
386
|
+
}
|
|
387
|
+
onRunComplete(_contexts, results) {
|
|
388
|
+
const rootDir = this.options.rootDir ?? process.cwd();
|
|
389
|
+
const outputFile = path.resolve(rootDir, this.options.outputFile ?? DEFAULT_OUTPUT_FILE);
|
|
390
|
+
writeResults(outputFile, convertJestResults(results, this.options));
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
var SUITE = "suite";
|
|
394
|
+
var STATE_PASS = "pass";
|
|
395
|
+
var STATE_FAIL = "fail";
|
|
396
|
+
var NOT_RUN_MODES = /* @__PURE__ */ new Set(["skip", "todo"]);
|
|
397
|
+
function vitestStatus(task) {
|
|
398
|
+
const state = task.result?.state;
|
|
399
|
+
const ran = state === STATE_PASS || state === STATE_FAIL;
|
|
400
|
+
if (!ran || NOT_RUN_MODES.has(task.mode ?? "")) {
|
|
401
|
+
return "skip" /* Skip */;
|
|
402
|
+
}
|
|
403
|
+
if (task.fails === true) {
|
|
404
|
+
return state === STATE_PASS ? "xfail" /* XFail */ : "xpass" /* XPass */;
|
|
405
|
+
}
|
|
406
|
+
return state === STATE_PASS ? "pass" /* Pass */ : "fail" /* Fail */;
|
|
407
|
+
}
|
|
408
|
+
function collect(scope, tasks, path) {
|
|
409
|
+
for (const task of tasks) {
|
|
410
|
+
if (task.type === SUITE) {
|
|
411
|
+
collect(scope, task.tasks ?? [], [...path, task.name]);
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
const error = task.result?.errors?.[0];
|
|
415
|
+
scope.out.push(
|
|
416
|
+
buildRecord({
|
|
417
|
+
framework: "vitest" /* Vitest */,
|
|
418
|
+
file: scope.file,
|
|
419
|
+
describePath: path,
|
|
420
|
+
title: task.name,
|
|
421
|
+
status: vitestStatus(task),
|
|
422
|
+
expectRed: task.fails === true,
|
|
423
|
+
durationMs: task.result?.duration ?? 0,
|
|
424
|
+
message: error?.message,
|
|
425
|
+
stack: error?.stack,
|
|
426
|
+
project: scope.project,
|
|
427
|
+
set: scope.set,
|
|
428
|
+
declared: scope.declared
|
|
429
|
+
})
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function convertVitestFiles(files, options = {}, readSource) {
|
|
434
|
+
const rootDir = options.rootDir ?? process.cwd();
|
|
435
|
+
const tests = [];
|
|
436
|
+
const project = options.project ?? defaultProject(rootDir);
|
|
437
|
+
const set = options.set ?? DEFAULT_SET;
|
|
438
|
+
const paths = files.map((file) => file.filepath);
|
|
439
|
+
const found = requirementsFromFiles(paths, readSource ?? fileReader(rootDir), rootDir);
|
|
440
|
+
for (const file of files) {
|
|
441
|
+
const declared = found.declaredIn(file.filepath);
|
|
442
|
+
collect({ file: relativePath(rootDir, file.filepath), project, set, declared, out: tests }, file.tasks, []);
|
|
443
|
+
}
|
|
444
|
+
return buildDocument(runInfo(options.startedAt ?? /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date(), options.run), found.requirements, tests);
|
|
445
|
+
}
|
|
446
|
+
var TestdocVitestReporter = class {
|
|
447
|
+
constructor(options = {}) {
|
|
448
|
+
this.startedAt = /* @__PURE__ */ new Date();
|
|
449
|
+
this.written = false;
|
|
450
|
+
this.options = options;
|
|
451
|
+
}
|
|
452
|
+
onInit() {
|
|
453
|
+
this.startRun();
|
|
454
|
+
}
|
|
455
|
+
onTestRunStart() {
|
|
456
|
+
this.startRun();
|
|
457
|
+
}
|
|
458
|
+
onWatcherRerun() {
|
|
459
|
+
this.startRun();
|
|
460
|
+
}
|
|
461
|
+
startRun() {
|
|
462
|
+
this.startedAt = /* @__PURE__ */ new Date();
|
|
463
|
+
this.written = false;
|
|
464
|
+
}
|
|
465
|
+
onTestRunEnd(modules = []) {
|
|
466
|
+
this.write(modules.map((module) => module.task));
|
|
467
|
+
}
|
|
468
|
+
onFinished(files = []) {
|
|
469
|
+
this.write(files);
|
|
470
|
+
}
|
|
471
|
+
write(files) {
|
|
472
|
+
if (this.written) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
this.written = true;
|
|
476
|
+
const rootDir = this.options.rootDir ?? process.cwd();
|
|
477
|
+
const outputFile = path.resolve(rootDir, this.options.outputFile ?? DEFAULT_OUTPUT_FILE);
|
|
478
|
+
writeResults(outputFile, convertVitestFiles(files, { ...this.options, startedAt: this.startedAt }));
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
exports.DEFAULT_OUTPUT_FILE = DEFAULT_OUTPUT_FILE;
|
|
483
|
+
exports.Framework = Framework;
|
|
484
|
+
exports.SCHEMA_ID = SCHEMA_ID;
|
|
485
|
+
exports.TestStatus = TestStatus;
|
|
486
|
+
exports.TestdocJestReporter = TestdocJestReporter;
|
|
487
|
+
exports.TestdocVitestReporter = TestdocVitestReporter;
|
|
488
|
+
exports.convertJestResults = convertJestResults;
|
|
489
|
+
exports.convertPlaywrightFile = convertPlaywrightFile;
|
|
490
|
+
exports.convertPlaywrightReport = convertPlaywrightReport;
|
|
491
|
+
exports.convertVitestFiles = convertVitestFiles;
|
|
492
|
+
exports.parseRequirements = parseRequirements;
|
|
493
|
+
exports.playwrightStatus = playwrightStatus;
|
|
494
|
+
exports.requirements = requirements;
|
|
495
|
+
exports.vitestStatus = vitestStatus;
|
|
496
|
+
exports.writeResults = writeResults;
|
|
497
|
+
//# sourceMappingURL=index.js.map
|
|
498
|
+
//# sourceMappingURL=index.js.map
|