|
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 json_exports = {}; |
|
f7eb47b…
|
lmata
|
30 |
__export(json_exports, { |
|
f7eb47b…
|
lmata
|
31 |
default: () => json_default, |
|
f7eb47b…
|
lmata
|
32 |
serializePatterns: () => serializePatterns |
|
f7eb47b…
|
lmata
|
33 |
}); |
|
f7eb47b…
|
lmata
|
34 |
module.exports = __toCommonJS(json_exports); |
|
f7eb47b…
|
lmata
|
35 |
var import_fs = __toESM(require("fs")); |
|
f7eb47b…
|
lmata
|
36 |
var import_path = __toESM(require("path")); |
|
f7eb47b…
|
lmata
|
37 |
var import_utils = require("playwright-core/lib/utils"); |
|
f7eb47b…
|
lmata
|
38 |
var import_base = require("./base"); |
|
f7eb47b…
|
lmata
|
39 |
var import_config = require("../common/config"); |
|
f7eb47b…
|
lmata
|
40 |
class JSONReporter { |
|
f7eb47b…
|
lmata
|
41 |
constructor(options) { |
|
f7eb47b…
|
lmata
|
42 |
this._errors = []; |
|
f7eb47b…
|
lmata
|
43 |
this._resolvedOutputFile = (0, import_base.resolveOutputFile)("JSON", options)?.outputFile; |
|
f7eb47b…
|
lmata
|
44 |
} |
|
f7eb47b…
|
lmata
|
45 |
version() { |
|
f7eb47b…
|
lmata
|
46 |
return "v2"; |
|
f7eb47b…
|
lmata
|
47 |
} |
|
f7eb47b…
|
lmata
|
48 |
printsToStdio() { |
|
f7eb47b…
|
lmata
|
49 |
return !this._resolvedOutputFile; |
|
f7eb47b…
|
lmata
|
50 |
} |
|
f7eb47b…
|
lmata
|
51 |
onConfigure(config) { |
|
f7eb47b…
|
lmata
|
52 |
this.config = config; |
|
f7eb47b…
|
lmata
|
53 |
} |
|
f7eb47b…
|
lmata
|
54 |
onBegin(suite) { |
|
f7eb47b…
|
lmata
|
55 |
this.suite = suite; |
|
f7eb47b…
|
lmata
|
56 |
} |
|
f7eb47b…
|
lmata
|
57 |
onError(error) { |
|
f7eb47b…
|
lmata
|
58 |
this._errors.push(error); |
|
f7eb47b…
|
lmata
|
59 |
} |
|
f7eb47b…
|
lmata
|
60 |
async onEnd(result) { |
|
f7eb47b…
|
lmata
|
61 |
await outputReport(this._serializeReport(result), this._resolvedOutputFile); |
|
f7eb47b…
|
lmata
|
62 |
} |
|
f7eb47b…
|
lmata
|
63 |
_serializeReport(result) { |
|
f7eb47b…
|
lmata
|
64 |
const report = { |
|
f7eb47b…
|
lmata
|
65 |
config: { |
|
f7eb47b…
|
lmata
|
66 |
...removePrivateFields(this.config), |
|
f7eb47b…
|
lmata
|
67 |
rootDir: (0, import_utils.toPosixPath)(this.config.rootDir), |
|
f7eb47b…
|
lmata
|
68 |
projects: this.config.projects.map((project) => { |
|
f7eb47b…
|
lmata
|
69 |
return { |
|
f7eb47b…
|
lmata
|
70 |
outputDir: (0, import_utils.toPosixPath)(project.outputDir), |
|
f7eb47b…
|
lmata
|
71 |
repeatEach: project.repeatEach, |
|
f7eb47b…
|
lmata
|
72 |
retries: project.retries, |
|
f7eb47b…
|
lmata
|
73 |
metadata: project.metadata, |
|
f7eb47b…
|
lmata
|
74 |
id: (0, import_config.getProjectId)(project), |
|
f7eb47b…
|
lmata
|
75 |
name: project.name, |
|
f7eb47b…
|
lmata
|
76 |
testDir: (0, import_utils.toPosixPath)(project.testDir), |
|
f7eb47b…
|
lmata
|
77 |
testIgnore: serializePatterns(project.testIgnore), |
|
f7eb47b…
|
lmata
|
78 |
testMatch: serializePatterns(project.testMatch), |
|
f7eb47b…
|
lmata
|
79 |
timeout: project.timeout |
|
f7eb47b…
|
lmata
|
80 |
}; |
|
f7eb47b…
|
lmata
|
81 |
}) |
|
f7eb47b…
|
lmata
|
82 |
}, |
|
f7eb47b…
|
lmata
|
83 |
suites: this._mergeSuites(this.suite.suites), |
|
f7eb47b…
|
lmata
|
84 |
errors: this._errors, |
|
f7eb47b…
|
lmata
|
85 |
stats: { |
|
f7eb47b…
|
lmata
|
86 |
startTime: result.startTime.toISOString(), |
|
f7eb47b…
|
lmata
|
87 |
duration: result.duration, |
|
f7eb47b…
|
lmata
|
88 |
expected: 0, |
|
f7eb47b…
|
lmata
|
89 |
skipped: 0, |
|
f7eb47b…
|
lmata
|
90 |
unexpected: 0, |
|
f7eb47b…
|
lmata
|
91 |
flaky: 0 |
|
f7eb47b…
|
lmata
|
92 |
} |
|
f7eb47b…
|
lmata
|
93 |
}; |
|
f7eb47b…
|
lmata
|
94 |
for (const test of this.suite.allTests()) |
|
f7eb47b…
|
lmata
|
95 |
++report.stats[test.outcome()]; |
|
f7eb47b…
|
lmata
|
96 |
return report; |
|
f7eb47b…
|
lmata
|
97 |
} |
|
f7eb47b…
|
lmata
|
98 |
_mergeSuites(suites) { |
|
f7eb47b…
|
lmata
|
99 |
const fileSuites = new import_utils.MultiMap(); |
|
f7eb47b…
|
lmata
|
100 |
for (const projectSuite of suites) { |
|
f7eb47b…
|
lmata
|
101 |
const projectId = (0, import_config.getProjectId)(projectSuite.project()); |
|
f7eb47b…
|
lmata
|
102 |
const projectName = projectSuite.project().name; |
|
f7eb47b…
|
lmata
|
103 |
for (const fileSuite of projectSuite.suites) { |
|
f7eb47b…
|
lmata
|
104 |
const file = fileSuite.location.file; |
|
f7eb47b…
|
lmata
|
105 |
const serialized = this._serializeSuite(projectId, projectName, fileSuite); |
|
f7eb47b…
|
lmata
|
106 |
if (serialized) |
|
f7eb47b…
|
lmata
|
107 |
fileSuites.set(file, serialized); |
|
f7eb47b…
|
lmata
|
108 |
} |
|
f7eb47b…
|
lmata
|
109 |
} |
|
f7eb47b…
|
lmata
|
110 |
const results = []; |
|
f7eb47b…
|
lmata
|
111 |
for (const [, suites2] of fileSuites) { |
|
f7eb47b…
|
lmata
|
112 |
const result = { |
|
f7eb47b…
|
lmata
|
113 |
title: suites2[0].title, |
|
f7eb47b…
|
lmata
|
114 |
file: suites2[0].file, |
|
f7eb47b…
|
lmata
|
115 |
column: 0, |
|
f7eb47b…
|
lmata
|
116 |
line: 0, |
|
f7eb47b…
|
lmata
|
117 |
specs: [] |
|
f7eb47b…
|
lmata
|
118 |
}; |
|
f7eb47b…
|
lmata
|
119 |
for (const suite of suites2) |
|
f7eb47b…
|
lmata
|
120 |
this._mergeTestsFromSuite(result, suite); |
|
f7eb47b…
|
lmata
|
121 |
results.push(result); |
|
f7eb47b…
|
lmata
|
122 |
} |
|
f7eb47b…
|
lmata
|
123 |
return results; |
|
f7eb47b…
|
lmata
|
124 |
} |
|
f7eb47b…
|
lmata
|
125 |
_relativeLocation(location) { |
|
f7eb47b…
|
lmata
|
126 |
if (!location) |
|
f7eb47b…
|
lmata
|
127 |
return { file: "", line: 0, column: 0 }; |
|
f7eb47b…
|
lmata
|
128 |
return { |
|
f7eb47b…
|
lmata
|
129 |
file: (0, import_utils.toPosixPath)(import_path.default.relative(this.config.rootDir, location.file)), |
|
f7eb47b…
|
lmata
|
130 |
line: location.line, |
|
f7eb47b…
|
lmata
|
131 |
column: location.column |
|
f7eb47b…
|
lmata
|
132 |
}; |
|
f7eb47b…
|
lmata
|
133 |
} |
|
f7eb47b…
|
lmata
|
134 |
_locationMatches(s1, s2) { |
|
f7eb47b…
|
lmata
|
135 |
return s1.file === s2.file && s1.line === s2.line && s1.column === s2.column; |
|
f7eb47b…
|
lmata
|
136 |
} |
|
f7eb47b…
|
lmata
|
137 |
_mergeTestsFromSuite(to, from) { |
|
f7eb47b…
|
lmata
|
138 |
for (const fromSuite of from.suites || []) { |
|
f7eb47b…
|
lmata
|
139 |
const toSuite = (to.suites || []).find((s) => s.title === fromSuite.title && this._locationMatches(s, fromSuite)); |
|
f7eb47b…
|
lmata
|
140 |
if (toSuite) { |
|
f7eb47b…
|
lmata
|
141 |
this._mergeTestsFromSuite(toSuite, fromSuite); |
|
f7eb47b…
|
lmata
|
142 |
} else { |
|
f7eb47b…
|
lmata
|
143 |
if (!to.suites) |
|
f7eb47b…
|
lmata
|
144 |
to.suites = []; |
|
f7eb47b…
|
lmata
|
145 |
to.suites.push(fromSuite); |
|
f7eb47b…
|
lmata
|
146 |
} |
|
f7eb47b…
|
lmata
|
147 |
} |
|
f7eb47b…
|
lmata
|
148 |
for (const spec of from.specs || []) { |
|
f7eb47b…
|
lmata
|
149 |
const toSpec = to.specs.find((s) => s.title === spec.title && s.file === (0, import_utils.toPosixPath)(import_path.default.relative(this.config.rootDir, spec.file)) && s.line === spec.line && s.column === spec.column); |
|
f7eb47b…
|
lmata
|
150 |
if (toSpec) |
|
f7eb47b…
|
lmata
|
151 |
toSpec.tests.push(...spec.tests); |
|
f7eb47b…
|
lmata
|
152 |
else |
|
f7eb47b…
|
lmata
|
153 |
to.specs.push(spec); |
|
f7eb47b…
|
lmata
|
154 |
} |
|
f7eb47b…
|
lmata
|
155 |
} |
|
f7eb47b…
|
lmata
|
156 |
_serializeSuite(projectId, projectName, suite) { |
|
f7eb47b…
|
lmata
|
157 |
if (!suite.allTests().length) |
|
f7eb47b…
|
lmata
|
158 |
return null; |
|
f7eb47b…
|
lmata
|
159 |
const suites = suite.suites.map((suite2) => this._serializeSuite(projectId, projectName, suite2)).filter((s) => s); |
|
f7eb47b…
|
lmata
|
160 |
return { |
|
f7eb47b…
|
lmata
|
161 |
title: suite.title, |
|
f7eb47b…
|
lmata
|
162 |
...this._relativeLocation(suite.location), |
|
f7eb47b…
|
lmata
|
163 |
specs: suite.tests.map((test) => this._serializeTestSpec(projectId, projectName, test)), |
|
f7eb47b…
|
lmata
|
164 |
suites: suites.length ? suites : void 0 |
|
f7eb47b…
|
lmata
|
165 |
}; |
|
f7eb47b…
|
lmata
|
166 |
} |
|
f7eb47b…
|
lmata
|
167 |
_serializeTestSpec(projectId, projectName, test) { |
|
f7eb47b…
|
lmata
|
168 |
return { |
|
f7eb47b…
|
lmata
|
169 |
title: test.title, |
|
f7eb47b…
|
lmata
|
170 |
ok: test.ok(), |
|
f7eb47b…
|
lmata
|
171 |
tags: test.tags.map((tag) => tag.substring(1)), |
|
f7eb47b…
|
lmata
|
172 |
// Strip '@'. |
|
f7eb47b…
|
lmata
|
173 |
tests: [this._serializeTest(projectId, projectName, test)], |
|
f7eb47b…
|
lmata
|
174 |
id: test.id, |
|
f7eb47b…
|
lmata
|
175 |
...this._relativeLocation(test.location) |
|
f7eb47b…
|
lmata
|
176 |
}; |
|
f7eb47b…
|
lmata
|
177 |
} |
|
f7eb47b…
|
lmata
|
178 |
_serializeTest(projectId, projectName, test) { |
|
f7eb47b…
|
lmata
|
179 |
return { |
|
f7eb47b…
|
lmata
|
180 |
timeout: test.timeout, |
|
f7eb47b…
|
lmata
|
181 |
annotations: test.annotations, |
|
f7eb47b…
|
lmata
|
182 |
expectedStatus: test.expectedStatus, |
|
f7eb47b…
|
lmata
|
183 |
projectId, |
|
f7eb47b…
|
lmata
|
184 |
projectName, |
|
f7eb47b…
|
lmata
|
185 |
results: test.results.map((r) => this._serializeTestResult(r, test)), |
|
f7eb47b…
|
lmata
|
186 |
status: test.outcome() |
|
f7eb47b…
|
lmata
|
187 |
}; |
|
f7eb47b…
|
lmata
|
188 |
} |
|
f7eb47b…
|
lmata
|
189 |
_serializeTestResult(result, test) { |
|
f7eb47b…
|
lmata
|
190 |
const steps = result.steps.filter((s) => s.category === "test.step"); |
|
f7eb47b…
|
lmata
|
191 |
const jsonResult = { |
|
f7eb47b…
|
lmata
|
192 |
workerIndex: result.workerIndex, |
|
f7eb47b…
|
lmata
|
193 |
parallelIndex: result.parallelIndex, |
|
f7eb47b…
|
lmata
|
194 |
status: result.status, |
|
f7eb47b…
|
lmata
|
195 |
duration: result.duration, |
|
f7eb47b…
|
lmata
|
196 |
error: result.error, |
|
f7eb47b…
|
lmata
|
197 |
errors: result.errors.map((e) => this._serializeError(e)), |
|
f7eb47b…
|
lmata
|
198 |
stdout: result.stdout.map((s) => stdioEntry(s)), |
|
f7eb47b…
|
lmata
|
199 |
stderr: result.stderr.map((s) => stdioEntry(s)), |
|
f7eb47b…
|
lmata
|
200 |
retry: result.retry, |
|
f7eb47b…
|
lmata
|
201 |
steps: steps.length ? steps.map((s) => this._serializeTestStep(s)) : void 0, |
|
f7eb47b…
|
lmata
|
202 |
startTime: result.startTime.toISOString(), |
|
f7eb47b…
|
lmata
|
203 |
annotations: result.annotations, |
|
f7eb47b…
|
lmata
|
204 |
attachments: result.attachments.map((a) => ({ |
|
f7eb47b…
|
lmata
|
205 |
name: a.name, |
|
f7eb47b…
|
lmata
|
206 |
contentType: a.contentType, |
|
f7eb47b…
|
lmata
|
207 |
path: a.path, |
|
f7eb47b…
|
lmata
|
208 |
body: a.body?.toString("base64") |
|
f7eb47b…
|
lmata
|
209 |
})) |
|
f7eb47b…
|
lmata
|
210 |
}; |
|
f7eb47b…
|
lmata
|
211 |
if (result.error?.stack) |
|
f7eb47b…
|
lmata
|
212 |
jsonResult.errorLocation = (0, import_base.prepareErrorStack)(result.error.stack).location; |
|
f7eb47b…
|
lmata
|
213 |
return jsonResult; |
|
f7eb47b…
|
lmata
|
214 |
} |
|
f7eb47b…
|
lmata
|
215 |
_serializeError(error) { |
|
f7eb47b…
|
lmata
|
216 |
return (0, import_base.formatError)(import_base.nonTerminalScreen, error); |
|
f7eb47b…
|
lmata
|
217 |
} |
|
f7eb47b…
|
lmata
|
218 |
_serializeTestStep(step) { |
|
f7eb47b…
|
lmata
|
219 |
const steps = step.steps.filter((s) => s.category === "test.step"); |
|
f7eb47b…
|
lmata
|
220 |
return { |
|
f7eb47b…
|
lmata
|
221 |
title: step.title, |
|
f7eb47b…
|
lmata
|
222 |
duration: step.duration, |
|
f7eb47b…
|
lmata
|
223 |
error: step.error, |
|
f7eb47b…
|
lmata
|
224 |
steps: steps.length ? steps.map((s) => this._serializeTestStep(s)) : void 0 |
|
f7eb47b…
|
lmata
|
225 |
}; |
|
f7eb47b…
|
lmata
|
226 |
} |
|
f7eb47b…
|
lmata
|
227 |
} |
|
f7eb47b…
|
lmata
|
228 |
async function outputReport(report, resolvedOutputFile) { |
|
f7eb47b…
|
lmata
|
229 |
const reportString = JSON.stringify(report, void 0, 2); |
|
f7eb47b…
|
lmata
|
230 |
if (resolvedOutputFile) { |
|
f7eb47b…
|
lmata
|
231 |
await import_fs.default.promises.mkdir(import_path.default.dirname(resolvedOutputFile), { recursive: true }); |
|
f7eb47b…
|
lmata
|
232 |
await import_fs.default.promises.writeFile(resolvedOutputFile, reportString); |
|
f7eb47b…
|
lmata
|
233 |
} else { |
|
f7eb47b…
|
lmata
|
234 |
console.log(reportString); |
|
f7eb47b…
|
lmata
|
235 |
} |
|
f7eb47b…
|
lmata
|
236 |
} |
|
f7eb47b…
|
lmata
|
237 |
function stdioEntry(s) { |
|
f7eb47b…
|
lmata
|
238 |
if (typeof s === "string") |
|
f7eb47b…
|
lmata
|
239 |
return { text: s }; |
|
f7eb47b…
|
lmata
|
240 |
return { buffer: s.toString("base64") }; |
|
f7eb47b…
|
lmata
|
241 |
} |
|
f7eb47b…
|
lmata
|
242 |
function removePrivateFields(config) { |
|
f7eb47b…
|
lmata
|
243 |
return Object.fromEntries(Object.entries(config).filter(([name, value]) => !name.startsWith("_"))); |
|
f7eb47b…
|
lmata
|
244 |
} |
|
f7eb47b…
|
lmata
|
245 |
function serializePatterns(patterns) { |
|
f7eb47b…
|
lmata
|
246 |
if (!Array.isArray(patterns)) |
|
f7eb47b…
|
lmata
|
247 |
patterns = [patterns]; |
|
f7eb47b…
|
lmata
|
248 |
return patterns.map((s) => s.toString()); |
|
f7eb47b…
|
lmata
|
249 |
} |
|
f7eb47b…
|
lmata
|
250 |
var json_default = JSONReporter; |
|
f7eb47b…
|
lmata
|
251 |
// Annotate the CommonJS export names for ESM import in node: |
|
f7eb47b…
|
lmata
|
252 |
0 && (module.exports = { |
|
f7eb47b…
|
lmata
|
253 |
serializePatterns |
|
f7eb47b…
|
lmata
|
254 |
}); |