@planitro/playwright-reporter 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +176 -2
- package/dist/core/src/automationId.d.ts +39 -0
- package/dist/core/src/automationId.js +102 -0
- package/dist/core/src/ci.d.ts +21 -0
- package/dist/core/src/ci.js +143 -0
- package/dist/core/src/http.d.ts +116 -0
- package/dist/core/src/http.js +270 -0
- package/dist/core/src/playwrightJson.d.ts +74 -0
- package/dist/core/src/playwrightJson.js +92 -0
- package/dist/core/src/results.d.ts +69 -0
- package/dist/core/src/results.js +159 -0
- package/dist/core/src/sender.d.ts +45 -0
- package/dist/core/src/sender.js +145 -0
- package/dist/core/src/steps.d.ts +48 -0
- package/dist/core/src/steps.js +482 -0
- package/dist/playwright-reporter/src/index.d.ts +95 -0
- package/dist/playwright-reporter/src/index.js +269 -0
- package/package.json +41 -4
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SerialQueue = exports.PlanitroClient = exports.PlanitroError = exports.consoleLogger = void 0;
|
|
37
|
+
exports.normalizeBaseUrl = normalizeBaseUrl;
|
|
38
|
+
exports.isInsecureUrl = isInsecureUrl;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const results_1 = require("./results");
|
|
42
|
+
exports.consoleLogger = {
|
|
43
|
+
info: (m) => console.log(`Planitro: ${m}`),
|
|
44
|
+
warn: (m) => console.warn(`Planitro: ${m}`),
|
|
45
|
+
debug: (m) => {
|
|
46
|
+
if (process.env.PLANITRO_DEBUG)
|
|
47
|
+
console.log(`Planitro [debug]: ${m}`);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
class PlanitroError extends Error {
|
|
51
|
+
constructor(message, status, code) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.status = status;
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.name = "PlanitroError";
|
|
56
|
+
}
|
|
57
|
+
/** Auth / plan / permission problems: retrying or sending more will not help. */
|
|
58
|
+
get fatal() {
|
|
59
|
+
return this.status === 401 || this.status === 402 || this.status === 403 || this.code === "redirect";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.PlanitroError = PlanitroError;
|
|
63
|
+
/** Accepts `https://planitro.app`, `https://planitro.app/`, `…/api/v1` or `…/api/v1/tests`. */
|
|
64
|
+
function normalizeBaseUrl(url) {
|
|
65
|
+
return url
|
|
66
|
+
.trim()
|
|
67
|
+
.replace(/\/+$/, "")
|
|
68
|
+
.replace(/\/api\/v1(\/tests)?$/, "");
|
|
69
|
+
}
|
|
70
|
+
/** True for plain-http URLs that are not on this machine (the key would travel unencrypted). */
|
|
71
|
+
function isInsecureUrl(url) {
|
|
72
|
+
try {
|
|
73
|
+
const u = new URL(url);
|
|
74
|
+
return u.protocol === "http:" && !["localhost", "127.0.0.1", "[::1]", "::1"].includes(u.hostname);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
81
|
+
/** HTTP client for the public `/api/v1/tests` API. Uses Node 18+ global fetch/FormData/Blob; zero deps. */
|
|
82
|
+
class PlanitroClient {
|
|
83
|
+
constructor(opts) {
|
|
84
|
+
this.baseUrl = normalizeBaseUrl(opts.url);
|
|
85
|
+
this.apiKey = opts.apiKey;
|
|
86
|
+
this.retries = opts.retries ?? 3;
|
|
87
|
+
this.backoffMs = opts.backoffMs ?? 500;
|
|
88
|
+
this.timeoutMs = opts.timeoutMs ?? 30_000;
|
|
89
|
+
this.userAgent = opts.userAgent ?? "planitro-client";
|
|
90
|
+
if (isInsecureUrl(this.baseUrl)) {
|
|
91
|
+
console.warn(`Planitro: ${this.baseUrl} is not https, so your API key is sent unencrypted. Use an https:// URL.`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** Makes a request, retrying transient failures. Throws PlanitroError (never includes the API key). */
|
|
95
|
+
async request(method, apiPath, body, timeoutMs = this.timeoutMs) {
|
|
96
|
+
const url = `${this.baseUrl}/api/v1/tests${apiPath}`;
|
|
97
|
+
let lastErr;
|
|
98
|
+
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
|
99
|
+
if (attempt > 0) {
|
|
100
|
+
const retryAfter = lastErr?.retryAfterMs;
|
|
101
|
+
await sleep(retryAfter ?? this.backoffMs * 2 ** (attempt - 1));
|
|
102
|
+
}
|
|
103
|
+
const headers = {
|
|
104
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
105
|
+
Accept: "application/json",
|
|
106
|
+
"User-Agent": this.userAgent,
|
|
107
|
+
};
|
|
108
|
+
let payload;
|
|
109
|
+
if (body?.json !== undefined) {
|
|
110
|
+
headers["Content-Type"] = "application/json";
|
|
111
|
+
payload = JSON.stringify(body.json);
|
|
112
|
+
}
|
|
113
|
+
else if (body?.form) {
|
|
114
|
+
payload = body.form(); // rebuilt per attempt: a FormData body can be consumed only once
|
|
115
|
+
}
|
|
116
|
+
let res;
|
|
117
|
+
try {
|
|
118
|
+
// Never follow redirects: the API key must only go to the configured host
|
|
119
|
+
res = await fetch(url, { method, headers, body: payload, redirect: "manual", signal: AbortSignal.timeout(timeoutMs) });
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
const err = e;
|
|
123
|
+
const reason = err.name === "TimeoutError" ? `timed out after ${timeoutMs} ms` : err.cause?.code || err.message;
|
|
124
|
+
lastErr = new PlanitroError(`${method} ${apiPath} failed: ${reason}`);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (res.status >= 300 && res.status < 400) {
|
|
128
|
+
const to = res.headers.get("location");
|
|
129
|
+
throw new PlanitroError(`${method} ${apiPath} → ${res.status}: the Planitro URL redirects${to ? ` to ${to}` : ""}; set PLANITRO_URL to the final address`, res.status, "redirect");
|
|
130
|
+
}
|
|
131
|
+
const text = await res.text().catch(() => "");
|
|
132
|
+
if (res.ok) {
|
|
133
|
+
if (!text)
|
|
134
|
+
return undefined;
|
|
135
|
+
try {
|
|
136
|
+
return JSON.parse(text);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
throw new PlanitroError(`${method} ${apiPath}: invalid JSON response`, res.status);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
let message = text.slice(0, 300) || res.statusText;
|
|
143
|
+
let code;
|
|
144
|
+
try {
|
|
145
|
+
const j = JSON.parse(text);
|
|
146
|
+
if (j && typeof j.error === "string")
|
|
147
|
+
message = j.error;
|
|
148
|
+
if (j && typeof j.code === "string")
|
|
149
|
+
code = j.code;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
/* not JSON */
|
|
153
|
+
}
|
|
154
|
+
const err = new PlanitroError(`${method} ${apiPath} → ${res.status}: ${message}`, res.status, code);
|
|
155
|
+
if (res.status === 429 || res.status >= 500) {
|
|
156
|
+
const ra = Number(res.headers.get("retry-after"));
|
|
157
|
+
if (Number.isFinite(ra) && ra > 0) {
|
|
158
|
+
err.retryAfterMs = Math.min(ra * 1000, 30_000);
|
|
159
|
+
}
|
|
160
|
+
lastErr = err;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
throw err;
|
|
164
|
+
}
|
|
165
|
+
throw lastErr ?? new PlanitroError(`${method} ${apiPath} failed`);
|
|
166
|
+
}
|
|
167
|
+
project() {
|
|
168
|
+
return this.request("GET", "/project");
|
|
169
|
+
}
|
|
170
|
+
createRun(body) {
|
|
171
|
+
return this.request("POST", "/runs", { json: dropEmpty(body) });
|
|
172
|
+
}
|
|
173
|
+
postResults(runId, results, autoCreate) {
|
|
174
|
+
return this.request("POST", `/runs/${encodeURIComponent(String(runId))}/results`, {
|
|
175
|
+
json: { auto_create: autoCreate, results },
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/** `timing` keeps the original end of a run that already happened (uploads/replays). */
|
|
179
|
+
completeRun(runId, timing) {
|
|
180
|
+
const json = timing ? dropEmpty({ duration_ms: timing.durationMs, completed_at: timing.completedAt }) : undefined;
|
|
181
|
+
return this.request("POST", `/runs/${encodeURIComponent(String(runId))}/complete`, json ? { json } : undefined);
|
|
182
|
+
}
|
|
183
|
+
/** Uploads one file. Returns false (without calling the server) when it is missing or larger than 50 MB. */
|
|
184
|
+
async uploadAttachment(runId, resultId, att, log) {
|
|
185
|
+
let size;
|
|
186
|
+
try {
|
|
187
|
+
const st = fs.statSync(att.path);
|
|
188
|
+
if (!st.isFile())
|
|
189
|
+
return false;
|
|
190
|
+
size = st.size;
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
log?.debug?.(`attachment not found, skipped: ${att.path}`);
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
if (size > results_1.MAX_ATTACHMENT_BYTES) {
|
|
197
|
+
log?.warn(`attachment ${path.basename(att.path)} is ${(size / 1048576).toFixed(1)} MB (> 50 MB), skipped`);
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
const data = fs.readFileSync(att.path);
|
|
201
|
+
const fileName = fileNameFor(att);
|
|
202
|
+
await this.request("POST", `/runs/${encodeURIComponent(String(runId))}/results/${encodeURIComponent(String(resultId))}/attachments`, {
|
|
203
|
+
form: () => {
|
|
204
|
+
const fd = new FormData();
|
|
205
|
+
fd.append("file", new Blob([data], { type: att.contentType || "application/octet-stream" }), fileName);
|
|
206
|
+
return fd;
|
|
207
|
+
},
|
|
208
|
+
}, Math.max(this.timeoutMs, 120_000));
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
/** `POST /runs/junit` — files are read up front; the server creates and completes the run. */
|
|
212
|
+
uploadJunit(files, fields) {
|
|
213
|
+
const contents = files.map((f) => ({ name: path.basename(f), data: fs.readFileSync(f) }));
|
|
214
|
+
return this.request("POST", "/runs/junit", {
|
|
215
|
+
form: () => {
|
|
216
|
+
const fd = new FormData();
|
|
217
|
+
for (const [k, val] of Object.entries(fields)) {
|
|
218
|
+
if (val === undefined || val === "")
|
|
219
|
+
continue;
|
|
220
|
+
fd.append(k, String(val));
|
|
221
|
+
}
|
|
222
|
+
for (const c of contents)
|
|
223
|
+
fd.append("files", new Blob([c.data], { type: "application/xml" }), c.name);
|
|
224
|
+
return fd;
|
|
225
|
+
},
|
|
226
|
+
}, Math.max(this.timeoutMs, 120_000));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.PlanitroClient = PlanitroClient;
|
|
230
|
+
function dropEmpty(o) {
|
|
231
|
+
const out = {};
|
|
232
|
+
for (const [k, val] of Object.entries(o))
|
|
233
|
+
if (val !== undefined && val !== null && val !== "")
|
|
234
|
+
out[k] = val;
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
/** A readable, unique-ish filename: Playwright names attachments "screenshot", "trace", "video" without extension. */
|
|
238
|
+
function fileNameFor(att) {
|
|
239
|
+
const base = path.basename(att.path);
|
|
240
|
+
if (att.name && !/^(screenshot|trace|video)$/.test(att.name) && path.extname(att.name))
|
|
241
|
+
return att.name;
|
|
242
|
+
return base;
|
|
243
|
+
}
|
|
244
|
+
/** Runs async jobs one after another; never rejects. Used to keep result posts ordered. */
|
|
245
|
+
class SerialQueue {
|
|
246
|
+
constructor() {
|
|
247
|
+
this.tail = Promise.resolve();
|
|
248
|
+
this.pending = 0;
|
|
249
|
+
}
|
|
250
|
+
push(job) {
|
|
251
|
+
this.pending++;
|
|
252
|
+
const p = this.tail.then(job).catch(() => undefined).finally(() => {
|
|
253
|
+
this.pending--;
|
|
254
|
+
});
|
|
255
|
+
this.tail = p;
|
|
256
|
+
return p;
|
|
257
|
+
}
|
|
258
|
+
get size() {
|
|
259
|
+
return this.pending;
|
|
260
|
+
}
|
|
261
|
+
/** Resolves when everything queued so far (and anything queued while waiting) is done. */
|
|
262
|
+
async idle() {
|
|
263
|
+
let t;
|
|
264
|
+
do {
|
|
265
|
+
t = this.tail;
|
|
266
|
+
await t;
|
|
267
|
+
} while (t !== this.tail);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.SerialQueue = SerialQueue;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AttachmentMode, PendingResult } from "./results";
|
|
2
|
+
/** The parts of Playwright's JSON reporter output (`--reporter=json`) we read. */
|
|
3
|
+
export interface JsonReport {
|
|
4
|
+
config?: {
|
|
5
|
+
rootDir?: string;
|
|
6
|
+
projects?: Array<{
|
|
7
|
+
name?: string;
|
|
8
|
+
testDir?: string;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
suites?: JsonSuite[];
|
|
12
|
+
/** When the run started (ISO) and how long it took in ms; present in Playwright >= 1.30. */
|
|
13
|
+
stats?: {
|
|
14
|
+
startTime?: string;
|
|
15
|
+
duration?: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface JsonSuite {
|
|
19
|
+
title: string;
|
|
20
|
+
file?: string;
|
|
21
|
+
specs?: JsonSpec[];
|
|
22
|
+
suites?: JsonSuite[];
|
|
23
|
+
}
|
|
24
|
+
interface JsonSpec {
|
|
25
|
+
title: string;
|
|
26
|
+
file?: string;
|
|
27
|
+
tags?: string[];
|
|
28
|
+
tests?: JsonTest[];
|
|
29
|
+
}
|
|
30
|
+
interface JsonTest {
|
|
31
|
+
projectName?: string;
|
|
32
|
+
status?: string;
|
|
33
|
+
results?: JsonResult[];
|
|
34
|
+
}
|
|
35
|
+
interface JsonResult {
|
|
36
|
+
status?: string;
|
|
37
|
+
retry?: number;
|
|
38
|
+
duration?: number;
|
|
39
|
+
error?: {
|
|
40
|
+
message?: string;
|
|
41
|
+
stack?: string;
|
|
42
|
+
};
|
|
43
|
+
errors?: Array<{
|
|
44
|
+
message?: string;
|
|
45
|
+
stack?: string;
|
|
46
|
+
}>;
|
|
47
|
+
attachments?: Array<{
|
|
48
|
+
name: string;
|
|
49
|
+
contentType: string;
|
|
50
|
+
path?: string;
|
|
51
|
+
}>;
|
|
52
|
+
/** Only `test.step` steps (the JSON reporter drops actions and assertions). */
|
|
53
|
+
steps?: JsonStep[];
|
|
54
|
+
}
|
|
55
|
+
interface JsonStep {
|
|
56
|
+
title: string;
|
|
57
|
+
steps?: JsonStep[];
|
|
58
|
+
}
|
|
59
|
+
export declare function isPlaywrightJsonReport(v: unknown): v is JsonReport;
|
|
60
|
+
/**
|
|
61
|
+
* Converts a Playwright JSON report into Planitro results using the same automation_id rules as the reporter:
|
|
62
|
+
* file relative to the project's testDir, describe titles, test title, case tags stripped, no project name.
|
|
63
|
+
* Tests run by several projects collapse into one result (worst status wins).
|
|
64
|
+
*/
|
|
65
|
+
export declare function convertPlaywrightJson(report: JsonReport, attachmentMode?: AttachmentMode): PendingResult[];
|
|
66
|
+
/**
|
|
67
|
+
* Original start/duration of the runs in one or more reports: earliest start, and
|
|
68
|
+
* the span up to the latest end. Undefined when no report has stats.
|
|
69
|
+
*/
|
|
70
|
+
export declare function reportTiming(reports: JsonReport[]): {
|
|
71
|
+
startedAt: string;
|
|
72
|
+
durationMs: number;
|
|
73
|
+
} | undefined;
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPlaywrightJsonReport = isPlaywrightJsonReport;
|
|
4
|
+
exports.convertPlaywrightJson = convertPlaywrightJson;
|
|
5
|
+
exports.reportTiming = reportTiming;
|
|
6
|
+
const automationId_1 = require("./automationId");
|
|
7
|
+
const steps_1 = require("./steps");
|
|
8
|
+
const results_1 = require("./results");
|
|
9
|
+
function isPlaywrightJsonReport(v) {
|
|
10
|
+
return !!v && typeof v === "object" && Array.isArray(v.suites) && "config" in v;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Converts a Playwright JSON report into Planitro results using the same automation_id rules as the reporter:
|
|
14
|
+
* file relative to the project's testDir, describe titles, test title, case tags stripped, no project name.
|
|
15
|
+
* Tests run by several projects collapse into one result (worst status wins).
|
|
16
|
+
*/
|
|
17
|
+
function convertPlaywrightJson(report, attachmentMode = "failures") {
|
|
18
|
+
const rootDir = report.config?.rootDir ?? "";
|
|
19
|
+
const testDirs = new Map();
|
|
20
|
+
for (const p of report.config?.projects ?? []) {
|
|
21
|
+
if (p.testDir)
|
|
22
|
+
testDirs.set(p.name ?? "", p.testDir);
|
|
23
|
+
}
|
|
24
|
+
const dedup = new results_1.ResultDeduper();
|
|
25
|
+
const visit = (suite, describes, fileFromRoot) => {
|
|
26
|
+
for (const spec of suite.specs ?? []) {
|
|
27
|
+
const specFile = (0, automationId_1.toPosixPath)(spec.file || fileFromRoot);
|
|
28
|
+
for (const t of spec.tests ?? []) {
|
|
29
|
+
const results = t.results ?? [];
|
|
30
|
+
const last = results[results.length - 1];
|
|
31
|
+
// The JSON report gives files relative to rootDir; automation_id wants them relative to the project's testDir.
|
|
32
|
+
const testDir = testDirs.get(t.projectName ?? "");
|
|
33
|
+
let rel = specFile;
|
|
34
|
+
if (rootDir && testDir) {
|
|
35
|
+
const abs = (rootDir.startsWith("/") ? "/" : "") + (0, automationId_1.joinPosix)(rootDir, specFile);
|
|
36
|
+
rel = (0, automationId_1.relativePosix)(abs, testDir);
|
|
37
|
+
}
|
|
38
|
+
const ids = (0, automationId_1.buildPlaywrightId)(rel, describes, spec.title);
|
|
39
|
+
const status = t.status ? (0, results_1.mapOutcome)(t.status) : last ? (0, results_1.mapPlaywrightStatus)(last.status ?? "failed") : "skipped";
|
|
40
|
+
const failed = status === "failed";
|
|
41
|
+
const errMessage = failed ? last?.error?.message ?? last?.errors?.[0]?.message : undefined;
|
|
42
|
+
const errStack = failed ? last?.error?.stack ?? last?.errors?.[0]?.stack : undefined;
|
|
43
|
+
const payload = {
|
|
44
|
+
automation_id: ids.automationId,
|
|
45
|
+
title: ids.title,
|
|
46
|
+
suite_path: ids.suitePath,
|
|
47
|
+
status,
|
|
48
|
+
duration_ms: Math.max(0, Math.round(last?.duration ?? 0)),
|
|
49
|
+
retries: last?.retry ?? 0,
|
|
50
|
+
error_message: (0, results_1.truncate)(errMessage ?? null),
|
|
51
|
+
error_stack: (0, results_1.truncate)(errStack ?? null),
|
|
52
|
+
tags: (0, automationId_1.buildTags)(spec.tags, [...describes, spec.title]),
|
|
53
|
+
};
|
|
54
|
+
if (status === "passed") {
|
|
55
|
+
const cs = (0, steps_1.convertPlaywrightSteps)(last?.steps, { onlyTestSteps: true });
|
|
56
|
+
if (cs.steps.length > 0 || cs.expected.length > 0) {
|
|
57
|
+
payload.steps = cs.steps;
|
|
58
|
+
payload.expected = cs.expected;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
dedup.add({
|
|
62
|
+
payload,
|
|
63
|
+
attachments: (0, results_1.selectAttachments)(attachmentMode, status, last?.attachments ?? []),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const child of suite.suites ?? [])
|
|
68
|
+
visit(child, [...describes, child.title], fileFromRoot);
|
|
69
|
+
};
|
|
70
|
+
// Top-level suites are files; nested suites are describe blocks.
|
|
71
|
+
for (const fileSuite of report.suites ?? [])
|
|
72
|
+
visit(fileSuite, [], (0, automationId_1.toPosixPath)(fileSuite.file || fileSuite.title));
|
|
73
|
+
return dedup.values();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Original start/duration of the runs in one or more reports: earliest start, and
|
|
77
|
+
* the span up to the latest end. Undefined when no report has stats.
|
|
78
|
+
*/
|
|
79
|
+
function reportTiming(reports) {
|
|
80
|
+
let start = Infinity;
|
|
81
|
+
let end = -Infinity;
|
|
82
|
+
for (const r of reports) {
|
|
83
|
+
const t = r.stats?.startTime ? Date.parse(r.stats.startTime) : NaN;
|
|
84
|
+
if (!Number.isFinite(t))
|
|
85
|
+
continue;
|
|
86
|
+
start = Math.min(start, t);
|
|
87
|
+
end = Math.max(end, t + Math.max(0, Math.round(r.stats?.duration ?? 0)));
|
|
88
|
+
}
|
|
89
|
+
if (!Number.isFinite(start))
|
|
90
|
+
return undefined;
|
|
91
|
+
return { startedAt: new Date(start).toISOString(), durationMs: Math.max(0, end - start) };
|
|
92
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** One entry of `POST /api/v1/tests/runs/:runId/results`. */
|
|
2
|
+
export type ResultStatus = "passed" | "failed" | "skipped" | "blocked";
|
|
3
|
+
export interface ResultPayload {
|
|
4
|
+
automation_id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
suite_path: string[];
|
|
7
|
+
status: ResultStatus;
|
|
8
|
+
duration_ms: number;
|
|
9
|
+
retries: number;
|
|
10
|
+
error_message: string | null;
|
|
11
|
+
error_stack: string | null;
|
|
12
|
+
tags: string[];
|
|
13
|
+
/** Readable steps / expected results from the step tree (PTR-863); only sent for passed results. */
|
|
14
|
+
steps?: string[];
|
|
15
|
+
expected?: string[];
|
|
16
|
+
}
|
|
17
|
+
/** A file on disk to upload for a result once the server tells us its result_id. */
|
|
18
|
+
export interface LocalAttachment {
|
|
19
|
+
name: string;
|
|
20
|
+
path: string;
|
|
21
|
+
contentType: string;
|
|
22
|
+
}
|
|
23
|
+
/** A result plus the attachments that belong to it (attachments never go in the JSON body). */
|
|
24
|
+
export interface PendingResult {
|
|
25
|
+
payload: ResultPayload;
|
|
26
|
+
attachments: LocalAttachment[];
|
|
27
|
+
}
|
|
28
|
+
export type AttachmentMode = "failures" | "all" | "none";
|
|
29
|
+
/** Server truncates error_message / error_stack at 64 KB; trim client side too so requests stay small. */
|
|
30
|
+
export declare const MAX_ERROR_BYTES: number;
|
|
31
|
+
export declare const MAX_ATTACHMENT_BYTES: number;
|
|
32
|
+
/** Server accepts at most 500 results per request. */
|
|
33
|
+
export declare const MAX_BATCH = 500;
|
|
34
|
+
export declare function stripAnsi(s: string): string;
|
|
35
|
+
export declare function truncate(s: string | null | undefined, max?: number): string | null;
|
|
36
|
+
/** Playwright `TestResult.status` → Planitro status (used when the test outcome is not available). */
|
|
37
|
+
export declare function mapPlaywrightStatus(status: string): ResultStatus;
|
|
38
|
+
/**
|
|
39
|
+
* Playwright `TestCase.outcome()` (also `status` of a test in the JSON report) → Planitro status. This honours
|
|
40
|
+
* `test.fail()`: a test that is expected to fail and fails has outcome `expected`, i.e. passed.
|
|
41
|
+
*/
|
|
42
|
+
export declare function mapOutcome(outcome: string): ResultStatus;
|
|
43
|
+
/** Higher = worse. failed > blocked > passed > skipped. */
|
|
44
|
+
export declare function statusRank(s: ResultStatus): number;
|
|
45
|
+
/**
|
|
46
|
+
* Collapses results that share an automation_id (the same test run by several Playwright projects, e.g.
|
|
47
|
+
* chromium + firefox): the worst status wins (failed > passed > skipped). Returns true when `next` should
|
|
48
|
+
* replace `current` (strictly worse; on a tie the first one reported stays).
|
|
49
|
+
*/
|
|
50
|
+
export declare function shouldReplace(current: ResultPayload | undefined, next: ResultPayload): boolean;
|
|
51
|
+
/** In-memory dedup map used by both the reporter and the JSON converter. */
|
|
52
|
+
export declare class ResultDeduper {
|
|
53
|
+
private readonly map;
|
|
54
|
+
/** Adds or merges a result. Returns true when it was stored (new id, or worse than what we had). */
|
|
55
|
+
add(r: PendingResult): boolean;
|
|
56
|
+
get(id: string): PendingResult | undefined;
|
|
57
|
+
values(): PendingResult[];
|
|
58
|
+
get size(): number;
|
|
59
|
+
}
|
|
60
|
+
/** Picks which attachments to upload for a final result according to the mode. */
|
|
61
|
+
export declare function selectAttachments(mode: AttachmentMode, status: ResultStatus, attachments: ReadonlyArray<{
|
|
62
|
+
name: string;
|
|
63
|
+
path?: string;
|
|
64
|
+
contentType: string;
|
|
65
|
+
}>): LocalAttachment[];
|
|
66
|
+
export declare function parseAttachmentMode(v: unknown, fallback?: AttachmentMode): AttachmentMode;
|
|
67
|
+
export declare function parseBool(v: unknown, fallback: boolean): boolean;
|
|
68
|
+
/** Counts per status, for the final one-line summary. */
|
|
69
|
+
export declare function countStatuses(results: Iterable<ResultPayload>): Record<ResultStatus, number>;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResultDeduper = exports.MAX_BATCH = exports.MAX_ATTACHMENT_BYTES = exports.MAX_ERROR_BYTES = void 0;
|
|
4
|
+
exports.stripAnsi = stripAnsi;
|
|
5
|
+
exports.truncate = truncate;
|
|
6
|
+
exports.mapPlaywrightStatus = mapPlaywrightStatus;
|
|
7
|
+
exports.mapOutcome = mapOutcome;
|
|
8
|
+
exports.statusRank = statusRank;
|
|
9
|
+
exports.shouldReplace = shouldReplace;
|
|
10
|
+
exports.selectAttachments = selectAttachments;
|
|
11
|
+
exports.parseAttachmentMode = parseAttachmentMode;
|
|
12
|
+
exports.parseBool = parseBool;
|
|
13
|
+
exports.countStatuses = countStatuses;
|
|
14
|
+
/** Server truncates error_message / error_stack at 64 KB; trim client side too so requests stay small. */
|
|
15
|
+
exports.MAX_ERROR_BYTES = 64 * 1024;
|
|
16
|
+
exports.MAX_ATTACHMENT_BYTES = 50 * 1024 * 1024;
|
|
17
|
+
/** Server accepts at most 500 results per request. */
|
|
18
|
+
exports.MAX_BATCH = 500;
|
|
19
|
+
// eslint-disable-next-line no-control-regex
|
|
20
|
+
const ANSI_RE = /[\u001b\u009b][[\]()#;?]*(?:(?:(?:[a-zA-Z\d]*(?:;[a-zA-Z\d]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-ntqry=><~]))/g;
|
|
21
|
+
function stripAnsi(s) {
|
|
22
|
+
return s.replace(ANSI_RE, "");
|
|
23
|
+
}
|
|
24
|
+
function truncate(s, max = exports.MAX_ERROR_BYTES) {
|
|
25
|
+
if (s === null || s === undefined || s === "")
|
|
26
|
+
return null;
|
|
27
|
+
const clean = stripAnsi(s);
|
|
28
|
+
if (Buffer.byteLength(clean, "utf8") <= max)
|
|
29
|
+
return clean;
|
|
30
|
+
// Cut by bytes, then drop a possibly broken trailing character.
|
|
31
|
+
const buf = Buffer.from(clean, "utf8").subarray(0, max - 20);
|
|
32
|
+
return buf.toString("utf8").replace(/�$/, "") + "\n… [truncated]";
|
|
33
|
+
}
|
|
34
|
+
/** Playwright `TestResult.status` → Planitro status (used when the test outcome is not available). */
|
|
35
|
+
function mapPlaywrightStatus(status) {
|
|
36
|
+
switch (status) {
|
|
37
|
+
case "passed":
|
|
38
|
+
return "passed";
|
|
39
|
+
case "skipped":
|
|
40
|
+
return "skipped";
|
|
41
|
+
case "failed":
|
|
42
|
+
case "timedOut":
|
|
43
|
+
case "interrupted":
|
|
44
|
+
default:
|
|
45
|
+
return "failed";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Playwright `TestCase.outcome()` (also `status` of a test in the JSON report) → Planitro status. This honours
|
|
50
|
+
* `test.fail()`: a test that is expected to fail and fails has outcome `expected`, i.e. passed.
|
|
51
|
+
*/
|
|
52
|
+
function mapOutcome(outcome) {
|
|
53
|
+
switch (outcome) {
|
|
54
|
+
case "expected":
|
|
55
|
+
case "flaky":
|
|
56
|
+
return "passed";
|
|
57
|
+
case "skipped":
|
|
58
|
+
return "skipped";
|
|
59
|
+
case "unexpected":
|
|
60
|
+
default:
|
|
61
|
+
return "failed";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const RANK = { failed: 4, blocked: 3, passed: 2, skipped: 1 };
|
|
65
|
+
/** Higher = worse. failed > blocked > passed > skipped. */
|
|
66
|
+
function statusRank(s) {
|
|
67
|
+
return RANK[s] ?? 0;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Collapses results that share an automation_id (the same test run by several Playwright projects, e.g.
|
|
71
|
+
* chromium + firefox): the worst status wins (failed > passed > skipped). Returns true when `next` should
|
|
72
|
+
* replace `current` (strictly worse; on a tie the first one reported stays).
|
|
73
|
+
*/
|
|
74
|
+
function shouldReplace(current, next) {
|
|
75
|
+
if (!current)
|
|
76
|
+
return true;
|
|
77
|
+
return statusRank(next.status) > statusRank(current.status);
|
|
78
|
+
}
|
|
79
|
+
/** In-memory dedup map used by both the reporter and the JSON converter. */
|
|
80
|
+
class ResultDeduper {
|
|
81
|
+
constructor() {
|
|
82
|
+
this.map = new Map();
|
|
83
|
+
}
|
|
84
|
+
/** Adds or merges a result. Returns true when it was stored (new id, or worse than what we had). */
|
|
85
|
+
add(r) {
|
|
86
|
+
const cur = this.map.get(r.payload.automation_id);
|
|
87
|
+
if (!shouldReplace(cur?.payload, r.payload)) {
|
|
88
|
+
// Keep the max retry count seen so flakiness on one browser is not lost.
|
|
89
|
+
if (cur && r.payload.retries > cur.payload.retries && cur.payload.status === r.payload.status) {
|
|
90
|
+
cur.payload.retries = r.payload.retries;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
this.map.set(r.payload.automation_id, r);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
get(id) {
|
|
98
|
+
return this.map.get(id);
|
|
99
|
+
}
|
|
100
|
+
values() {
|
|
101
|
+
return [...this.map.values()];
|
|
102
|
+
}
|
|
103
|
+
get size() {
|
|
104
|
+
return this.map.size;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.ResultDeduper = ResultDeduper;
|
|
108
|
+
const UPLOADABLE = /^(image\/|video\/|application\/zip$)/;
|
|
109
|
+
/** Picks which attachments to upload for a final result according to the mode. */
|
|
110
|
+
function selectAttachments(mode, status, attachments) {
|
|
111
|
+
if (mode === "none")
|
|
112
|
+
return [];
|
|
113
|
+
if (mode === "failures" && status !== "failed")
|
|
114
|
+
return [];
|
|
115
|
+
const out = [];
|
|
116
|
+
for (const a of attachments) {
|
|
117
|
+
if (!a.path)
|
|
118
|
+
continue;
|
|
119
|
+
if (!UPLOADABLE.test(a.contentType || ""))
|
|
120
|
+
continue;
|
|
121
|
+
out.push({ name: a.name, path: a.path, contentType: a.contentType });
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
function parseAttachmentMode(v, fallback = "failures") {
|
|
126
|
+
if (v === true)
|
|
127
|
+
return "all";
|
|
128
|
+
if (v === false)
|
|
129
|
+
return "none";
|
|
130
|
+
if (typeof v !== "string")
|
|
131
|
+
return fallback;
|
|
132
|
+
const s = v.trim().toLowerCase();
|
|
133
|
+
if (s === "all" || s === "true" || s === "always")
|
|
134
|
+
return "all";
|
|
135
|
+
if (s === "none" || s === "false" || s === "off" || s === "0" || s === "never")
|
|
136
|
+
return "none";
|
|
137
|
+
if (s === "failures" || s === "failed" || s === "on-failure")
|
|
138
|
+
return "failures";
|
|
139
|
+
return fallback;
|
|
140
|
+
}
|
|
141
|
+
function parseBool(v, fallback) {
|
|
142
|
+
if (typeof v === "boolean")
|
|
143
|
+
return v;
|
|
144
|
+
if (typeof v !== "string" || v.trim() === "")
|
|
145
|
+
return fallback;
|
|
146
|
+
const s = v.trim().toLowerCase();
|
|
147
|
+
if (["0", "false", "no", "off"].includes(s))
|
|
148
|
+
return false;
|
|
149
|
+
if (["1", "true", "yes", "on"].includes(s))
|
|
150
|
+
return true;
|
|
151
|
+
return fallback;
|
|
152
|
+
}
|
|
153
|
+
/** Counts per status, for the final one-line summary. */
|
|
154
|
+
function countStatuses(results) {
|
|
155
|
+
const c = { passed: 0, failed: 0, skipped: 0, blocked: 0 };
|
|
156
|
+
for (const r of results)
|
|
157
|
+
c[r.status] = (c[r.status] ?? 0) + 1;
|
|
158
|
+
return c;
|
|
159
|
+
}
|