@plune-ai/playwright 0.2.5 → 0.2.7
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 +4 -1
- package/dist/index.cjs +267 -37
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +267 -37
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -34,10 +34,13 @@ That is the whole setup. Options, if you want them:
|
|
|
34
34
|
batchSize: 100, // results per request (max 500)
|
|
35
35
|
fallbackPath: '.plune/pending-results.jsonl',
|
|
36
36
|
apiUrl: 'https://beta-api.plune.ai', // or PLUNE_API_URL
|
|
37
|
-
token: process.env.PLUNE_TOKEN, // or whatever `plune login` saved
|
|
38
37
|
}]
|
|
39
38
|
```
|
|
40
39
|
|
|
40
|
+
Keep the token out of this list: it comes from `PLUNE_TOKEN` or what `plune login` saved. Playwright
|
|
41
|
+
writes every reporter's options into its JSON report, so a token set here travels with any such
|
|
42
|
+
report a CI job keeps as an artifact.
|
|
43
|
+
|
|
41
44
|
## From CI, without editing the config
|
|
42
45
|
|
|
43
46
|
A committed config cannot know the run key of a job that does not exist yet, so the environment
|
package/dist/index.cjs
CHANGED
|
@@ -34,16 +34,23 @@ __export(src_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
var import_node_fs = require("fs");
|
|
37
|
+
var import_node_util = require("util");
|
|
37
38
|
|
|
38
39
|
// ../../dist/reporter-core.js
|
|
39
40
|
var import_crypto = require("crypto");
|
|
40
41
|
var import_fs = require("fs");
|
|
41
42
|
var import_os = require("os");
|
|
42
43
|
var import_path = require("path");
|
|
44
|
+
var import_http = require("http");
|
|
45
|
+
var import_https = require("https");
|
|
43
46
|
var path = __toESM(require("path"), 1);
|
|
44
47
|
var fs = __toESM(require("fs"), 1);
|
|
45
48
|
var path2 = __toESM(require("path"), 1);
|
|
46
49
|
var import_crypto2 = require("crypto");
|
|
50
|
+
var import_fs2 = require("fs");
|
|
51
|
+
var import_os2 = require("os");
|
|
52
|
+
var import_path2 = require("path");
|
|
53
|
+
var import_util = require("util");
|
|
47
54
|
var DEFAULT_API_URL = "https://beta-api.plune.ai";
|
|
48
55
|
function resolveApiUrl(explicit) {
|
|
49
56
|
const raw = explicit ?? process.env["PLUNE_API_URL"] ?? DEFAULT_API_URL;
|
|
@@ -54,6 +61,8 @@ function credentialsFile() {
|
|
|
54
61
|
return (0, import_path.join)(base, "plune", "credentials.json");
|
|
55
62
|
}
|
|
56
63
|
function loadToken() {
|
|
64
|
+
const fromEnv = process.env["PLUNE_TOKEN"]?.trim();
|
|
65
|
+
if (fromEnv !== void 0 && fromEnv !== "") return fromEnv;
|
|
57
66
|
try {
|
|
58
67
|
const parsed = JSON.parse((0, import_fs.readFileSync)(credentialsFile(), "utf-8"));
|
|
59
68
|
return typeof parsed.token === "string" && parsed.token.length > 0 ? parsed.token : null;
|
|
@@ -62,6 +71,36 @@ function loadToken() {
|
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
73
|
var RETRY_DELAYS_MS = [300, 900];
|
|
74
|
+
var IDLE_MS = 3e5;
|
|
75
|
+
function nodeTransport(url, init, idleMs = IDLE_MS) {
|
|
76
|
+
return new Promise((resolve2, reject) => {
|
|
77
|
+
const target = new URL(url);
|
|
78
|
+
const send = target.protocol === "https:" ? import_https.request : import_http.request;
|
|
79
|
+
const req = send(target, { method: init.method, headers: init.headers }, (res) => {
|
|
80
|
+
const chunks = [];
|
|
81
|
+
res.on("data", (chunk2) => chunks.push(chunk2));
|
|
82
|
+
res.on("error", reject);
|
|
83
|
+
res.on("end", () => {
|
|
84
|
+
const status = res.statusCode ?? 0;
|
|
85
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
86
|
+
resolve2({
|
|
87
|
+
ok: status >= 200 && status <= 299,
|
|
88
|
+
status,
|
|
89
|
+
headers: {
|
|
90
|
+
get: (name) => {
|
|
91
|
+
const value2 = res.headers[name.toLowerCase()];
|
|
92
|
+
return value2 === void 0 ? null : Array.isArray(value2) ? value2.join(", ") : value2;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
json: async () => JSON.parse(text)
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
req.setTimeout(idleMs, () => req.destroy(new Error(`no answer from ${target.origin} in ${idleMs} ms`)));
|
|
100
|
+
req.on("error", reject);
|
|
101
|
+
req.end(init.body);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
65
104
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
66
105
|
async function detailOf(res) {
|
|
67
106
|
try {
|
|
@@ -85,7 +124,7 @@ function classify(status) {
|
|
|
85
124
|
return "other";
|
|
86
125
|
}
|
|
87
126
|
function createClient(opts) {
|
|
88
|
-
const doFetch = opts.fetchImpl ??
|
|
127
|
+
const doFetch = opts.fetchImpl ?? nodeTransport;
|
|
89
128
|
const wait = opts.wait ?? sleep;
|
|
90
129
|
const base = opts.apiUrl.replace(/\/+$/, "");
|
|
91
130
|
const scrub = (text) => opts.token === "" ? text : text.split(opts.token).join("***");
|
|
@@ -113,7 +152,11 @@ function createClient(opts) {
|
|
|
113
152
|
}
|
|
114
153
|
if (res.ok) {
|
|
115
154
|
if (res.status === 204) return { ok: true, status: res.status, body: void 0 };
|
|
116
|
-
|
|
155
|
+
try {
|
|
156
|
+
return { ok: true, status: res.status, body: await res.json() };
|
|
157
|
+
} catch {
|
|
158
|
+
return { ok: false, kind: "other", status: res.status, detail: "the answer was not JSON" };
|
|
159
|
+
}
|
|
117
160
|
}
|
|
118
161
|
const detail = scrub(await detailOf(res));
|
|
119
162
|
const kind = classify(res.status);
|
|
@@ -219,6 +262,25 @@ function boundKey(key) {
|
|
|
219
262
|
function boundTitle(title) {
|
|
220
263
|
return title.length <= TITLE_MAX ? title : `${title.slice(0, TITLE_MAX - 1)}\u2026`;
|
|
221
264
|
}
|
|
265
|
+
var BATCH_BYTES = 8 * 1024 * 1024;
|
|
266
|
+
var ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ results: [] }));
|
|
267
|
+
function packed(results) {
|
|
268
|
+
const out = [];
|
|
269
|
+
let part = [];
|
|
270
|
+
let bytes = ENVELOPE_BYTES;
|
|
271
|
+
for (const result of results) {
|
|
272
|
+
const size = Buffer.byteLength(JSON.stringify(result));
|
|
273
|
+
if (part.length > 0 && bytes + 1 + size > BATCH_BYTES) {
|
|
274
|
+
out.push(part);
|
|
275
|
+
part = [];
|
|
276
|
+
bytes = ENVELOPE_BYTES;
|
|
277
|
+
}
|
|
278
|
+
bytes += (part.length > 0 ? 1 : 0) + size;
|
|
279
|
+
part.push(result);
|
|
280
|
+
}
|
|
281
|
+
if (part.length > 0) out.push(part);
|
|
282
|
+
return out;
|
|
283
|
+
}
|
|
222
284
|
function chunk(items, size) {
|
|
223
285
|
const out = [];
|
|
224
286
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
@@ -232,7 +294,7 @@ function warnIfDropped(sent, run, log) {
|
|
|
232
294
|
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
233
295
|
);
|
|
234
296
|
}
|
|
235
|
-
async function startRun(passed,
|
|
297
|
+
async function startRun(passed, declared2) {
|
|
236
298
|
const env = readEnv();
|
|
237
299
|
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
238
300
|
const cfg = { ...env.config, ...stated };
|
|
@@ -281,7 +343,7 @@ async function startRun(passed, declared) {
|
|
|
281
343
|
return fit;
|
|
282
344
|
});
|
|
283
345
|
}
|
|
284
|
-
const expected =
|
|
346
|
+
const expected = declared2?.map(bound);
|
|
285
347
|
if (offline) {
|
|
286
348
|
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
287
349
|
}
|
|
@@ -420,27 +482,35 @@ async function startRun(passed, declared) {
|
|
|
420
482
|
progress();
|
|
421
483
|
return;
|
|
422
484
|
}
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
485
|
+
for (const part of packed(submissions)) {
|
|
486
|
+
if (offline) {
|
|
487
|
+
defer(part);
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
490
|
+
const out = await client.post(`/v1/runs/${runId}/results`, {
|
|
491
|
+
results: part
|
|
492
|
+
});
|
|
493
|
+
const counts = out.ok ? out.body?.counts : void 0;
|
|
494
|
+
if (counts !== void 0) {
|
|
495
|
+
stats.accepted += counts.accepted ?? 0;
|
|
496
|
+
stats.duplicate += counts.duplicate ?? 0;
|
|
497
|
+
stats.conflict += counts.conflict ?? 0;
|
|
498
|
+
stats.rejected += counts.rejected ?? 0;
|
|
499
|
+
progress();
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
if (out.ok) {
|
|
503
|
+
log("plune: could not send results (the answer carried no counts).");
|
|
504
|
+
} else if (out.kind === "auth") {
|
|
505
|
+
log('plune: the API token was refused \u2014 run "plune login" with a fresh one.');
|
|
506
|
+
offline = true;
|
|
507
|
+
} else if (out.kind === "conflict") {
|
|
508
|
+
log(`plune: this run is closed \u2014 ${out.detail}`);
|
|
509
|
+
} else {
|
|
510
|
+
log(`plune: could not send results (${out.detail || out.kind}).`);
|
|
511
|
+
}
|
|
512
|
+
defer(part);
|
|
442
513
|
}
|
|
443
|
-
defer(submissions);
|
|
444
514
|
}
|
|
445
515
|
function progress() {
|
|
446
516
|
const total = expected?.length ?? 0;
|
|
@@ -456,9 +526,12 @@ async function startRun(passed, declared) {
|
|
|
456
526
|
if (stats.unresolved > 0) parts.push(`${stats.unresolved} with no matching test case`);
|
|
457
527
|
if (stats.offered > 0) parts.push(`${stats.offered} offered for review`);
|
|
458
528
|
if (stats.created > 0) parts.push(`${stats.created} added as cases (trusted source)`);
|
|
459
|
-
if (stats.deferred > 0) parts.push(`${stats.deferred} written to ${fallbackPath}`);
|
|
529
|
+
if (stats.deferred > 0) parts.push(`${stats.deferred} not delivered \u2014 written to ${fallbackPath}`);
|
|
460
530
|
if (shortened.size > 0) parts.push(`${shortened.size} test name(s) shortened to fit a key`);
|
|
461
531
|
log(`plune: ${parts.join(" \xB7 ")}`);
|
|
532
|
+
if (stats.deferred > 0 && process.env["GITHUB_ACTIONS"] === "true") {
|
|
533
|
+
log(`::warning::${stats.deferred} result(s) were not delivered to Plune \u2014 see the reporting step's log.`);
|
|
534
|
+
}
|
|
462
535
|
}
|
|
463
536
|
return {
|
|
464
537
|
get runId() {
|
|
@@ -513,10 +586,127 @@ function resultKey(testId, retry) {
|
|
|
513
586
|
const plain = `${testId}#${retry}`;
|
|
514
587
|
return plain.length <= RESULT_KEY_MAX ? plain : `${sha256(testId).slice(0, HASH_CHARS)}#${retry}`;
|
|
515
588
|
}
|
|
589
|
+
function failureOf(attempt, home = (0, import_os2.homedir)()) {
|
|
590
|
+
const error = chosen(attempt);
|
|
591
|
+
const line = error === void 0 ? void 0 : firstLine(machineless(error.text, attempt.repoRoot, home));
|
|
592
|
+
const headline = line !== void 0 && jsonBytes(line) <= HEADLINE_LIMIT ? line : void 0;
|
|
593
|
+
const steps = chainOf(attempt.steps);
|
|
594
|
+
const location = error === void 0 ? void 0 : fromRoot(placeOf(error, attempt.testFile), attempt.repoRoot);
|
|
595
|
+
const artifacts = attempt.attachments.filter((a) => a.path !== void 0 && !a.name.startsWith("_") && a.contentType !== METADATA_TYPE).map(({ name, contentType }) => ({ name: fileNameOf(name), ...contentType ? { contentType } : {} })).filter((a) => a.name !== "");
|
|
596
|
+
const ciUrl = webLink(attempt.buildHref);
|
|
597
|
+
const failure = {
|
|
598
|
+
...headline !== void 0 ? { headline } : {},
|
|
599
|
+
...steps.length > 0 ? { steps } : {},
|
|
600
|
+
...location !== void 0 ? { location } : {},
|
|
601
|
+
...artifacts.length > 0 ? { artifacts } : {},
|
|
602
|
+
...ciUrl !== void 0 ? { ciUrl } : {}
|
|
603
|
+
};
|
|
604
|
+
return Object.keys(failure).length === 0 ? void 0 : failure;
|
|
605
|
+
}
|
|
606
|
+
function repoRootOf(dir, stopAt) {
|
|
607
|
+
for (let here = (0, import_path2.resolve)(dir); ; here = (0, import_path2.dirname)(here)) {
|
|
608
|
+
if ((0, import_fs2.existsSync)((0, import_path2.join)(here, ".git"))) return here;
|
|
609
|
+
if (here === stopAt || (0, import_path2.dirname)(here) === here) return void 0;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
function errorContextOf(attempt, home = (0, import_os2.homedir)()) {
|
|
613
|
+
const text = attempt.errors.map((e) => e.text).filter((t) => t !== "").join("\n\n");
|
|
614
|
+
return cut(machineless(text, attempt.repoRoot, home));
|
|
615
|
+
}
|
|
616
|
+
function machineless(raw, repoRoot, home) {
|
|
617
|
+
let text = (0, import_util.stripVTControlCharacters)(raw).replaceAll("\x1B", "");
|
|
618
|
+
const root = repoRoot === void 0 ? void 0 : pathIn(repoRoot);
|
|
619
|
+
if (root !== void 0) text = text.replace(new RegExp(`${PATH_START}${root.source}[\\\\/]+`, root.flags), "");
|
|
620
|
+
const own = pathIn(home);
|
|
621
|
+
if (own !== void 0) text = text.replace(new RegExp(`${PATH_START}${own.source}(?![\\w.-])`, own.flags), "~");
|
|
622
|
+
if (repoRoot === void 0) text = text.replace(ANY_HOME, "~");
|
|
623
|
+
return text;
|
|
624
|
+
}
|
|
625
|
+
var PATH_START = "(?<![\\w.~%/\\\\-])";
|
|
626
|
+
var TEXT_LIMIT = 524288;
|
|
627
|
+
var HEADLINE_LIMIT = 8 * 1024;
|
|
628
|
+
var jsonBytes = (text) => Buffer.byteLength(JSON.stringify(text)) - 2;
|
|
629
|
+
var ANY_HOME = /(?<=^|[\s'"`(=,[])(?:file:\/\/\/?)?(?:\/home\/|\/Users\/|[A-Za-z]:[\\/]+Users[\\/]+)[^\\/\s'"`:*?<>|]+/g;
|
|
630
|
+
function pathIn(path3) {
|
|
631
|
+
const parts = path3.split(/[\\/]+/);
|
|
632
|
+
while (parts.length > 1 && parts.at(-1) === "") parts.pop();
|
|
633
|
+
if (!parts.some((part) => part !== "" && !/^[A-Za-z]:$/.test(part))) return void 0;
|
|
634
|
+
const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]+");
|
|
635
|
+
return new RegExp(`(?:file:\\/\\/\\/?)?${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
|
|
636
|
+
}
|
|
637
|
+
var fileNameOf = (name) => /^(?:file:\/\/|[\\/]|~[\\/]|[A-Za-z]:[\\/])/.test(name) ? name.split(/[\\/]/).pop() ?? "" : name;
|
|
638
|
+
function cut(text) {
|
|
639
|
+
if (jsonBytes(text) <= TEXT_LIMIT) return text;
|
|
640
|
+
const lines = text.split("\n");
|
|
641
|
+
const size = lines.map((line) => jsonBytes(line) + 2);
|
|
642
|
+
const budget = TEXT_LIMIT - jsonBytes(omitted(lines.length));
|
|
643
|
+
let used = 0;
|
|
644
|
+
let head = 0;
|
|
645
|
+
let tail = lines.length;
|
|
646
|
+
while (head < tail && used + size[head] <= budget / 2) used += size[head++];
|
|
647
|
+
while (tail > head && used + size[tail - 1] <= budget) used += size[--tail];
|
|
648
|
+
return [...lines.slice(0, head), omitted(tail - head), ...lines.slice(tail)].join("\n");
|
|
649
|
+
}
|
|
650
|
+
var omitted = (lines) => `\u2026[omitted ${lines} lines]\u2026`;
|
|
651
|
+
var METADATA_TYPE = "application/plune.metadata+json";
|
|
652
|
+
var REPO_RELATIVE = /^(?![A-Za-z][A-Za-z0-9+.-]*:)(?![\\/~])(?!(?:.*[\\/])?\.\.(?:[\\/]|$)).+$/;
|
|
653
|
+
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
654
|
+
var FRAME_MAX = 8192;
|
|
655
|
+
var firstLine = (text) => (0, import_util.stripVTControlCharacters)(text).split("\n").map((line) => line.trim()).find((line) => line !== "");
|
|
656
|
+
function chosen({ status, errors }) {
|
|
657
|
+
if (status === "timedOut") {
|
|
658
|
+
const timeout = errors.findIndex((e) => firstLine(e.text)?.startsWith("Test timeout of ") === true);
|
|
659
|
+
if (timeout !== -1 && timeout + 1 < errors.length) return errors[timeout + 1];
|
|
660
|
+
}
|
|
661
|
+
return errors[0];
|
|
662
|
+
}
|
|
663
|
+
function chainOf(steps) {
|
|
664
|
+
const chain = [];
|
|
665
|
+
for (let failed = steps.find((s) => s.failed); failed !== void 0; failed = failed.steps.find((s) => s.failed)) {
|
|
666
|
+
chain.push(failed.title);
|
|
667
|
+
}
|
|
668
|
+
return chain;
|
|
669
|
+
}
|
|
670
|
+
function placeOf(error, testFile) {
|
|
671
|
+
const own = normal(testFile);
|
|
672
|
+
let first;
|
|
673
|
+
for (const line of (0, import_util.stripVTControlCharacters)(error.text).split("\n")) {
|
|
674
|
+
if (line.length > FRAME_MAX) continue;
|
|
675
|
+
const frame = FRAME.exec(line);
|
|
676
|
+
if (frame === null) continue;
|
|
677
|
+
const place = { file: fileOf(frame[1]), line: Number(frame[2]), column: Number(frame[3]) };
|
|
678
|
+
if (normal(place.file) === own) return place;
|
|
679
|
+
if (first === void 0 && !normal(place.file).includes("/node_modules/")) first = place;
|
|
680
|
+
}
|
|
681
|
+
return error.location ?? first;
|
|
682
|
+
}
|
|
683
|
+
function fileOf(raw) {
|
|
684
|
+
if (!raw.startsWith("file://")) return raw;
|
|
685
|
+
let path3 = raw.slice("file://".length);
|
|
686
|
+
try {
|
|
687
|
+
path3 = decodeURIComponent(path3);
|
|
688
|
+
} catch {
|
|
689
|
+
}
|
|
690
|
+
return /^\/[A-Za-z]:\//.test(path3) ? path3.slice(1) : path3;
|
|
691
|
+
}
|
|
692
|
+
var normal = (path3) => import_path2.posix.normalize(path3.replace(/\\/g, "/")).replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`);
|
|
693
|
+
function fromRoot(place, root) {
|
|
694
|
+
if (place === void 0 || root === void 0 || !Number.isInteger(place.line) || place.line < 1) return void 0;
|
|
695
|
+
const base = normal(root).replace(/\/+$/, "");
|
|
696
|
+
const file = normal(place.file);
|
|
697
|
+
if (!file.startsWith(`${base}/`)) return void 0;
|
|
698
|
+
const relative = file.slice(base.length + 1);
|
|
699
|
+
if (!REPO_RELATIVE.test(relative)) return void 0;
|
|
700
|
+
const column = place.column !== void 0 && Number.isInteger(place.column) && place.column >= 1 ? place.column : void 0;
|
|
701
|
+
return column === void 0 ? { file: relative, line: place.line } : { file: relative, line: place.line, column };
|
|
702
|
+
}
|
|
703
|
+
function webLink(href) {
|
|
704
|
+
return href !== void 0 && /^https?:\/\//i.test(href) && URL.canParse(href) ? href : void 0;
|
|
705
|
+
}
|
|
516
706
|
|
|
517
707
|
// src/index.ts
|
|
518
708
|
var SOURCE = "playwright";
|
|
519
|
-
function
|
|
709
|
+
function fileOf2(test) {
|
|
520
710
|
for (let suite = test.parent; suite !== void 0; suite = suite.parent) {
|
|
521
711
|
if (suite.type === "file") return suite.title.replace(/\\/g, "/");
|
|
522
712
|
}
|
|
@@ -532,13 +722,13 @@ function titlesOf(test) {
|
|
|
532
722
|
function keysFor(test) {
|
|
533
723
|
return [
|
|
534
724
|
{ kind: "playwright-id", value: test.id },
|
|
535
|
-
{ kind: "path-title", value: [
|
|
725
|
+
{ kind: "path-title", value: [fileOf2(test), ...titlesOf(test)].join("#") }
|
|
536
726
|
];
|
|
537
727
|
}
|
|
538
|
-
var
|
|
728
|
+
var METADATA_TYPE2 = "application/plune.metadata+json";
|
|
539
729
|
var TOKEN = /@P([A-Za-z0-9_-]+)/;
|
|
540
730
|
function metadataOf(result) {
|
|
541
|
-
const found = result.attachments.find((a) => a.contentType ===
|
|
731
|
+
const found = result.attachments.find((a) => a.contentType === METADATA_TYPE2);
|
|
542
732
|
if (found === void 0) return void 0;
|
|
543
733
|
try {
|
|
544
734
|
const raw = found.body !== void 0 ? found.body.toString("utf8") : found.path !== void 0 ? (0, import_node_fs.readFileSync)(found.path, "utf8") : void 0;
|
|
@@ -554,14 +744,43 @@ function statedIdOf(test, metadata) {
|
|
|
554
744
|
if (token !== void 0) return token;
|
|
555
745
|
return metadata?.id !== void 0 && metadata.id !== "" ? metadata.id : void 0;
|
|
556
746
|
}
|
|
557
|
-
|
|
558
|
-
|
|
747
|
+
var NOT_FAILED = /* @__PURE__ */ new Set(["passed", "skipped"]);
|
|
748
|
+
function textOf(error) {
|
|
749
|
+
const message = error.message || error.value || "";
|
|
750
|
+
if (!error.stack && !error.location) return message;
|
|
751
|
+
const lines = error.stack?.split("\n") ?? [];
|
|
752
|
+
const at = lines.findIndex((line) => line.startsWith(" at "));
|
|
753
|
+
const tokens = [(at === -1 ? lines : lines.slice(0, at)).join("\n") || message];
|
|
754
|
+
if (error.snippet) tokens.push("", (0, import_node_util.stripVTControlCharacters)(error.snippet));
|
|
755
|
+
if (at !== -1) tokens.push(lines.slice(at).join("\n"));
|
|
756
|
+
if (error.cause) tokens.push(`[cause]: ${textOf(error.cause)}`);
|
|
757
|
+
return tokens.join("\n");
|
|
758
|
+
}
|
|
759
|
+
function declared(steps) {
|
|
760
|
+
return steps.filter((step) => step.category === "test.step").map((step) => ({ title: step.title, failed: step.error !== void 0, steps: declared(step.steps) }));
|
|
761
|
+
}
|
|
762
|
+
function attemptOf(test, result, ctx) {
|
|
763
|
+
return {
|
|
764
|
+
status: result.status,
|
|
765
|
+
errors: result.errors.map((e) => ({ text: textOf(e), ...e.location !== void 0 ? { location: e.location } : {} })),
|
|
766
|
+
steps: declared(result.steps ?? []),
|
|
767
|
+
attachments: result.attachments.map(({ name, contentType, path: path3 }) => ({
|
|
768
|
+
name,
|
|
769
|
+
contentType,
|
|
770
|
+
...path3 !== void 0 ? { path: path3 } : {}
|
|
771
|
+
})),
|
|
772
|
+
...ctx.buildHref !== void 0 ? { buildHref: ctx.buildHref } : {},
|
|
773
|
+
testFile: test.location.file,
|
|
774
|
+
...ctx.repoRoot !== void 0 ? { repoRoot: ctx.repoRoot } : {}
|
|
775
|
+
};
|
|
559
776
|
}
|
|
560
|
-
function pendingFrom(test, result) {
|
|
777
|
+
function pendingFrom(test, result, ctx) {
|
|
561
778
|
const metadata = metadataOf(result);
|
|
562
779
|
const pluneId = statedIdOf(test, metadata);
|
|
563
780
|
const expected = test.expectedStatus;
|
|
564
|
-
const
|
|
781
|
+
const attempt = attemptOf(test, result, ctx);
|
|
782
|
+
const errorContext = errorContextOf(attempt);
|
|
783
|
+
const failure = NOT_FAILED.has(result.status) ? void 0 : failureOf(attempt);
|
|
565
784
|
const startedAt = result.startTime;
|
|
566
785
|
return {
|
|
567
786
|
resultKey: resultKey(test.id, result.retry),
|
|
@@ -575,7 +794,7 @@ function pendingFrom(test, result) {
|
|
|
575
794
|
title: titlesOf(test).join(" \u203A "),
|
|
576
795
|
// The line as well as the file. A reviewer's first move on an unknown test is to open it, and
|
|
577
796
|
// `specRef` is the only thing the entry carries that can take them there.
|
|
578
|
-
specRef: `${
|
|
797
|
+
specRef: `${fileOf2(test)}:${test.location.line}`,
|
|
579
798
|
source: SOURCE,
|
|
580
799
|
// The runner's own word, untouched. Mapping it is the platform's job and a project's setting.
|
|
581
800
|
rawStatus: result.status,
|
|
@@ -589,7 +808,8 @@ function pendingFrom(test, result) {
|
|
|
589
808
|
retry: result.retry,
|
|
590
809
|
worker: String(result.workerIndex)
|
|
591
810
|
},
|
|
592
|
-
...errorContext !== "" ? { errorContext } : {}
|
|
811
|
+
...errorContext !== "" ? { errorContext } : {},
|
|
812
|
+
...failure !== void 0 ? { failure } : {}
|
|
593
813
|
};
|
|
594
814
|
}
|
|
595
815
|
var PluneReporter = class {
|
|
@@ -601,6 +821,9 @@ var PluneReporter = class {
|
|
|
601
821
|
chain = Promise.resolve();
|
|
602
822
|
keepOpen = false;
|
|
603
823
|
complained = false;
|
|
824
|
+
/** Kept whole: `metadata.ci` is written into it after `onConfigure`, so it is read at the run's opening. */
|
|
825
|
+
config = null;
|
|
826
|
+
context = {};
|
|
604
827
|
constructor(options = {}) {
|
|
605
828
|
this.options = options;
|
|
606
829
|
}
|
|
@@ -614,6 +837,9 @@ var PluneReporter = class {
|
|
|
614
837
|
}
|
|
615
838
|
onConfigure(config) {
|
|
616
839
|
this.keepOpen = config.shard !== null && config.shard !== void 0 || readEnv().keepOpen;
|
|
840
|
+
this.config = config;
|
|
841
|
+
const repoRoot = config.rootDir === void 0 ? void 0 : repoRootOf(config.rootDir);
|
|
842
|
+
if (repoRoot !== void 0) this.context = { repoRoot };
|
|
617
843
|
}
|
|
618
844
|
/**
|
|
619
845
|
* Only the list is taken here; the run opens on the first result. `onBegin` also fires for
|
|
@@ -627,6 +853,10 @@ var PluneReporter = class {
|
|
|
627
853
|
}
|
|
628
854
|
open() {
|
|
629
855
|
if (this.session === null) {
|
|
856
|
+
const ci = this.config?.metadata?.["ci"];
|
|
857
|
+
const buildHref = typeof ci === "object" && ci !== null ? ci.buildHref : void 0;
|
|
858
|
+
if (typeof buildHref === "string") this.context = { ...this.context, buildHref };
|
|
859
|
+
const ciUrl = webLink(this.context.buildHref);
|
|
630
860
|
this.session = startRun(
|
|
631
861
|
{
|
|
632
862
|
...this.options.apiUrl !== void 0 ? { apiUrl: this.options.apiUrl } : {},
|
|
@@ -634,7 +864,7 @@ var PluneReporter = class {
|
|
|
634
864
|
...this.options.externalKey !== void 0 ? { externalKey: this.options.externalKey } : {},
|
|
635
865
|
...this.options.batchSize !== void 0 ? { batchSize: this.options.batchSize } : {},
|
|
636
866
|
...this.options.fallbackPath !== void 0 ? { fallbackPath: this.options.fallbackPath } : {},
|
|
637
|
-
meta: { runner: SOURCE }
|
|
867
|
+
meta: { runner: SOURCE, ...ciUrl !== void 0 ? { ciUrl } : {} }
|
|
638
868
|
},
|
|
639
869
|
this.declared
|
|
640
870
|
);
|
|
@@ -644,7 +874,7 @@ var PluneReporter = class {
|
|
|
644
874
|
onTestEnd(test, result) {
|
|
645
875
|
const session = this.open();
|
|
646
876
|
this.chain = this.chain.then(async () => {
|
|
647
|
-
(await session).add(pendingFrom(test, result));
|
|
877
|
+
await (await session).add(pendingFrom(test, result, this.context));
|
|
648
878
|
}).catch((err) => this.giveUp(err));
|
|
649
879
|
}
|
|
650
880
|
async onEnd(_result) {
|
package/dist/index.d.cts
CHANGED
|
@@ -24,6 +24,9 @@ declare class PluneReporter {
|
|
|
24
24
|
private chain;
|
|
25
25
|
private keepOpen;
|
|
26
26
|
private complained;
|
|
27
|
+
/** Kept whole: `metadata.ci` is written into it after `onConfigure`, so it is read at the run's opening. */
|
|
28
|
+
private config;
|
|
29
|
+
private context;
|
|
27
30
|
constructor(options?: PluneReporterOptions);
|
|
28
31
|
/** Playwright reads this to pick the v2 calling convention (`onConfigure` + `onBegin(suite)`). */
|
|
29
32
|
version(): 'v2';
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,9 @@ declare class PluneReporter {
|
|
|
24
24
|
private chain;
|
|
25
25
|
private keepOpen;
|
|
26
26
|
private complained;
|
|
27
|
+
/** Kept whole: `metadata.ci` is written into it after `onConfigure`, so it is read at the run's opening. */
|
|
28
|
+
private config;
|
|
29
|
+
private context;
|
|
27
30
|
constructor(options?: PluneReporterOptions);
|
|
28
31
|
/** Playwright reads this to pick the v2 calling convention (`onConfigure` + `onBegin(suite)`). */
|
|
29
32
|
version(): 'v2';
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { readFileSync as readFileSync2 } from "fs";
|
|
3
|
+
import { stripVTControlCharacters as stripVTControlCharacters2 } from "util";
|
|
3
4
|
|
|
4
5
|
// ../../dist/reporter-core.js
|
|
5
6
|
import { createHash } from "crypto";
|
|
6
7
|
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
7
8
|
import { homedir } from "os";
|
|
8
9
|
import { dirname, join } from "path";
|
|
10
|
+
import { request as httpRequest } from "http";
|
|
11
|
+
import { request as httpsRequest } from "https";
|
|
9
12
|
import * as path from "path";
|
|
10
13
|
import * as fs from "fs";
|
|
11
14
|
import * as path2 from "path";
|
|
12
15
|
import { createHash as createHash2 } from "crypto";
|
|
16
|
+
import { existsSync as existsSync2 } from "fs";
|
|
17
|
+
import { homedir as homedir2 } from "os";
|
|
18
|
+
import { dirname as dirname3, join as join3, posix, resolve } from "path";
|
|
19
|
+
import { stripVTControlCharacters } from "util";
|
|
13
20
|
var DEFAULT_API_URL = "https://beta-api.plune.ai";
|
|
14
21
|
function resolveApiUrl(explicit) {
|
|
15
22
|
const raw = explicit ?? process.env["PLUNE_API_URL"] ?? DEFAULT_API_URL;
|
|
@@ -20,6 +27,8 @@ function credentialsFile() {
|
|
|
20
27
|
return join(base, "plune", "credentials.json");
|
|
21
28
|
}
|
|
22
29
|
function loadToken() {
|
|
30
|
+
const fromEnv = process.env["PLUNE_TOKEN"]?.trim();
|
|
31
|
+
if (fromEnv !== void 0 && fromEnv !== "") return fromEnv;
|
|
23
32
|
try {
|
|
24
33
|
const parsed = JSON.parse(readFileSync(credentialsFile(), "utf-8"));
|
|
25
34
|
return typeof parsed.token === "string" && parsed.token.length > 0 ? parsed.token : null;
|
|
@@ -28,6 +37,36 @@ function loadToken() {
|
|
|
28
37
|
}
|
|
29
38
|
}
|
|
30
39
|
var RETRY_DELAYS_MS = [300, 900];
|
|
40
|
+
var IDLE_MS = 3e5;
|
|
41
|
+
function nodeTransport(url, init, idleMs = IDLE_MS) {
|
|
42
|
+
return new Promise((resolve2, reject) => {
|
|
43
|
+
const target = new URL(url);
|
|
44
|
+
const send = target.protocol === "https:" ? httpsRequest : httpRequest;
|
|
45
|
+
const req = send(target, { method: init.method, headers: init.headers }, (res) => {
|
|
46
|
+
const chunks = [];
|
|
47
|
+
res.on("data", (chunk2) => chunks.push(chunk2));
|
|
48
|
+
res.on("error", reject);
|
|
49
|
+
res.on("end", () => {
|
|
50
|
+
const status = res.statusCode ?? 0;
|
|
51
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
52
|
+
resolve2({
|
|
53
|
+
ok: status >= 200 && status <= 299,
|
|
54
|
+
status,
|
|
55
|
+
headers: {
|
|
56
|
+
get: (name) => {
|
|
57
|
+
const value2 = res.headers[name.toLowerCase()];
|
|
58
|
+
return value2 === void 0 ? null : Array.isArray(value2) ? value2.join(", ") : value2;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
json: async () => JSON.parse(text)
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
req.setTimeout(idleMs, () => req.destroy(new Error(`no answer from ${target.origin} in ${idleMs} ms`)));
|
|
66
|
+
req.on("error", reject);
|
|
67
|
+
req.end(init.body);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
31
70
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
32
71
|
async function detailOf(res) {
|
|
33
72
|
try {
|
|
@@ -51,7 +90,7 @@ function classify(status) {
|
|
|
51
90
|
return "other";
|
|
52
91
|
}
|
|
53
92
|
function createClient(opts) {
|
|
54
|
-
const doFetch = opts.fetchImpl ??
|
|
93
|
+
const doFetch = opts.fetchImpl ?? nodeTransport;
|
|
55
94
|
const wait = opts.wait ?? sleep;
|
|
56
95
|
const base = opts.apiUrl.replace(/\/+$/, "");
|
|
57
96
|
const scrub = (text) => opts.token === "" ? text : text.split(opts.token).join("***");
|
|
@@ -79,7 +118,11 @@ function createClient(opts) {
|
|
|
79
118
|
}
|
|
80
119
|
if (res.ok) {
|
|
81
120
|
if (res.status === 204) return { ok: true, status: res.status, body: void 0 };
|
|
82
|
-
|
|
121
|
+
try {
|
|
122
|
+
return { ok: true, status: res.status, body: await res.json() };
|
|
123
|
+
} catch {
|
|
124
|
+
return { ok: false, kind: "other", status: res.status, detail: "the answer was not JSON" };
|
|
125
|
+
}
|
|
83
126
|
}
|
|
84
127
|
const detail = scrub(await detailOf(res));
|
|
85
128
|
const kind = classify(res.status);
|
|
@@ -185,6 +228,25 @@ function boundKey(key) {
|
|
|
185
228
|
function boundTitle(title) {
|
|
186
229
|
return title.length <= TITLE_MAX ? title : `${title.slice(0, TITLE_MAX - 1)}\u2026`;
|
|
187
230
|
}
|
|
231
|
+
var BATCH_BYTES = 8 * 1024 * 1024;
|
|
232
|
+
var ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ results: [] }));
|
|
233
|
+
function packed(results) {
|
|
234
|
+
const out = [];
|
|
235
|
+
let part = [];
|
|
236
|
+
let bytes = ENVELOPE_BYTES;
|
|
237
|
+
for (const result of results) {
|
|
238
|
+
const size = Buffer.byteLength(JSON.stringify(result));
|
|
239
|
+
if (part.length > 0 && bytes + 1 + size > BATCH_BYTES) {
|
|
240
|
+
out.push(part);
|
|
241
|
+
part = [];
|
|
242
|
+
bytes = ENVELOPE_BYTES;
|
|
243
|
+
}
|
|
244
|
+
bytes += (part.length > 0 ? 1 : 0) + size;
|
|
245
|
+
part.push(result);
|
|
246
|
+
}
|
|
247
|
+
if (part.length > 0) out.push(part);
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
188
250
|
function chunk(items, size) {
|
|
189
251
|
const out = [];
|
|
190
252
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
@@ -198,7 +260,7 @@ function warnIfDropped(sent, run, log) {
|
|
|
198
260
|
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
199
261
|
);
|
|
200
262
|
}
|
|
201
|
-
async function startRun(passed,
|
|
263
|
+
async function startRun(passed, declared2) {
|
|
202
264
|
const env = readEnv();
|
|
203
265
|
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
204
266
|
const cfg = { ...env.config, ...stated };
|
|
@@ -247,7 +309,7 @@ async function startRun(passed, declared) {
|
|
|
247
309
|
return fit;
|
|
248
310
|
});
|
|
249
311
|
}
|
|
250
|
-
const expected =
|
|
312
|
+
const expected = declared2?.map(bound);
|
|
251
313
|
if (offline) {
|
|
252
314
|
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
253
315
|
}
|
|
@@ -386,27 +448,35 @@ async function startRun(passed, declared) {
|
|
|
386
448
|
progress();
|
|
387
449
|
return;
|
|
388
450
|
}
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
451
|
+
for (const part of packed(submissions)) {
|
|
452
|
+
if (offline) {
|
|
453
|
+
defer(part);
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
const out = await client.post(`/v1/runs/${runId}/results`, {
|
|
457
|
+
results: part
|
|
458
|
+
});
|
|
459
|
+
const counts = out.ok ? out.body?.counts : void 0;
|
|
460
|
+
if (counts !== void 0) {
|
|
461
|
+
stats.accepted += counts.accepted ?? 0;
|
|
462
|
+
stats.duplicate += counts.duplicate ?? 0;
|
|
463
|
+
stats.conflict += counts.conflict ?? 0;
|
|
464
|
+
stats.rejected += counts.rejected ?? 0;
|
|
465
|
+
progress();
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
if (out.ok) {
|
|
469
|
+
log("plune: could not send results (the answer carried no counts).");
|
|
470
|
+
} else if (out.kind === "auth") {
|
|
471
|
+
log('plune: the API token was refused \u2014 run "plune login" with a fresh one.');
|
|
472
|
+
offline = true;
|
|
473
|
+
} else if (out.kind === "conflict") {
|
|
474
|
+
log(`plune: this run is closed \u2014 ${out.detail}`);
|
|
475
|
+
} else {
|
|
476
|
+
log(`plune: could not send results (${out.detail || out.kind}).`);
|
|
477
|
+
}
|
|
478
|
+
defer(part);
|
|
408
479
|
}
|
|
409
|
-
defer(submissions);
|
|
410
480
|
}
|
|
411
481
|
function progress() {
|
|
412
482
|
const total = expected?.length ?? 0;
|
|
@@ -422,9 +492,12 @@ async function startRun(passed, declared) {
|
|
|
422
492
|
if (stats.unresolved > 0) parts.push(`${stats.unresolved} with no matching test case`);
|
|
423
493
|
if (stats.offered > 0) parts.push(`${stats.offered} offered for review`);
|
|
424
494
|
if (stats.created > 0) parts.push(`${stats.created} added as cases (trusted source)`);
|
|
425
|
-
if (stats.deferred > 0) parts.push(`${stats.deferred} written to ${fallbackPath}`);
|
|
495
|
+
if (stats.deferred > 0) parts.push(`${stats.deferred} not delivered \u2014 written to ${fallbackPath}`);
|
|
426
496
|
if (shortened.size > 0) parts.push(`${shortened.size} test name(s) shortened to fit a key`);
|
|
427
497
|
log(`plune: ${parts.join(" \xB7 ")}`);
|
|
498
|
+
if (stats.deferred > 0 && process.env["GITHUB_ACTIONS"] === "true") {
|
|
499
|
+
log(`::warning::${stats.deferred} result(s) were not delivered to Plune \u2014 see the reporting step's log.`);
|
|
500
|
+
}
|
|
428
501
|
}
|
|
429
502
|
return {
|
|
430
503
|
get runId() {
|
|
@@ -479,10 +552,127 @@ function resultKey(testId, retry) {
|
|
|
479
552
|
const plain = `${testId}#${retry}`;
|
|
480
553
|
return plain.length <= RESULT_KEY_MAX ? plain : `${sha256(testId).slice(0, HASH_CHARS)}#${retry}`;
|
|
481
554
|
}
|
|
555
|
+
function failureOf(attempt, home = homedir2()) {
|
|
556
|
+
const error = chosen(attempt);
|
|
557
|
+
const line = error === void 0 ? void 0 : firstLine(machineless(error.text, attempt.repoRoot, home));
|
|
558
|
+
const headline = line !== void 0 && jsonBytes(line) <= HEADLINE_LIMIT ? line : void 0;
|
|
559
|
+
const steps = chainOf(attempt.steps);
|
|
560
|
+
const location = error === void 0 ? void 0 : fromRoot(placeOf(error, attempt.testFile), attempt.repoRoot);
|
|
561
|
+
const artifacts = attempt.attachments.filter((a) => a.path !== void 0 && !a.name.startsWith("_") && a.contentType !== METADATA_TYPE).map(({ name, contentType }) => ({ name: fileNameOf(name), ...contentType ? { contentType } : {} })).filter((a) => a.name !== "");
|
|
562
|
+
const ciUrl = webLink(attempt.buildHref);
|
|
563
|
+
const failure = {
|
|
564
|
+
...headline !== void 0 ? { headline } : {},
|
|
565
|
+
...steps.length > 0 ? { steps } : {},
|
|
566
|
+
...location !== void 0 ? { location } : {},
|
|
567
|
+
...artifacts.length > 0 ? { artifacts } : {},
|
|
568
|
+
...ciUrl !== void 0 ? { ciUrl } : {}
|
|
569
|
+
};
|
|
570
|
+
return Object.keys(failure).length === 0 ? void 0 : failure;
|
|
571
|
+
}
|
|
572
|
+
function repoRootOf(dir, stopAt) {
|
|
573
|
+
for (let here = resolve(dir); ; here = dirname3(here)) {
|
|
574
|
+
if (existsSync2(join3(here, ".git"))) return here;
|
|
575
|
+
if (here === stopAt || dirname3(here) === here) return void 0;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function errorContextOf(attempt, home = homedir2()) {
|
|
579
|
+
const text = attempt.errors.map((e) => e.text).filter((t) => t !== "").join("\n\n");
|
|
580
|
+
return cut(machineless(text, attempt.repoRoot, home));
|
|
581
|
+
}
|
|
582
|
+
function machineless(raw, repoRoot, home) {
|
|
583
|
+
let text = stripVTControlCharacters(raw).replaceAll("\x1B", "");
|
|
584
|
+
const root = repoRoot === void 0 ? void 0 : pathIn(repoRoot);
|
|
585
|
+
if (root !== void 0) text = text.replace(new RegExp(`${PATH_START}${root.source}[\\\\/]+`, root.flags), "");
|
|
586
|
+
const own = pathIn(home);
|
|
587
|
+
if (own !== void 0) text = text.replace(new RegExp(`${PATH_START}${own.source}(?![\\w.-])`, own.flags), "~");
|
|
588
|
+
if (repoRoot === void 0) text = text.replace(ANY_HOME, "~");
|
|
589
|
+
return text;
|
|
590
|
+
}
|
|
591
|
+
var PATH_START = "(?<![\\w.~%/\\\\-])";
|
|
592
|
+
var TEXT_LIMIT = 524288;
|
|
593
|
+
var HEADLINE_LIMIT = 8 * 1024;
|
|
594
|
+
var jsonBytes = (text) => Buffer.byteLength(JSON.stringify(text)) - 2;
|
|
595
|
+
var ANY_HOME = /(?<=^|[\s'"`(=,[])(?:file:\/\/\/?)?(?:\/home\/|\/Users\/|[A-Za-z]:[\\/]+Users[\\/]+)[^\\/\s'"`:*?<>|]+/g;
|
|
596
|
+
function pathIn(path3) {
|
|
597
|
+
const parts = path3.split(/[\\/]+/);
|
|
598
|
+
while (parts.length > 1 && parts.at(-1) === "") parts.pop();
|
|
599
|
+
if (!parts.some((part) => part !== "" && !/^[A-Za-z]:$/.test(part))) return void 0;
|
|
600
|
+
const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]+");
|
|
601
|
+
return new RegExp(`(?:file:\\/\\/\\/?)?${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
|
|
602
|
+
}
|
|
603
|
+
var fileNameOf = (name) => /^(?:file:\/\/|[\\/]|~[\\/]|[A-Za-z]:[\\/])/.test(name) ? name.split(/[\\/]/).pop() ?? "" : name;
|
|
604
|
+
function cut(text) {
|
|
605
|
+
if (jsonBytes(text) <= TEXT_LIMIT) return text;
|
|
606
|
+
const lines = text.split("\n");
|
|
607
|
+
const size = lines.map((line) => jsonBytes(line) + 2);
|
|
608
|
+
const budget = TEXT_LIMIT - jsonBytes(omitted(lines.length));
|
|
609
|
+
let used = 0;
|
|
610
|
+
let head = 0;
|
|
611
|
+
let tail = lines.length;
|
|
612
|
+
while (head < tail && used + size[head] <= budget / 2) used += size[head++];
|
|
613
|
+
while (tail > head && used + size[tail - 1] <= budget) used += size[--tail];
|
|
614
|
+
return [...lines.slice(0, head), omitted(tail - head), ...lines.slice(tail)].join("\n");
|
|
615
|
+
}
|
|
616
|
+
var omitted = (lines) => `\u2026[omitted ${lines} lines]\u2026`;
|
|
617
|
+
var METADATA_TYPE = "application/plune.metadata+json";
|
|
618
|
+
var REPO_RELATIVE = /^(?![A-Za-z][A-Za-z0-9+.-]*:)(?![\\/~])(?!(?:.*[\\/])?\.\.(?:[\\/]|$)).+$/;
|
|
619
|
+
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
620
|
+
var FRAME_MAX = 8192;
|
|
621
|
+
var firstLine = (text) => stripVTControlCharacters(text).split("\n").map((line) => line.trim()).find((line) => line !== "");
|
|
622
|
+
function chosen({ status, errors }) {
|
|
623
|
+
if (status === "timedOut") {
|
|
624
|
+
const timeout = errors.findIndex((e) => firstLine(e.text)?.startsWith("Test timeout of ") === true);
|
|
625
|
+
if (timeout !== -1 && timeout + 1 < errors.length) return errors[timeout + 1];
|
|
626
|
+
}
|
|
627
|
+
return errors[0];
|
|
628
|
+
}
|
|
629
|
+
function chainOf(steps) {
|
|
630
|
+
const chain = [];
|
|
631
|
+
for (let failed = steps.find((s) => s.failed); failed !== void 0; failed = failed.steps.find((s) => s.failed)) {
|
|
632
|
+
chain.push(failed.title);
|
|
633
|
+
}
|
|
634
|
+
return chain;
|
|
635
|
+
}
|
|
636
|
+
function placeOf(error, testFile) {
|
|
637
|
+
const own = normal(testFile);
|
|
638
|
+
let first;
|
|
639
|
+
for (const line of stripVTControlCharacters(error.text).split("\n")) {
|
|
640
|
+
if (line.length > FRAME_MAX) continue;
|
|
641
|
+
const frame = FRAME.exec(line);
|
|
642
|
+
if (frame === null) continue;
|
|
643
|
+
const place = { file: fileOf(frame[1]), line: Number(frame[2]), column: Number(frame[3]) };
|
|
644
|
+
if (normal(place.file) === own) return place;
|
|
645
|
+
if (first === void 0 && !normal(place.file).includes("/node_modules/")) first = place;
|
|
646
|
+
}
|
|
647
|
+
return error.location ?? first;
|
|
648
|
+
}
|
|
649
|
+
function fileOf(raw) {
|
|
650
|
+
if (!raw.startsWith("file://")) return raw;
|
|
651
|
+
let path3 = raw.slice("file://".length);
|
|
652
|
+
try {
|
|
653
|
+
path3 = decodeURIComponent(path3);
|
|
654
|
+
} catch {
|
|
655
|
+
}
|
|
656
|
+
return /^\/[A-Za-z]:\//.test(path3) ? path3.slice(1) : path3;
|
|
657
|
+
}
|
|
658
|
+
var normal = (path3) => posix.normalize(path3.replace(/\\/g, "/")).replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`);
|
|
659
|
+
function fromRoot(place, root) {
|
|
660
|
+
if (place === void 0 || root === void 0 || !Number.isInteger(place.line) || place.line < 1) return void 0;
|
|
661
|
+
const base = normal(root).replace(/\/+$/, "");
|
|
662
|
+
const file = normal(place.file);
|
|
663
|
+
if (!file.startsWith(`${base}/`)) return void 0;
|
|
664
|
+
const relative = file.slice(base.length + 1);
|
|
665
|
+
if (!REPO_RELATIVE.test(relative)) return void 0;
|
|
666
|
+
const column = place.column !== void 0 && Number.isInteger(place.column) && place.column >= 1 ? place.column : void 0;
|
|
667
|
+
return column === void 0 ? { file: relative, line: place.line } : { file: relative, line: place.line, column };
|
|
668
|
+
}
|
|
669
|
+
function webLink(href) {
|
|
670
|
+
return href !== void 0 && /^https?:\/\//i.test(href) && URL.canParse(href) ? href : void 0;
|
|
671
|
+
}
|
|
482
672
|
|
|
483
673
|
// src/index.ts
|
|
484
674
|
var SOURCE = "playwright";
|
|
485
|
-
function
|
|
675
|
+
function fileOf2(test) {
|
|
486
676
|
for (let suite = test.parent; suite !== void 0; suite = suite.parent) {
|
|
487
677
|
if (suite.type === "file") return suite.title.replace(/\\/g, "/");
|
|
488
678
|
}
|
|
@@ -498,13 +688,13 @@ function titlesOf(test) {
|
|
|
498
688
|
function keysFor(test) {
|
|
499
689
|
return [
|
|
500
690
|
{ kind: "playwright-id", value: test.id },
|
|
501
|
-
{ kind: "path-title", value: [
|
|
691
|
+
{ kind: "path-title", value: [fileOf2(test), ...titlesOf(test)].join("#") }
|
|
502
692
|
];
|
|
503
693
|
}
|
|
504
|
-
var
|
|
694
|
+
var METADATA_TYPE2 = "application/plune.metadata+json";
|
|
505
695
|
var TOKEN = /@P([A-Za-z0-9_-]+)/;
|
|
506
696
|
function metadataOf(result) {
|
|
507
|
-
const found = result.attachments.find((a) => a.contentType ===
|
|
697
|
+
const found = result.attachments.find((a) => a.contentType === METADATA_TYPE2);
|
|
508
698
|
if (found === void 0) return void 0;
|
|
509
699
|
try {
|
|
510
700
|
const raw = found.body !== void 0 ? found.body.toString("utf8") : found.path !== void 0 ? readFileSync2(found.path, "utf8") : void 0;
|
|
@@ -520,14 +710,43 @@ function statedIdOf(test, metadata) {
|
|
|
520
710
|
if (token !== void 0) return token;
|
|
521
711
|
return metadata?.id !== void 0 && metadata.id !== "" ? metadata.id : void 0;
|
|
522
712
|
}
|
|
523
|
-
|
|
524
|
-
|
|
713
|
+
var NOT_FAILED = /* @__PURE__ */ new Set(["passed", "skipped"]);
|
|
714
|
+
function textOf(error) {
|
|
715
|
+
const message = error.message || error.value || "";
|
|
716
|
+
if (!error.stack && !error.location) return message;
|
|
717
|
+
const lines = error.stack?.split("\n") ?? [];
|
|
718
|
+
const at = lines.findIndex((line) => line.startsWith(" at "));
|
|
719
|
+
const tokens = [(at === -1 ? lines : lines.slice(0, at)).join("\n") || message];
|
|
720
|
+
if (error.snippet) tokens.push("", stripVTControlCharacters2(error.snippet));
|
|
721
|
+
if (at !== -1) tokens.push(lines.slice(at).join("\n"));
|
|
722
|
+
if (error.cause) tokens.push(`[cause]: ${textOf(error.cause)}`);
|
|
723
|
+
return tokens.join("\n");
|
|
724
|
+
}
|
|
725
|
+
function declared(steps) {
|
|
726
|
+
return steps.filter((step) => step.category === "test.step").map((step) => ({ title: step.title, failed: step.error !== void 0, steps: declared(step.steps) }));
|
|
727
|
+
}
|
|
728
|
+
function attemptOf(test, result, ctx) {
|
|
729
|
+
return {
|
|
730
|
+
status: result.status,
|
|
731
|
+
errors: result.errors.map((e) => ({ text: textOf(e), ...e.location !== void 0 ? { location: e.location } : {} })),
|
|
732
|
+
steps: declared(result.steps ?? []),
|
|
733
|
+
attachments: result.attachments.map(({ name, contentType, path: path3 }) => ({
|
|
734
|
+
name,
|
|
735
|
+
contentType,
|
|
736
|
+
...path3 !== void 0 ? { path: path3 } : {}
|
|
737
|
+
})),
|
|
738
|
+
...ctx.buildHref !== void 0 ? { buildHref: ctx.buildHref } : {},
|
|
739
|
+
testFile: test.location.file,
|
|
740
|
+
...ctx.repoRoot !== void 0 ? { repoRoot: ctx.repoRoot } : {}
|
|
741
|
+
};
|
|
525
742
|
}
|
|
526
|
-
function pendingFrom(test, result) {
|
|
743
|
+
function pendingFrom(test, result, ctx) {
|
|
527
744
|
const metadata = metadataOf(result);
|
|
528
745
|
const pluneId = statedIdOf(test, metadata);
|
|
529
746
|
const expected = test.expectedStatus;
|
|
530
|
-
const
|
|
747
|
+
const attempt = attemptOf(test, result, ctx);
|
|
748
|
+
const errorContext = errorContextOf(attempt);
|
|
749
|
+
const failure = NOT_FAILED.has(result.status) ? void 0 : failureOf(attempt);
|
|
531
750
|
const startedAt = result.startTime;
|
|
532
751
|
return {
|
|
533
752
|
resultKey: resultKey(test.id, result.retry),
|
|
@@ -541,7 +760,7 @@ function pendingFrom(test, result) {
|
|
|
541
760
|
title: titlesOf(test).join(" \u203A "),
|
|
542
761
|
// The line as well as the file. A reviewer's first move on an unknown test is to open it, and
|
|
543
762
|
// `specRef` is the only thing the entry carries that can take them there.
|
|
544
|
-
specRef: `${
|
|
763
|
+
specRef: `${fileOf2(test)}:${test.location.line}`,
|
|
545
764
|
source: SOURCE,
|
|
546
765
|
// The runner's own word, untouched. Mapping it is the platform's job and a project's setting.
|
|
547
766
|
rawStatus: result.status,
|
|
@@ -555,7 +774,8 @@ function pendingFrom(test, result) {
|
|
|
555
774
|
retry: result.retry,
|
|
556
775
|
worker: String(result.workerIndex)
|
|
557
776
|
},
|
|
558
|
-
...errorContext !== "" ? { errorContext } : {}
|
|
777
|
+
...errorContext !== "" ? { errorContext } : {},
|
|
778
|
+
...failure !== void 0 ? { failure } : {}
|
|
559
779
|
};
|
|
560
780
|
}
|
|
561
781
|
var PluneReporter = class {
|
|
@@ -567,6 +787,9 @@ var PluneReporter = class {
|
|
|
567
787
|
chain = Promise.resolve();
|
|
568
788
|
keepOpen = false;
|
|
569
789
|
complained = false;
|
|
790
|
+
/** Kept whole: `metadata.ci` is written into it after `onConfigure`, so it is read at the run's opening. */
|
|
791
|
+
config = null;
|
|
792
|
+
context = {};
|
|
570
793
|
constructor(options = {}) {
|
|
571
794
|
this.options = options;
|
|
572
795
|
}
|
|
@@ -580,6 +803,9 @@ var PluneReporter = class {
|
|
|
580
803
|
}
|
|
581
804
|
onConfigure(config) {
|
|
582
805
|
this.keepOpen = config.shard !== null && config.shard !== void 0 || readEnv().keepOpen;
|
|
806
|
+
this.config = config;
|
|
807
|
+
const repoRoot = config.rootDir === void 0 ? void 0 : repoRootOf(config.rootDir);
|
|
808
|
+
if (repoRoot !== void 0) this.context = { repoRoot };
|
|
583
809
|
}
|
|
584
810
|
/**
|
|
585
811
|
* Only the list is taken here; the run opens on the first result. `onBegin` also fires for
|
|
@@ -593,6 +819,10 @@ var PluneReporter = class {
|
|
|
593
819
|
}
|
|
594
820
|
open() {
|
|
595
821
|
if (this.session === null) {
|
|
822
|
+
const ci = this.config?.metadata?.["ci"];
|
|
823
|
+
const buildHref = typeof ci === "object" && ci !== null ? ci.buildHref : void 0;
|
|
824
|
+
if (typeof buildHref === "string") this.context = { ...this.context, buildHref };
|
|
825
|
+
const ciUrl = webLink(this.context.buildHref);
|
|
596
826
|
this.session = startRun(
|
|
597
827
|
{
|
|
598
828
|
...this.options.apiUrl !== void 0 ? { apiUrl: this.options.apiUrl } : {},
|
|
@@ -600,7 +830,7 @@ var PluneReporter = class {
|
|
|
600
830
|
...this.options.externalKey !== void 0 ? { externalKey: this.options.externalKey } : {},
|
|
601
831
|
...this.options.batchSize !== void 0 ? { batchSize: this.options.batchSize } : {},
|
|
602
832
|
...this.options.fallbackPath !== void 0 ? { fallbackPath: this.options.fallbackPath } : {},
|
|
603
|
-
meta: { runner: SOURCE }
|
|
833
|
+
meta: { runner: SOURCE, ...ciUrl !== void 0 ? { ciUrl } : {} }
|
|
604
834
|
},
|
|
605
835
|
this.declared
|
|
606
836
|
);
|
|
@@ -610,7 +840,7 @@ var PluneReporter = class {
|
|
|
610
840
|
onTestEnd(test, result) {
|
|
611
841
|
const session = this.open();
|
|
612
842
|
this.chain = this.chain.then(async () => {
|
|
613
|
-
(await session).add(pendingFrom(test, result));
|
|
843
|
+
await (await session).add(pendingFrom(test, result, this.context));
|
|
614
844
|
}).catch((err) => this.giveUp(err));
|
|
615
845
|
}
|
|
616
846
|
async onEnd(_result) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plune-ai/playwright",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Report Playwright results to Plune — a reporter and, later, a test importer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"playwright",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"tsup": "^8.0.0",
|
|
39
39
|
"typescript": "^5.4.0",
|
|
40
40
|
"vitest": "^1.6.0",
|
|
41
|
-
"@plune-ai/cli": "0.
|
|
41
|
+
"@plune-ai/cli": "0.14.1"
|
|
42
42
|
},
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|