executable-stories-formatters 0.1.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/README.md +205 -0
- package/dist/adapters.cjs +324 -0
- package/dist/adapters.cjs.map +1 -0
- package/dist/adapters.d.cts +1 -0
- package/dist/adapters.d.ts +1 -0
- package/dist/adapters.js +295 -0
- package/dist/adapters.js.map +1 -0
- package/dist/cli.js +5399 -0
- package/dist/cli.js.map +1 -0
- package/dist/index-DCJ0NvAp.d.cts +378 -0
- package/dist/index-DCJ0NvAp.d.ts +378 -0
- package/dist/index.cjs +5519 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1468 -0
- package/dist/index.d.ts +1468 -0
- package/dist/index.js +5448 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -0
- package/schemas/README.md +663 -0
- package/schemas/examples/dotnet.json +108 -0
- package/schemas/examples/full.json +254 -0
- package/schemas/examples/go.json +108 -0
- package/schemas/examples/junit5.json +108 -0
- package/schemas/examples/minimal.json +18 -0
- package/schemas/examples/pytest.json +108 -0
- package/schemas/examples/rust.json +108 -0
- package/schemas/raw-run.schema.json +437 -0
package/dist/adapters.js
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// src/converters/adapters/jest.ts
|
|
2
|
+
function mapJestStatus(status) {
|
|
3
|
+
switch (status) {
|
|
4
|
+
case "passed":
|
|
5
|
+
return "pass";
|
|
6
|
+
case "failed":
|
|
7
|
+
return "fail";
|
|
8
|
+
case "pending":
|
|
9
|
+
return "pending";
|
|
10
|
+
case "todo":
|
|
11
|
+
return "todo";
|
|
12
|
+
default:
|
|
13
|
+
return "unknown";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function adaptJestRun(jestResults, storyReports, options = {}) {
|
|
17
|
+
const testCases = [];
|
|
18
|
+
const fileResultsMap = /* @__PURE__ */ new Map();
|
|
19
|
+
for (const fileResult of jestResults.testResults) {
|
|
20
|
+
fileResultsMap.set(fileResult.testFilePath, fileResult);
|
|
21
|
+
}
|
|
22
|
+
for (const report of storyReports) {
|
|
23
|
+
const fileResult = fileResultsMap.get(report.testFilePath);
|
|
24
|
+
for (const meta of report.scenarios) {
|
|
25
|
+
if (!meta?.scenario) continue;
|
|
26
|
+
const matchingTest = findMatchingJestTest(fileResult, meta);
|
|
27
|
+
testCases.push({
|
|
28
|
+
externalId: matchingTest?.fullName,
|
|
29
|
+
title: meta.scenario,
|
|
30
|
+
titlePath: meta.suitePath ? [...meta.suitePath, meta.scenario] : [meta.scenario],
|
|
31
|
+
story: meta,
|
|
32
|
+
sourceFile: report.testFilePath,
|
|
33
|
+
sourceLine: void 0,
|
|
34
|
+
// Jest doesn't provide line numbers
|
|
35
|
+
status: matchingTest ? mapJestStatus(matchingTest.status) : "unknown",
|
|
36
|
+
durationMs: matchingTest?.duration,
|
|
37
|
+
error: matchingTest?.failureMessages?.length ? { message: matchingTest.failureMessages.join("\n") } : void 0,
|
|
38
|
+
stepEvents: void 0,
|
|
39
|
+
// Jest doesn't provide step-level results
|
|
40
|
+
attachments: void 0,
|
|
41
|
+
// Jest doesn't capture attachments
|
|
42
|
+
meta: { jestStatus: matchingTest?.status },
|
|
43
|
+
retry: 0,
|
|
44
|
+
retries: 0,
|
|
45
|
+
projectName: void 0
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
testCases,
|
|
51
|
+
startedAtMs: jestResults.startTime,
|
|
52
|
+
finishedAtMs: Date.now(),
|
|
53
|
+
projectRoot: options.projectRoot ?? process.cwd(),
|
|
54
|
+
packageVersion: options.packageVersion,
|
|
55
|
+
gitSha: options.gitSha,
|
|
56
|
+
ci: detectCI()
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function findMatchingJestTest(fileResult, meta) {
|
|
60
|
+
if (!fileResult) return void 0;
|
|
61
|
+
const expectedFullName = meta.suitePath ? [...meta.suitePath, meta.scenario].join(" > ") : meta.scenario;
|
|
62
|
+
return fileResult.testResults.find((test) => test.fullName === expectedFullName);
|
|
63
|
+
}
|
|
64
|
+
function detectCI() {
|
|
65
|
+
if (process.env.GITHUB_ACTIONS === "true") {
|
|
66
|
+
return {
|
|
67
|
+
name: "GitHub Actions",
|
|
68
|
+
url: process.env.GITHUB_SERVER_URL && process.env.GITHUB_REPOSITORY ? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` : void 0,
|
|
69
|
+
buildNumber: process.env.GITHUB_RUN_NUMBER
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (process.env.JENKINS_URL) {
|
|
73
|
+
return {
|
|
74
|
+
name: "Jenkins",
|
|
75
|
+
url: process.env.BUILD_URL,
|
|
76
|
+
buildNumber: process.env.BUILD_NUMBER
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (process.env.CI) {
|
|
80
|
+
return {
|
|
81
|
+
name: "CI",
|
|
82
|
+
url: void 0,
|
|
83
|
+
buildNumber: void 0
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return void 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/converters/adapters/vitest.ts
|
|
90
|
+
function mapVitestStatus(state) {
|
|
91
|
+
switch (state) {
|
|
92
|
+
case "passed":
|
|
93
|
+
return "pass";
|
|
94
|
+
case "failed":
|
|
95
|
+
return "fail";
|
|
96
|
+
case "skipped":
|
|
97
|
+
return "skip";
|
|
98
|
+
case "pending":
|
|
99
|
+
return "pending";
|
|
100
|
+
default:
|
|
101
|
+
return "unknown";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function adaptVitestRun(testModules, options = {}) {
|
|
105
|
+
const testCases = [];
|
|
106
|
+
const projectRoot = options.projectRoot ?? process.cwd();
|
|
107
|
+
for (const mod of testModules) {
|
|
108
|
+
const collection = mod.children;
|
|
109
|
+
if (!collection) continue;
|
|
110
|
+
const moduleId = mod.moduleId ?? mod.relativeModuleId ?? "";
|
|
111
|
+
const sourcePath = moduleId.startsWith("/") ? moduleId : `${projectRoot}/${moduleId}`;
|
|
112
|
+
for (const test of collection.allTests()) {
|
|
113
|
+
const meta = test.meta();
|
|
114
|
+
const story = meta?.["story"];
|
|
115
|
+
if (!story?.scenario || !Array.isArray(story.steps)) continue;
|
|
116
|
+
const result = test.result();
|
|
117
|
+
const state = result?.state;
|
|
118
|
+
const errors = state === "failed" && result ? result.errors : void 0;
|
|
119
|
+
testCases.push({
|
|
120
|
+
externalId: test.name,
|
|
121
|
+
title: story.scenario,
|
|
122
|
+
titlePath: story.suitePath ? [...story.suitePath, story.scenario] : [story.scenario],
|
|
123
|
+
story,
|
|
124
|
+
sourceFile: sourcePath,
|
|
125
|
+
sourceLine: void 0,
|
|
126
|
+
// Vitest doesn't provide line numbers easily
|
|
127
|
+
status: mapVitestStatus(state),
|
|
128
|
+
durationMs: result?.duration,
|
|
129
|
+
error: errors?.length ? {
|
|
130
|
+
message: formatVitestError(errors[0]),
|
|
131
|
+
stack: errors[0].stack
|
|
132
|
+
} : void 0,
|
|
133
|
+
stepEvents: void 0,
|
|
134
|
+
// Vitest doesn't provide step-level results
|
|
135
|
+
attachments: void 0,
|
|
136
|
+
// Vitest doesn't capture attachments
|
|
137
|
+
meta: { vitestState: state },
|
|
138
|
+
retry: 0,
|
|
139
|
+
retries: 0,
|
|
140
|
+
projectName: void 0
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
testCases,
|
|
146
|
+
startedAtMs: options.startedAtMs,
|
|
147
|
+
finishedAtMs: Date.now(),
|
|
148
|
+
projectRoot,
|
|
149
|
+
packageVersion: options.packageVersion,
|
|
150
|
+
gitSha: options.gitSha,
|
|
151
|
+
ci: detectCI2()
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function formatVitestError(error) {
|
|
155
|
+
const parts = [];
|
|
156
|
+
if (error.message) {
|
|
157
|
+
parts.push(error.message);
|
|
158
|
+
}
|
|
159
|
+
if (error.diff) {
|
|
160
|
+
parts.push("", error.diff);
|
|
161
|
+
}
|
|
162
|
+
return parts.join("\n") || "Unknown error";
|
|
163
|
+
}
|
|
164
|
+
function detectCI2() {
|
|
165
|
+
if (process.env.GITHUB_ACTIONS === "true") {
|
|
166
|
+
return {
|
|
167
|
+
name: "GitHub Actions",
|
|
168
|
+
url: process.env.GITHUB_SERVER_URL && process.env.GITHUB_REPOSITORY ? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` : void 0,
|
|
169
|
+
buildNumber: process.env.GITHUB_RUN_NUMBER
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (process.env.JENKINS_URL) {
|
|
173
|
+
return {
|
|
174
|
+
name: "Jenkins",
|
|
175
|
+
url: process.env.BUILD_URL,
|
|
176
|
+
buildNumber: process.env.BUILD_NUMBER
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (process.env.CI) {
|
|
180
|
+
return {
|
|
181
|
+
name: "CI",
|
|
182
|
+
url: void 0,
|
|
183
|
+
buildNumber: void 0
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return void 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/converters/adapters/playwright.ts
|
|
190
|
+
function mapPlaywrightStatus(status) {
|
|
191
|
+
switch (status) {
|
|
192
|
+
case "passed":
|
|
193
|
+
return "pass";
|
|
194
|
+
case "failed":
|
|
195
|
+
return "fail";
|
|
196
|
+
case "skipped":
|
|
197
|
+
return "skip";
|
|
198
|
+
case "timedOut":
|
|
199
|
+
return "timeout";
|
|
200
|
+
case "interrupted":
|
|
201
|
+
return "interrupted";
|
|
202
|
+
default:
|
|
203
|
+
return "unknown";
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function adaptPlaywrightRun(testResults, options = {}) {
|
|
207
|
+
const testCases = [];
|
|
208
|
+
const projectRoot = options.projectRoot ?? process.cwd();
|
|
209
|
+
for (const [test, result] of testResults) {
|
|
210
|
+
const storyAnnotation = test.annotations.find((a) => a.type === "story-meta");
|
|
211
|
+
if (!storyAnnotation?.description) continue;
|
|
212
|
+
let story;
|
|
213
|
+
try {
|
|
214
|
+
story = JSON.parse(storyAnnotation.description);
|
|
215
|
+
} catch {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (!story?.scenario || !Array.isArray(story.steps)) continue;
|
|
219
|
+
const attachments = convertAttachments(result.attachments);
|
|
220
|
+
const error = result.errors?.length ? {
|
|
221
|
+
message: result.errors[0].message,
|
|
222
|
+
stack: result.errors[0].stack
|
|
223
|
+
} : void 0;
|
|
224
|
+
testCases.push({
|
|
225
|
+
externalId: test.titlePath().join(" > "),
|
|
226
|
+
title: story.scenario,
|
|
227
|
+
titlePath: test.titlePath(),
|
|
228
|
+
story,
|
|
229
|
+
sourceFile: test.location.file,
|
|
230
|
+
sourceLine: test.location.line,
|
|
231
|
+
status: mapPlaywrightStatus(result.status),
|
|
232
|
+
durationMs: result.duration,
|
|
233
|
+
error,
|
|
234
|
+
stepEvents: void 0,
|
|
235
|
+
// Playwright could provide step info, but we don't capture it yet
|
|
236
|
+
attachments,
|
|
237
|
+
meta: {
|
|
238
|
+
playwrightStatus: result.status,
|
|
239
|
+
column: test.location.column
|
|
240
|
+
},
|
|
241
|
+
retry: result.retry,
|
|
242
|
+
retries: test.retries,
|
|
243
|
+
projectName: options.projectName
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
testCases,
|
|
248
|
+
startedAtMs: options.startedAtMs,
|
|
249
|
+
finishedAtMs: Date.now(),
|
|
250
|
+
projectRoot,
|
|
251
|
+
packageVersion: options.packageVersion,
|
|
252
|
+
gitSha: options.gitSha,
|
|
253
|
+
ci: detectCI3()
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function convertAttachments(attachments) {
|
|
257
|
+
return attachments.map((att) => ({
|
|
258
|
+
name: att.name,
|
|
259
|
+
mediaType: att.contentType,
|
|
260
|
+
path: att.path,
|
|
261
|
+
body: att.body ? att.body.toString("base64") : void 0,
|
|
262
|
+
encoding: att.body ? "BASE64" : void 0,
|
|
263
|
+
byteLength: att.body?.length
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
function detectCI3() {
|
|
267
|
+
if (process.env.GITHUB_ACTIONS === "true") {
|
|
268
|
+
return {
|
|
269
|
+
name: "GitHub Actions",
|
|
270
|
+
url: process.env.GITHUB_SERVER_URL && process.env.GITHUB_REPOSITORY ? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` : void 0,
|
|
271
|
+
buildNumber: process.env.GITHUB_RUN_NUMBER
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (process.env.JENKINS_URL) {
|
|
275
|
+
return {
|
|
276
|
+
name: "Jenkins",
|
|
277
|
+
url: process.env.BUILD_URL,
|
|
278
|
+
buildNumber: process.env.BUILD_NUMBER
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (process.env.CI) {
|
|
282
|
+
return {
|
|
283
|
+
name: "CI",
|
|
284
|
+
url: void 0,
|
|
285
|
+
buildNumber: void 0
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
return void 0;
|
|
289
|
+
}
|
|
290
|
+
export {
|
|
291
|
+
adaptJestRun,
|
|
292
|
+
adaptPlaywrightRun,
|
|
293
|
+
adaptVitestRun
|
|
294
|
+
};
|
|
295
|
+
//# sourceMappingURL=adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/converters/adapters/jest.ts","../src/converters/adapters/vitest.ts","../src/converters/adapters/playwright.ts"],"sourcesContent":["/**\n * Jest Adapter - Layer 1.\n *\n * Transforms Jest test results and story reports into RawRun.\n */\n\nimport type { StoryMeta } from \"../../types/story\";\nimport type { RawRun, RawTestCase, RawStatus } from \"../../types/raw\";\n\n/** Jest test result shape (subset of what Jest provides) */\nexport interface JestTestResult {\n fullName: string;\n status: \"passed\" | \"failed\" | \"pending\" | \"todo\";\n duration?: number;\n failureMessages?: string[];\n}\n\n/** Jest file result shape */\nexport interface JestFileResult {\n testFilePath: string;\n testResults: JestTestResult[];\n}\n\n/** Jest aggregated result shape */\nexport interface JestAggregatedResult {\n testResults: JestFileResult[];\n startTime?: number;\n}\n\n/** Story file report written by story.init() */\nexport interface StoryFileReport {\n testFilePath: string;\n scenarios: StoryMeta[];\n}\n\n/** Options for Jest adapter */\nexport interface JestAdapterOptions {\n /** Project root directory */\n projectRoot?: string;\n /** Package version */\n packageVersion?: string;\n /** Git SHA */\n gitSha?: string;\n}\n\n/**\n * Map Jest status to RawStatus.\n */\nfunction mapJestStatus(status: JestTestResult[\"status\"]): RawStatus {\n switch (status) {\n case \"passed\":\n return \"pass\";\n case \"failed\":\n return \"fail\";\n case \"pending\":\n return \"pending\";\n case \"todo\":\n return \"todo\";\n default:\n return \"unknown\";\n }\n}\n\n/**\n * Adapt Jest results and story reports to RawRun.\n *\n * @param jestResults - Jest aggregated results\n * @param storyReports - Story reports from story.init()\n * @param options - Adapter options\n * @returns RawRun for ACL processing\n */\nexport function adaptJestRun(\n jestResults: JestAggregatedResult,\n storyReports: StoryFileReport[],\n options: JestAdapterOptions = {}\n): RawRun {\n const testCases: RawTestCase[] = [];\n\n // Build map of Jest results by file for lookup\n const fileResultsMap = new Map<string, JestFileResult>();\n for (const fileResult of jestResults.testResults) {\n fileResultsMap.set(fileResult.testFilePath, fileResult);\n }\n\n // Process each story report\n for (const report of storyReports) {\n const fileResult = fileResultsMap.get(report.testFilePath);\n\n for (const meta of report.scenarios) {\n if (!meta?.scenario) continue;\n\n // Find matching Jest test result\n const matchingTest = findMatchingJestTest(fileResult, meta);\n\n testCases.push({\n externalId: matchingTest?.fullName,\n title: meta.scenario,\n titlePath: meta.suitePath\n ? [...meta.suitePath, meta.scenario]\n : [meta.scenario],\n story: meta,\n sourceFile: report.testFilePath,\n sourceLine: undefined, // Jest doesn't provide line numbers\n status: matchingTest ? mapJestStatus(matchingTest.status) : \"unknown\",\n durationMs: matchingTest?.duration,\n error: matchingTest?.failureMessages?.length\n ? { message: matchingTest.failureMessages.join(\"\\n\") }\n : undefined,\n stepEvents: undefined, // Jest doesn't provide step-level results\n attachments: undefined, // Jest doesn't capture attachments\n meta: { jestStatus: matchingTest?.status },\n retry: 0,\n retries: 0,\n projectName: undefined,\n });\n }\n }\n\n return {\n testCases,\n startedAtMs: jestResults.startTime,\n finishedAtMs: Date.now(),\n projectRoot: options.projectRoot ?? process.cwd(),\n packageVersion: options.packageVersion,\n gitSha: options.gitSha,\n ci: detectCI(),\n };\n}\n\n/**\n * Find matching Jest test result for a story.\n *\n * Matches by constructing fullName from suitePath and scenario.\n */\nfunction findMatchingJestTest(\n fileResult: JestFileResult | undefined,\n meta: StoryMeta\n): JestTestResult | undefined {\n if (!fileResult) return undefined;\n\n // Construct expected fullName\n const expectedFullName = meta.suitePath\n ? [...meta.suitePath, meta.scenario].join(\" > \")\n : meta.scenario;\n\n return fileResult.testResults.find((test) => test.fullName === expectedFullName);\n}\n\n/**\n * Detect CI environment.\n */\nfunction detectCI() {\n if (process.env.GITHUB_ACTIONS === \"true\") {\n return {\n name: \"GitHub Actions\",\n url: process.env.GITHUB_SERVER_URL && process.env.GITHUB_REPOSITORY\n ? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`\n : undefined,\n buildNumber: process.env.GITHUB_RUN_NUMBER,\n };\n }\n\n if (process.env.JENKINS_URL) {\n return {\n name: \"Jenkins\",\n url: process.env.BUILD_URL,\n buildNumber: process.env.BUILD_NUMBER,\n };\n }\n\n if (process.env.CI) {\n return {\n name: \"CI\",\n url: undefined,\n buildNumber: undefined,\n };\n }\n\n return undefined;\n}\n","/**\n * Vitest Adapter - Layer 1.\n *\n * Transforms Vitest test results into RawRun.\n */\n\nimport type { StoryMeta } from \"../../types/story\";\nimport type { RawRun, RawTestCase, RawStatus } from \"../../types/raw\";\n\n/** Vitest test state */\nexport type VitestState = \"passed\" | \"failed\" | \"skipped\" | \"pending\";\n\n/** Vitest serialized error */\nexport interface VitestSerializedError {\n message?: string;\n stack?: string;\n diff?: string;\n}\n\n/** Vitest test result shape */\nexport interface VitestTestResult {\n state?: VitestState;\n duration?: number;\n errors?: VitestSerializedError[];\n}\n\n/** Vitest test case shape (minimal) */\nexport interface VitestTestCase {\n name: string;\n meta: () => Record<string, unknown>;\n result: () => VitestTestResult | undefined;\n}\n\n/** Vitest test module shape (minimal) */\nexport interface VitestTestModule {\n moduleId?: string;\n relativeModuleId?: string;\n children?: {\n allTests: () => Iterable<VitestTestCase>;\n };\n}\n\n/** Options for Vitest adapter */\nexport interface VitestAdapterOptions {\n /** Project root directory */\n projectRoot?: string;\n /** Package version */\n packageVersion?: string;\n /** Git SHA */\n gitSha?: string;\n /** Start time (epoch ms) */\n startedAtMs?: number;\n}\n\n/**\n * Map Vitest state to RawStatus.\n */\nfunction mapVitestStatus(state?: VitestState): RawStatus {\n switch (state) {\n case \"passed\":\n return \"pass\";\n case \"failed\":\n return \"fail\";\n case \"skipped\":\n return \"skip\";\n case \"pending\":\n return \"pending\";\n default:\n return \"unknown\";\n }\n}\n\n/**\n * Adapt Vitest test modules to RawRun.\n *\n * @param testModules - Vitest test modules\n * @param options - Adapter options\n * @returns RawRun for ACL processing\n */\nexport function adaptVitestRun(\n testModules: ReadonlyArray<VitestTestModule>,\n options: VitestAdapterOptions = {}\n): RawRun {\n const testCases: RawTestCase[] = [];\n const projectRoot = options.projectRoot ?? process.cwd();\n\n for (const mod of testModules) {\n const collection = mod.children;\n if (!collection) continue;\n\n // Get module path\n const moduleId = mod.moduleId ?? mod.relativeModuleId ?? \"\";\n const sourcePath = moduleId.startsWith(\"/\")\n ? moduleId\n : `${projectRoot}/${moduleId}`;\n\n for (const test of collection.allTests()) {\n const meta = test.meta();\n const story = meta?.[\"story\"] as StoryMeta | undefined;\n\n if (!story?.scenario || !Array.isArray(story.steps)) continue;\n\n const result = test.result();\n const state = result?.state;\n const errors = state === \"failed\" && result ? result.errors : undefined;\n\n testCases.push({\n externalId: test.name,\n title: story.scenario,\n titlePath: story.suitePath\n ? [...story.suitePath, story.scenario]\n : [story.scenario],\n story,\n sourceFile: sourcePath,\n sourceLine: undefined, // Vitest doesn't provide line numbers easily\n status: mapVitestStatus(state),\n durationMs: result?.duration,\n error: errors?.length\n ? {\n message: formatVitestError(errors[0]),\n stack: errors[0].stack,\n }\n : undefined,\n stepEvents: undefined, // Vitest doesn't provide step-level results\n attachments: undefined, // Vitest doesn't capture attachments\n meta: { vitestState: state },\n retry: 0,\n retries: 0,\n projectName: undefined,\n });\n }\n }\n\n return {\n testCases,\n startedAtMs: options.startedAtMs,\n finishedAtMs: Date.now(),\n projectRoot,\n packageVersion: options.packageVersion,\n gitSha: options.gitSha,\n ci: detectCI(),\n };\n}\n\n/**\n * Format Vitest error message.\n */\nfunction formatVitestError(error: VitestSerializedError): string {\n const parts: string[] = [];\n\n if (error.message) {\n parts.push(error.message);\n }\n\n if (error.diff) {\n parts.push(\"\", error.diff);\n }\n\n return parts.join(\"\\n\") || \"Unknown error\";\n}\n\n/**\n * Detect CI environment.\n */\nfunction detectCI() {\n if (process.env.GITHUB_ACTIONS === \"true\") {\n return {\n name: \"GitHub Actions\",\n url: process.env.GITHUB_SERVER_URL && process.env.GITHUB_REPOSITORY\n ? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`\n : undefined,\n buildNumber: process.env.GITHUB_RUN_NUMBER,\n };\n }\n\n if (process.env.JENKINS_URL) {\n return {\n name: \"Jenkins\",\n url: process.env.BUILD_URL,\n buildNumber: process.env.BUILD_NUMBER,\n };\n }\n\n if (process.env.CI) {\n return {\n name: \"CI\",\n url: undefined,\n buildNumber: undefined,\n };\n }\n\n return undefined;\n}\n","/**\n * Playwright Adapter - Layer 1.\n *\n * Transforms Playwright test results into RawRun.\n */\n\nimport type { StoryMeta } from \"../../types/story\";\nimport type { RawRun, RawTestCase, RawStatus, RawAttachment } from \"../../types/raw\";\n\n/** Playwright test status */\nexport type PlaywrightStatus =\n | \"passed\"\n | \"failed\"\n | \"skipped\"\n | \"timedOut\"\n | \"interrupted\";\n\n/** Playwright test error */\nexport interface PlaywrightError {\n message?: string;\n stack?: string;\n}\n\n/** Playwright attachment */\nexport interface PlaywrightAttachment {\n name: string;\n contentType: string;\n path?: string;\n body?: Buffer;\n}\n\n/** Playwright test result */\nexport interface PlaywrightTestResult {\n status: PlaywrightStatus;\n duration: number;\n errors: PlaywrightError[];\n attachments: PlaywrightAttachment[];\n retry: number;\n}\n\n/** Playwright test case annotation */\nexport interface PlaywrightAnnotation {\n type: string;\n description?: string;\n}\n\n/** Playwright test location */\nexport interface PlaywrightLocation {\n file: string;\n line: number;\n column: number;\n}\n\n/** Playwright test case shape (minimal) */\nexport interface PlaywrightTestCase {\n title: string;\n titlePath: () => string[];\n annotations: PlaywrightAnnotation[];\n location: PlaywrightLocation;\n retries: number;\n}\n\n/** Options for Playwright adapter */\nexport interface PlaywrightAdapterOptions {\n /** Project root directory */\n projectRoot?: string;\n /** Package version */\n packageVersion?: string;\n /** Git SHA */\n gitSha?: string;\n /** Start time (epoch ms) */\n startedAtMs?: number;\n /** Playwright project name */\n projectName?: string;\n}\n\n/**\n * Map Playwright status to RawStatus.\n */\nfunction mapPlaywrightStatus(status: PlaywrightStatus): RawStatus {\n switch (status) {\n case \"passed\":\n return \"pass\";\n case \"failed\":\n return \"fail\";\n case \"skipped\":\n return \"skip\";\n case \"timedOut\":\n return \"timeout\";\n case \"interrupted\":\n return \"interrupted\";\n default:\n return \"unknown\";\n }\n}\n\n/**\n * Adapt Playwright test results to RawRun.\n *\n * @param testResults - Array of [testCase, result] tuples\n * @param options - Adapter options\n * @returns RawRun for ACL processing\n */\nexport function adaptPlaywrightRun(\n testResults: Array<[PlaywrightTestCase, PlaywrightTestResult]>,\n options: PlaywrightAdapterOptions = {}\n): RawRun {\n const testCases: RawTestCase[] = [];\n const projectRoot = options.projectRoot ?? process.cwd();\n\n for (const [test, result] of testResults) {\n // Find story-meta annotation\n const storyAnnotation = test.annotations.find((a) => a.type === \"story-meta\");\n if (!storyAnnotation?.description) continue;\n\n let story: StoryMeta;\n try {\n story = JSON.parse(storyAnnotation.description);\n } catch {\n continue; // Skip if annotation is not valid JSON\n }\n\n if (!story?.scenario || !Array.isArray(story.steps)) continue;\n\n // Convert attachments\n const attachments = convertAttachments(result.attachments);\n\n // Get error info\n const error = result.errors?.length\n ? {\n message: result.errors[0].message,\n stack: result.errors[0].stack,\n }\n : undefined;\n\n testCases.push({\n externalId: test.titlePath().join(\" > \"),\n title: story.scenario,\n titlePath: test.titlePath(),\n story,\n sourceFile: test.location.file,\n sourceLine: test.location.line,\n status: mapPlaywrightStatus(result.status),\n durationMs: result.duration,\n error,\n stepEvents: undefined, // Playwright could provide step info, but we don't capture it yet\n attachments,\n meta: {\n playwrightStatus: result.status,\n column: test.location.column,\n },\n retry: result.retry,\n retries: test.retries,\n projectName: options.projectName,\n });\n }\n\n return {\n testCases,\n startedAtMs: options.startedAtMs,\n finishedAtMs: Date.now(),\n projectRoot,\n packageVersion: options.packageVersion,\n gitSha: options.gitSha,\n ci: detectCI(),\n };\n}\n\n/**\n * Convert Playwright attachments to raw attachments.\n */\nfunction convertAttachments(\n attachments: PlaywrightAttachment[]\n): RawAttachment[] {\n return attachments.map((att) => ({\n name: att.name,\n mediaType: att.contentType,\n path: att.path,\n body: att.body ? att.body.toString(\"base64\") : undefined,\n encoding: att.body ? \"BASE64\" as const : undefined,\n byteLength: att.body?.length,\n }));\n}\n\n/**\n * Detect CI environment.\n */\nfunction detectCI() {\n if (process.env.GITHUB_ACTIONS === \"true\") {\n return {\n name: \"GitHub Actions\",\n url: process.env.GITHUB_SERVER_URL && process.env.GITHUB_REPOSITORY\n ? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`\n : undefined,\n buildNumber: process.env.GITHUB_RUN_NUMBER,\n };\n }\n\n if (process.env.JENKINS_URL) {\n return {\n name: \"Jenkins\",\n url: process.env.BUILD_URL,\n buildNumber: process.env.BUILD_NUMBER,\n };\n }\n\n if (process.env.CI) {\n return {\n name: \"CI\",\n url: undefined,\n buildNumber: undefined,\n };\n }\n\n return undefined;\n}\n"],"mappings":";AAgDA,SAAS,cAAc,QAA6C;AAClE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAUO,SAAS,aACd,aACA,cACA,UAA8B,CAAC,GACvB;AACR,QAAM,YAA2B,CAAC;AAGlC,QAAM,iBAAiB,oBAAI,IAA4B;AACvD,aAAW,cAAc,YAAY,aAAa;AAChD,mBAAe,IAAI,WAAW,cAAc,UAAU;AAAA,EACxD;AAGA,aAAW,UAAU,cAAc;AACjC,UAAM,aAAa,eAAe,IAAI,OAAO,YAAY;AAEzD,eAAW,QAAQ,OAAO,WAAW;AACnC,UAAI,CAAC,MAAM,SAAU;AAGrB,YAAM,eAAe,qBAAqB,YAAY,IAAI;AAE1D,gBAAU,KAAK;AAAA,QACb,YAAY,cAAc;AAAA,QAC1B,OAAO,KAAK;AAAA,QACZ,WAAW,KAAK,YACZ,CAAC,GAAG,KAAK,WAAW,KAAK,QAAQ,IACjC,CAAC,KAAK,QAAQ;AAAA,QAClB,OAAO;AAAA,QACP,YAAY,OAAO;AAAA,QACnB,YAAY;AAAA;AAAA,QACZ,QAAQ,eAAe,cAAc,aAAa,MAAM,IAAI;AAAA,QAC5D,YAAY,cAAc;AAAA,QAC1B,OAAO,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