@plune-ai/playwright 0.2.4 → 0.2.6
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 +12 -1
- package/dist/index.cjs +263 -38
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +263 -38
- 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 and blob reports, so a token set here travels with any
|
|
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
|
|
@@ -56,6 +59,7 @@ fills in what you left out. Anything set in the config file wins.
|
|
|
56
59
|
| `PLUNE_ENV` | where it ran — `staging`, `prod`, a preview name |
|
|
57
60
|
| `PLUNE_LABELS` | comma-separated marks: `smoke,nightly` |
|
|
58
61
|
| `PLUNE_CREATE` | offer tests Plune has no case for to the review queue |
|
|
62
|
+
| `PLUNE_FULL_RUN` | this run is the whole suite: a case it used to report and did not is marked detached |
|
|
59
63
|
|
|
60
64
|
Flags are read by value, not by presence: `PLUNE_PROCEED=0` in a matrix cell means off.
|
|
61
65
|
|
|
@@ -69,6 +73,13 @@ result: a reporter sees a test's result, not its source, and a body nobody wrote
|
|
|
69
73
|
queue exists to keep out. A person decides whether the project tracks the test; approving attaches
|
|
70
74
|
the keys, so the next run resolves instead of offering it again.
|
|
71
75
|
|
|
76
|
+
`PLUNE_FULL_RUN=1` is the reporter's word that nothing was filtered out — not `-g`, not a file
|
|
77
|
+
argument, not `--only-changed`. When such a run finishes with every expected test reported, the
|
|
78
|
+
platform marks the active cases this reporter used to report and did not this time as **detached**
|
|
79
|
+
(kept, with their history; the run is named as the reason), and prints how many. A later result on
|
|
80
|
+
a detached case makes it active again on its own. Set it on the CI job that runs everything and
|
|
81
|
+
nowhere else; a run that lost a shard never detaches anything.
|
|
82
|
+
|
|
72
83
|
`PLUNE_GROUP` is **not supported yet** — a group of runs is a Plune feature that does not exist, and
|
|
73
84
|
a group of one run means nothing. Setting it prints a line saying it was ignored, rather than
|
|
74
85
|
accepting it and quietly dropping it. If you report to a deployment older than run titles, the
|
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("***");
|
|
@@ -161,6 +200,7 @@ function readEnv(env = process.env) {
|
|
|
161
200
|
const environment = value(env, "PLUNE_ENV");
|
|
162
201
|
const labels = list(env, "PLUNE_LABELS");
|
|
163
202
|
const offerDiscovered = flag(env, "PLUNE_CREATE");
|
|
203
|
+
const full = flag(env, "PLUNE_FULL_RUN");
|
|
164
204
|
return {
|
|
165
205
|
config: {
|
|
166
206
|
...externalKey !== void 0 ? { externalKey } : {},
|
|
@@ -173,7 +213,8 @@ function readEnv(env = process.env) {
|
|
|
173
213
|
...labels !== void 0 ? { labels } : {},
|
|
174
214
|
// Only when set: `false` here would outrank a config file that asked for it, and an unset
|
|
175
215
|
// variable is not an instruction.
|
|
176
|
-
...offerDiscovered ? { offerDiscovered } : {}
|
|
216
|
+
...offerDiscovered ? { offerDiscovered } : {},
|
|
217
|
+
...full ? { full } : {}
|
|
177
218
|
},
|
|
178
219
|
// Two names for two situations that end the same way. `SHARED_RUN` says other processes are
|
|
179
220
|
// reporting into this run; `PROCEED` says the job will close it on its own schedule. Either
|
|
@@ -217,6 +258,25 @@ function boundKey(key) {
|
|
|
217
258
|
function boundTitle(title) {
|
|
218
259
|
return title.length <= TITLE_MAX ? title : `${title.slice(0, TITLE_MAX - 1)}\u2026`;
|
|
219
260
|
}
|
|
261
|
+
var BATCH_BYTES = 8 * 1024 * 1024;
|
|
262
|
+
var ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ results: [] }));
|
|
263
|
+
function packed(results) {
|
|
264
|
+
const out = [];
|
|
265
|
+
let part = [];
|
|
266
|
+
let bytes = ENVELOPE_BYTES;
|
|
267
|
+
for (const result of results) {
|
|
268
|
+
const size = Buffer.byteLength(JSON.stringify(result));
|
|
269
|
+
if (part.length > 0 && bytes + 1 + size > BATCH_BYTES) {
|
|
270
|
+
out.push(part);
|
|
271
|
+
part = [];
|
|
272
|
+
bytes = ENVELOPE_BYTES;
|
|
273
|
+
}
|
|
274
|
+
bytes += (part.length > 0 ? 1 : 0) + size;
|
|
275
|
+
part.push(result);
|
|
276
|
+
}
|
|
277
|
+
if (part.length > 0) out.push(part);
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
220
280
|
function chunk(items, size) {
|
|
221
281
|
const out = [];
|
|
222
282
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
@@ -230,7 +290,7 @@ function warnIfDropped(sent, run, log) {
|
|
|
230
290
|
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
231
291
|
);
|
|
232
292
|
}
|
|
233
|
-
async function startRun(passed,
|
|
293
|
+
async function startRun(passed, declared2) {
|
|
234
294
|
const env = readEnv();
|
|
235
295
|
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
236
296
|
const cfg = { ...env.config, ...stated };
|
|
@@ -279,7 +339,7 @@ async function startRun(passed, declared) {
|
|
|
279
339
|
return fit;
|
|
280
340
|
});
|
|
281
341
|
}
|
|
282
|
-
const expected =
|
|
342
|
+
const expected = declared2?.map(bound);
|
|
283
343
|
if (offline) {
|
|
284
344
|
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
285
345
|
}
|
|
@@ -313,7 +373,11 @@ async function startRun(passed, declared) {
|
|
|
313
373
|
const hit = keys.map((k) => resolved.get(k.value)).find((v) => typeof v === "string");
|
|
314
374
|
if (typeof hit === "string") return [{ testCaseId: hit }];
|
|
315
375
|
return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
|
|
316
|
-
})
|
|
376
|
+
}),
|
|
377
|
+
// The claim travels with the list it is about (D20). A runner that could not enumerate
|
|
378
|
+
// its tests has no list, and a claim without one is nothing the platform can check —
|
|
379
|
+
// so it is not sent, rather than sent and silently meaningless.
|
|
380
|
+
...cfg.full === true ? { full: true } : {}
|
|
317
381
|
};
|
|
318
382
|
if (expected !== void 0 && expected.length > EXPECTED_MAX) {
|
|
319
383
|
log(`plune: ${expected.length} tests is more than the run configuration holds \u2014 reporting the first ${EXPECTED_MAX}.`);
|
|
@@ -414,27 +478,32 @@ async function startRun(passed, declared) {
|
|
|
414
478
|
progress();
|
|
415
479
|
return;
|
|
416
480
|
}
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
481
|
+
for (const part of packed(submissions)) {
|
|
482
|
+
if (offline) {
|
|
483
|
+
defer(part);
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
const out = await client.post(`/v1/runs/${runId}/results`, {
|
|
487
|
+
results: part
|
|
488
|
+
});
|
|
489
|
+
if (out.ok) {
|
|
490
|
+
stats.accepted += out.body.counts.accepted ?? 0;
|
|
491
|
+
stats.duplicate += out.body.counts.duplicate ?? 0;
|
|
492
|
+
stats.conflict += out.body.counts.conflict ?? 0;
|
|
493
|
+
stats.rejected += out.body.counts.rejected ?? 0;
|
|
494
|
+
progress();
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
if (out.kind === "auth") {
|
|
498
|
+
log('plune: the API token was refused \u2014 run "plune login" with a fresh one.');
|
|
499
|
+
offline = true;
|
|
500
|
+
} else if (out.kind === "conflict") {
|
|
501
|
+
log(`plune: this run is closed \u2014 ${out.detail}`);
|
|
502
|
+
} else {
|
|
503
|
+
log(`plune: could not send results (${out.detail || out.kind}).`);
|
|
504
|
+
}
|
|
505
|
+
defer(part);
|
|
436
506
|
}
|
|
437
|
-
defer(submissions);
|
|
438
507
|
}
|
|
439
508
|
function progress() {
|
|
440
509
|
const total = expected?.length ?? 0;
|
|
@@ -450,9 +519,12 @@ async function startRun(passed, declared) {
|
|
|
450
519
|
if (stats.unresolved > 0) parts.push(`${stats.unresolved} with no matching test case`);
|
|
451
520
|
if (stats.offered > 0) parts.push(`${stats.offered} offered for review`);
|
|
452
521
|
if (stats.created > 0) parts.push(`${stats.created} added as cases (trusted source)`);
|
|
453
|
-
if (stats.deferred > 0) parts.push(`${stats.deferred} written to ${fallbackPath}`);
|
|
522
|
+
if (stats.deferred > 0) parts.push(`${stats.deferred} not delivered \u2014 written to ${fallbackPath}`);
|
|
454
523
|
if (shortened.size > 0) parts.push(`${shortened.size} test name(s) shortened to fit a key`);
|
|
455
524
|
log(`plune: ${parts.join(" \xB7 ")}`);
|
|
525
|
+
if (stats.deferred > 0 && process.env["GITHUB_ACTIONS"] === "true") {
|
|
526
|
+
log(`::warning::${stats.deferred} result(s) were not delivered to Plune \u2014 see the reporting step's log.`);
|
|
527
|
+
}
|
|
456
528
|
}
|
|
457
529
|
return {
|
|
458
530
|
get runId() {
|
|
@@ -480,6 +552,9 @@ async function startRun(passed, declared) {
|
|
|
480
552
|
...reason !== void 0 ? { reason } : {}
|
|
481
553
|
});
|
|
482
554
|
if (!out.ok) log(`plune: could not close run ${runId} (${out.detail || out.kind}).`);
|
|
555
|
+
else if (typeof out.body.detached === "number" && out.body.detached > 0) {
|
|
556
|
+
log(`plune: ${out.body.detached} test case(s) marked detached \u2014 this full run no longer reports them.`);
|
|
557
|
+
}
|
|
483
558
|
}
|
|
484
559
|
summarise();
|
|
485
560
|
},
|
|
@@ -504,10 +579,120 @@ function resultKey(testId, retry) {
|
|
|
504
579
|
const plain = `${testId}#${retry}`;
|
|
505
580
|
return plain.length <= RESULT_KEY_MAX ? plain : `${sha256(testId).slice(0, HASH_CHARS)}#${retry}`;
|
|
506
581
|
}
|
|
582
|
+
function failureOf(attempt) {
|
|
583
|
+
const error = chosen(attempt);
|
|
584
|
+
const headline = error === void 0 ? void 0 : firstLine(error.text);
|
|
585
|
+
const steps = chainOf(attempt.steps);
|
|
586
|
+
const location = error === void 0 ? void 0 : fromRoot(placeOf(error, attempt.testFile), attempt.repoRoot);
|
|
587
|
+
const artifacts = attempt.attachments.filter((a) => a.path !== void 0 && a.name !== "" && !a.name.startsWith("_") && a.contentType !== METADATA_TYPE).map(({ name, contentType }) => contentType === void 0 ? { name } : { name, contentType });
|
|
588
|
+
const ciUrl = webLink(attempt.buildHref);
|
|
589
|
+
const failure = {
|
|
590
|
+
...headline !== void 0 ? { headline } : {},
|
|
591
|
+
...steps.length > 0 ? { steps } : {},
|
|
592
|
+
...location !== void 0 ? { location } : {},
|
|
593
|
+
...artifacts.length > 0 ? { artifacts } : {},
|
|
594
|
+
...ciUrl !== void 0 ? { ciUrl } : {}
|
|
595
|
+
};
|
|
596
|
+
return Object.keys(failure).length === 0 ? void 0 : failure;
|
|
597
|
+
}
|
|
598
|
+
function repoRootOf(dir, stopAt) {
|
|
599
|
+
for (let here = (0, import_path2.resolve)(dir); ; here = (0, import_path2.dirname)(here)) {
|
|
600
|
+
if ((0, import_fs2.existsSync)((0, import_path2.join)(here, ".git"))) return here;
|
|
601
|
+
if (here === stopAt || (0, import_path2.dirname)(here) === here) return void 0;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
function errorContextOf(attempt, home = (0, import_os2.homedir)()) {
|
|
605
|
+
let text = (0, import_util.stripVTControlCharacters)(
|
|
606
|
+
attempt.errors.map((e) => e.text).filter((t) => t !== "").join("\n\n")
|
|
607
|
+
).replaceAll("\x1B", "");
|
|
608
|
+
const root = attempt.repoRoot === void 0 ? void 0 : pathIn(attempt.repoRoot);
|
|
609
|
+
if (root !== void 0) text = text.replace(new RegExp(`${root.source}[\\\\/]`, root.flags), "");
|
|
610
|
+
const own = pathIn(home);
|
|
611
|
+
if (own !== void 0) text = text.replace(new RegExp(`${own.source}(?![\\w.-])`, own.flags), "~");
|
|
612
|
+
if (attempt.repoRoot === void 0) text = text.replace(ANY_HOME, "~");
|
|
613
|
+
return cut(text);
|
|
614
|
+
}
|
|
615
|
+
var TEXT_LIMIT = 524288;
|
|
616
|
+
var ANY_HOME = /(?<=^|[\s'"`(=,[])(?:file:\/\/\/?)?(?:\/home\/|\/Users\/|[A-Za-z]:[\\/]Users[\\/])[^\\/\s'"`:*?<>|]+/g;
|
|
617
|
+
function pathIn(path3) {
|
|
618
|
+
const parts = path3.split(/[\\/]+/);
|
|
619
|
+
while (parts.length > 1 && parts.at(-1) === "") parts.pop();
|
|
620
|
+
if (!parts.some((part) => part !== "" && !/^[A-Za-z]:$/.test(part))) return void 0;
|
|
621
|
+
const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]");
|
|
622
|
+
return new RegExp(`(?:file:\\/\\/\\/?)?${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
|
|
623
|
+
}
|
|
624
|
+
function cut(text) {
|
|
625
|
+
if (Buffer.byteLength(text) <= TEXT_LIMIT) return text;
|
|
626
|
+
const lines = text.split("\n");
|
|
627
|
+
const size = lines.map((line) => Buffer.byteLength(line) + 1);
|
|
628
|
+
const budget = TEXT_LIMIT - Buffer.byteLength(omitted(lines.length));
|
|
629
|
+
let used = 0;
|
|
630
|
+
let head = 0;
|
|
631
|
+
let tail = lines.length;
|
|
632
|
+
while (head < tail && used + size[head] <= budget / 2) used += size[head++];
|
|
633
|
+
while (tail > head && used + size[tail - 1] <= budget) used += size[--tail];
|
|
634
|
+
return [...lines.slice(0, head), omitted(tail - head), ...lines.slice(tail)].join("\n");
|
|
635
|
+
}
|
|
636
|
+
var omitted = (lines) => `\u2026[omitted ${lines} lines]\u2026`;
|
|
637
|
+
var METADATA_TYPE = "application/plune.metadata+json";
|
|
638
|
+
var REPO_RELATIVE = /^(?![A-Za-z][A-Za-z0-9+.-]*:)(?![\\/~])(?!(?:.*[\\/])?\.\.(?:[\\/]|$)).+$/;
|
|
639
|
+
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
640
|
+
var firstLine = (text) => (0, import_util.stripVTControlCharacters)(text).split("\n").map((line) => line.trim()).find((line) => line !== "");
|
|
641
|
+
function chosen({ status, errors }) {
|
|
642
|
+
if (status === "timedOut") {
|
|
643
|
+
const timeout = errors.findIndex((e) => firstLine(e.text)?.startsWith("Test timeout of ") === true);
|
|
644
|
+
if (timeout !== -1 && timeout + 1 < errors.length) return errors[timeout + 1];
|
|
645
|
+
}
|
|
646
|
+
return errors[0];
|
|
647
|
+
}
|
|
648
|
+
function chainOf(steps) {
|
|
649
|
+
const chain = [];
|
|
650
|
+
for (let failed = steps.find((s) => s.failed); failed !== void 0; failed = failed.steps.find((s) => s.failed)) {
|
|
651
|
+
chain.push(failed.title);
|
|
652
|
+
}
|
|
653
|
+
return chain;
|
|
654
|
+
}
|
|
655
|
+
function placeOf(error, testFile) {
|
|
656
|
+
const own = normal(testFile);
|
|
657
|
+
let first;
|
|
658
|
+
for (const line of (0, import_util.stripVTControlCharacters)(error.text).split("\n")) {
|
|
659
|
+
const frame = FRAME.exec(line);
|
|
660
|
+
if (frame === null) continue;
|
|
661
|
+
const place = { file: fileOf(frame[1]), line: Number(frame[2]), column: Number(frame[3]) };
|
|
662
|
+
if (normal(place.file) === own) return place;
|
|
663
|
+
if (first === void 0 && !normal(place.file).includes("/node_modules/")) first = place;
|
|
664
|
+
}
|
|
665
|
+
return error.location ?? first;
|
|
666
|
+
}
|
|
667
|
+
function fileOf(raw) {
|
|
668
|
+
if (!raw.startsWith("file://")) return raw;
|
|
669
|
+
const path3 = decodeURIComponent(raw.slice("file://".length));
|
|
670
|
+
return /^\/[A-Za-z]:\//.test(path3) ? path3.slice(1) : path3;
|
|
671
|
+
}
|
|
672
|
+
var normal = (path3) => import_path2.posix.normalize(path3.replace(/\\/g, "/")).replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`);
|
|
673
|
+
function fromRoot(place, root) {
|
|
674
|
+
if (place === void 0 || root === void 0 || !Number.isInteger(place.line) || place.line < 1) return void 0;
|
|
675
|
+
const base = normal(root).replace(/\/+$/, "");
|
|
676
|
+
const file = normal(place.file);
|
|
677
|
+
if (!file.startsWith(`${base}/`)) return void 0;
|
|
678
|
+
const relative = file.slice(base.length + 1);
|
|
679
|
+
if (!REPO_RELATIVE.test(relative)) return void 0;
|
|
680
|
+
const column = place.column !== void 0 && Number.isInteger(place.column) && place.column >= 1 ? place.column : void 0;
|
|
681
|
+
return column === void 0 ? { file: relative, line: place.line } : { file: relative, line: place.line, column };
|
|
682
|
+
}
|
|
683
|
+
function webLink(href) {
|
|
684
|
+
if (href === void 0) return void 0;
|
|
685
|
+
try {
|
|
686
|
+
const { protocol } = new URL(href);
|
|
687
|
+
return protocol === "http:" || protocol === "https:" ? href : void 0;
|
|
688
|
+
} catch {
|
|
689
|
+
return void 0;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
507
692
|
|
|
508
693
|
// src/index.ts
|
|
509
694
|
var SOURCE = "playwright";
|
|
510
|
-
function
|
|
695
|
+
function fileOf2(test) {
|
|
511
696
|
for (let suite = test.parent; suite !== void 0; suite = suite.parent) {
|
|
512
697
|
if (suite.type === "file") return suite.title.replace(/\\/g, "/");
|
|
513
698
|
}
|
|
@@ -523,13 +708,13 @@ function titlesOf(test) {
|
|
|
523
708
|
function keysFor(test) {
|
|
524
709
|
return [
|
|
525
710
|
{ kind: "playwright-id", value: test.id },
|
|
526
|
-
{ kind: "path-title", value: [
|
|
711
|
+
{ kind: "path-title", value: [fileOf2(test), ...titlesOf(test)].join("#") }
|
|
527
712
|
];
|
|
528
713
|
}
|
|
529
|
-
var
|
|
714
|
+
var METADATA_TYPE2 = "application/plune.metadata+json";
|
|
530
715
|
var TOKEN = /@P([A-Za-z0-9_-]+)/;
|
|
531
716
|
function metadataOf(result) {
|
|
532
|
-
const found = result.attachments.find((a) => a.contentType ===
|
|
717
|
+
const found = result.attachments.find((a) => a.contentType === METADATA_TYPE2);
|
|
533
718
|
if (found === void 0) return void 0;
|
|
534
719
|
try {
|
|
535
720
|
const raw = found.body !== void 0 ? found.body.toString("utf8") : found.path !== void 0 ? (0, import_node_fs.readFileSync)(found.path, "utf8") : void 0;
|
|
@@ -545,14 +730,43 @@ function statedIdOf(test, metadata) {
|
|
|
545
730
|
if (token !== void 0) return token;
|
|
546
731
|
return metadata?.id !== void 0 && metadata.id !== "" ? metadata.id : void 0;
|
|
547
732
|
}
|
|
548
|
-
|
|
549
|
-
|
|
733
|
+
var NOT_FAILED = /* @__PURE__ */ new Set(["passed", "skipped"]);
|
|
734
|
+
function textOf(error) {
|
|
735
|
+
const message = error.message || error.value || "";
|
|
736
|
+
if (!error.stack && !error.location) return message;
|
|
737
|
+
const lines = error.stack?.split("\n") ?? [];
|
|
738
|
+
const at = lines.findIndex((line) => line.startsWith(" at "));
|
|
739
|
+
const tokens = [(at === -1 ? lines : lines.slice(0, at)).join("\n") || message];
|
|
740
|
+
if (error.snippet) tokens.push("", (0, import_node_util.stripVTControlCharacters)(error.snippet));
|
|
741
|
+
if (at !== -1) tokens.push(lines.slice(at).join("\n"));
|
|
742
|
+
if (error.cause) tokens.push(`[cause]: ${textOf(error.cause)}`);
|
|
743
|
+
return tokens.join("\n");
|
|
744
|
+
}
|
|
745
|
+
function declared(steps) {
|
|
746
|
+
return steps.filter((step) => step.category === "test.step").map((step) => ({ title: step.title, failed: step.error !== void 0, steps: declared(step.steps) }));
|
|
747
|
+
}
|
|
748
|
+
function attemptOf(test, result, ctx) {
|
|
749
|
+
return {
|
|
750
|
+
status: result.status,
|
|
751
|
+
errors: result.errors.map((e) => ({ text: textOf(e), ...e.location !== void 0 ? { location: e.location } : {} })),
|
|
752
|
+
steps: declared(result.steps ?? []),
|
|
753
|
+
attachments: result.attachments.map(({ name, contentType, path: path3 }) => ({
|
|
754
|
+
name,
|
|
755
|
+
contentType,
|
|
756
|
+
...path3 !== void 0 ? { path: path3 } : {}
|
|
757
|
+
})),
|
|
758
|
+
...ctx.buildHref !== void 0 ? { buildHref: ctx.buildHref } : {},
|
|
759
|
+
testFile: test.location.file,
|
|
760
|
+
...ctx.repoRoot !== void 0 ? { repoRoot: ctx.repoRoot } : {}
|
|
761
|
+
};
|
|
550
762
|
}
|
|
551
|
-
function pendingFrom(test, result) {
|
|
763
|
+
function pendingFrom(test, result, ctx) {
|
|
552
764
|
const metadata = metadataOf(result);
|
|
553
765
|
const pluneId = statedIdOf(test, metadata);
|
|
554
766
|
const expected = test.expectedStatus;
|
|
555
|
-
const
|
|
767
|
+
const attempt = attemptOf(test, result, ctx);
|
|
768
|
+
const errorContext = errorContextOf(attempt);
|
|
769
|
+
const failure = NOT_FAILED.has(result.status) ? void 0 : failureOf(attempt);
|
|
556
770
|
const startedAt = result.startTime;
|
|
557
771
|
return {
|
|
558
772
|
resultKey: resultKey(test.id, result.retry),
|
|
@@ -566,7 +780,7 @@ function pendingFrom(test, result) {
|
|
|
566
780
|
title: titlesOf(test).join(" \u203A "),
|
|
567
781
|
// The line as well as the file. A reviewer's first move on an unknown test is to open it, and
|
|
568
782
|
// `specRef` is the only thing the entry carries that can take them there.
|
|
569
|
-
specRef: `${
|
|
783
|
+
specRef: `${fileOf2(test)}:${test.location.line}`,
|
|
570
784
|
source: SOURCE,
|
|
571
785
|
// The runner's own word, untouched. Mapping it is the platform's job and a project's setting.
|
|
572
786
|
rawStatus: result.status,
|
|
@@ -580,7 +794,8 @@ function pendingFrom(test, result) {
|
|
|
580
794
|
retry: result.retry,
|
|
581
795
|
worker: String(result.workerIndex)
|
|
582
796
|
},
|
|
583
|
-
...errorContext !== "" ? { errorContext } : {}
|
|
797
|
+
...errorContext !== "" ? { errorContext } : {},
|
|
798
|
+
...failure !== void 0 ? { failure } : {}
|
|
584
799
|
};
|
|
585
800
|
}
|
|
586
801
|
var PluneReporter = class {
|
|
@@ -592,6 +807,9 @@ var PluneReporter = class {
|
|
|
592
807
|
chain = Promise.resolve();
|
|
593
808
|
keepOpen = false;
|
|
594
809
|
complained = false;
|
|
810
|
+
/** Kept whole: `metadata.ci` is written into it after `onConfigure`, so it is read at the run's opening. */
|
|
811
|
+
config = null;
|
|
812
|
+
context = {};
|
|
595
813
|
constructor(options = {}) {
|
|
596
814
|
this.options = options;
|
|
597
815
|
}
|
|
@@ -605,6 +823,9 @@ var PluneReporter = class {
|
|
|
605
823
|
}
|
|
606
824
|
onConfigure(config) {
|
|
607
825
|
this.keepOpen = config.shard !== null && config.shard !== void 0 || readEnv().keepOpen;
|
|
826
|
+
this.config = config;
|
|
827
|
+
const repoRoot = config.rootDir === void 0 ? void 0 : repoRootOf(config.rootDir);
|
|
828
|
+
if (repoRoot !== void 0) this.context = { repoRoot };
|
|
608
829
|
}
|
|
609
830
|
/**
|
|
610
831
|
* Only the list is taken here; the run opens on the first result. `onBegin` also fires for
|
|
@@ -618,6 +839,10 @@ var PluneReporter = class {
|
|
|
618
839
|
}
|
|
619
840
|
open() {
|
|
620
841
|
if (this.session === null) {
|
|
842
|
+
const ci = this.config?.metadata?.["ci"];
|
|
843
|
+
const buildHref = typeof ci === "object" && ci !== null ? ci.buildHref : void 0;
|
|
844
|
+
if (typeof buildHref === "string") this.context = { ...this.context, buildHref };
|
|
845
|
+
const ciUrl = webLink(this.context.buildHref);
|
|
621
846
|
this.session = startRun(
|
|
622
847
|
{
|
|
623
848
|
...this.options.apiUrl !== void 0 ? { apiUrl: this.options.apiUrl } : {},
|
|
@@ -625,7 +850,7 @@ var PluneReporter = class {
|
|
|
625
850
|
...this.options.externalKey !== void 0 ? { externalKey: this.options.externalKey } : {},
|
|
626
851
|
...this.options.batchSize !== void 0 ? { batchSize: this.options.batchSize } : {},
|
|
627
852
|
...this.options.fallbackPath !== void 0 ? { fallbackPath: this.options.fallbackPath } : {},
|
|
628
|
-
meta: { runner: SOURCE }
|
|
853
|
+
meta: { runner: SOURCE, ...ciUrl !== void 0 ? { ciUrl } : {} }
|
|
629
854
|
},
|
|
630
855
|
this.declared
|
|
631
856
|
);
|
|
@@ -635,7 +860,7 @@ var PluneReporter = class {
|
|
|
635
860
|
onTestEnd(test, result) {
|
|
636
861
|
const session = this.open();
|
|
637
862
|
this.chain = this.chain.then(async () => {
|
|
638
|
-
(await session).add(pendingFrom(test, result));
|
|
863
|
+
(await session).add(pendingFrom(test, result, this.context));
|
|
639
864
|
}).catch((err) => this.giveUp(err));
|
|
640
865
|
}
|
|
641
866
|
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("***");
|
|
@@ -127,6 +166,7 @@ function readEnv(env = process.env) {
|
|
|
127
166
|
const environment = value(env, "PLUNE_ENV");
|
|
128
167
|
const labels = list(env, "PLUNE_LABELS");
|
|
129
168
|
const offerDiscovered = flag(env, "PLUNE_CREATE");
|
|
169
|
+
const full = flag(env, "PLUNE_FULL_RUN");
|
|
130
170
|
return {
|
|
131
171
|
config: {
|
|
132
172
|
...externalKey !== void 0 ? { externalKey } : {},
|
|
@@ -139,7 +179,8 @@ function readEnv(env = process.env) {
|
|
|
139
179
|
...labels !== void 0 ? { labels } : {},
|
|
140
180
|
// Only when set: `false` here would outrank a config file that asked for it, and an unset
|
|
141
181
|
// variable is not an instruction.
|
|
142
|
-
...offerDiscovered ? { offerDiscovered } : {}
|
|
182
|
+
...offerDiscovered ? { offerDiscovered } : {},
|
|
183
|
+
...full ? { full } : {}
|
|
143
184
|
},
|
|
144
185
|
// Two names for two situations that end the same way. `SHARED_RUN` says other processes are
|
|
145
186
|
// reporting into this run; `PROCEED` says the job will close it on its own schedule. Either
|
|
@@ -183,6 +224,25 @@ function boundKey(key) {
|
|
|
183
224
|
function boundTitle(title) {
|
|
184
225
|
return title.length <= TITLE_MAX ? title : `${title.slice(0, TITLE_MAX - 1)}\u2026`;
|
|
185
226
|
}
|
|
227
|
+
var BATCH_BYTES = 8 * 1024 * 1024;
|
|
228
|
+
var ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ results: [] }));
|
|
229
|
+
function packed(results) {
|
|
230
|
+
const out = [];
|
|
231
|
+
let part = [];
|
|
232
|
+
let bytes = ENVELOPE_BYTES;
|
|
233
|
+
for (const result of results) {
|
|
234
|
+
const size = Buffer.byteLength(JSON.stringify(result));
|
|
235
|
+
if (part.length > 0 && bytes + 1 + size > BATCH_BYTES) {
|
|
236
|
+
out.push(part);
|
|
237
|
+
part = [];
|
|
238
|
+
bytes = ENVELOPE_BYTES;
|
|
239
|
+
}
|
|
240
|
+
bytes += (part.length > 0 ? 1 : 0) + size;
|
|
241
|
+
part.push(result);
|
|
242
|
+
}
|
|
243
|
+
if (part.length > 0) out.push(part);
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
186
246
|
function chunk(items, size) {
|
|
187
247
|
const out = [];
|
|
188
248
|
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
|
@@ -196,7 +256,7 @@ function warnIfDropped(sent, run, log) {
|
|
|
196
256
|
`plune: this deployment stored none of ${names.join(", ")} \u2014 it is older than the fields. The run is otherwise reported in full.`
|
|
197
257
|
);
|
|
198
258
|
}
|
|
199
|
-
async function startRun(passed,
|
|
259
|
+
async function startRun(passed, declared2) {
|
|
200
260
|
const env = readEnv();
|
|
201
261
|
const stated = Object.fromEntries(Object.entries(passed).filter(([, v]) => v !== void 0));
|
|
202
262
|
const cfg = { ...env.config, ...stated };
|
|
@@ -245,7 +305,7 @@ async function startRun(passed, declared) {
|
|
|
245
305
|
return fit;
|
|
246
306
|
});
|
|
247
307
|
}
|
|
248
|
-
const expected =
|
|
308
|
+
const expected = declared2?.map(bound);
|
|
249
309
|
if (offline) {
|
|
250
310
|
log('plune: no API token \u2014 run "plune login" first. Results will be written to the fallback file.');
|
|
251
311
|
}
|
|
@@ -279,7 +339,11 @@ async function startRun(passed, declared) {
|
|
|
279
339
|
const hit = keys.map((k) => resolved.get(k.value)).find((v) => typeof v === "string");
|
|
280
340
|
if (typeof hit === "string") return [{ testCaseId: hit }];
|
|
281
341
|
return keys[0] === void 0 ? [] : [{ externalKey: keys[0] }];
|
|
282
|
-
})
|
|
342
|
+
}),
|
|
343
|
+
// The claim travels with the list it is about (D20). A runner that could not enumerate
|
|
344
|
+
// its tests has no list, and a claim without one is nothing the platform can check —
|
|
345
|
+
// so it is not sent, rather than sent and silently meaningless.
|
|
346
|
+
...cfg.full === true ? { full: true } : {}
|
|
283
347
|
};
|
|
284
348
|
if (expected !== void 0 && expected.length > EXPECTED_MAX) {
|
|
285
349
|
log(`plune: ${expected.length} tests is more than the run configuration holds \u2014 reporting the first ${EXPECTED_MAX}.`);
|
|
@@ -380,27 +444,32 @@ async function startRun(passed, declared) {
|
|
|
380
444
|
progress();
|
|
381
445
|
return;
|
|
382
446
|
}
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
447
|
+
for (const part of packed(submissions)) {
|
|
448
|
+
if (offline) {
|
|
449
|
+
defer(part);
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
const out = await client.post(`/v1/runs/${runId}/results`, {
|
|
453
|
+
results: part
|
|
454
|
+
});
|
|
455
|
+
if (out.ok) {
|
|
456
|
+
stats.accepted += out.body.counts.accepted ?? 0;
|
|
457
|
+
stats.duplicate += out.body.counts.duplicate ?? 0;
|
|
458
|
+
stats.conflict += out.body.counts.conflict ?? 0;
|
|
459
|
+
stats.rejected += out.body.counts.rejected ?? 0;
|
|
460
|
+
progress();
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (out.kind === "auth") {
|
|
464
|
+
log('plune: the API token was refused \u2014 run "plune login" with a fresh one.');
|
|
465
|
+
offline = true;
|
|
466
|
+
} else if (out.kind === "conflict") {
|
|
467
|
+
log(`plune: this run is closed \u2014 ${out.detail}`);
|
|
468
|
+
} else {
|
|
469
|
+
log(`plune: could not send results (${out.detail || out.kind}).`);
|
|
470
|
+
}
|
|
471
|
+
defer(part);
|
|
402
472
|
}
|
|
403
|
-
defer(submissions);
|
|
404
473
|
}
|
|
405
474
|
function progress() {
|
|
406
475
|
const total = expected?.length ?? 0;
|
|
@@ -416,9 +485,12 @@ async function startRun(passed, declared) {
|
|
|
416
485
|
if (stats.unresolved > 0) parts.push(`${stats.unresolved} with no matching test case`);
|
|
417
486
|
if (stats.offered > 0) parts.push(`${stats.offered} offered for review`);
|
|
418
487
|
if (stats.created > 0) parts.push(`${stats.created} added as cases (trusted source)`);
|
|
419
|
-
if (stats.deferred > 0) parts.push(`${stats.deferred} written to ${fallbackPath}`);
|
|
488
|
+
if (stats.deferred > 0) parts.push(`${stats.deferred} not delivered \u2014 written to ${fallbackPath}`);
|
|
420
489
|
if (shortened.size > 0) parts.push(`${shortened.size} test name(s) shortened to fit a key`);
|
|
421
490
|
log(`plune: ${parts.join(" \xB7 ")}`);
|
|
491
|
+
if (stats.deferred > 0 && process.env["GITHUB_ACTIONS"] === "true") {
|
|
492
|
+
log(`::warning::${stats.deferred} result(s) were not delivered to Plune \u2014 see the reporting step's log.`);
|
|
493
|
+
}
|
|
422
494
|
}
|
|
423
495
|
return {
|
|
424
496
|
get runId() {
|
|
@@ -446,6 +518,9 @@ async function startRun(passed, declared) {
|
|
|
446
518
|
...reason !== void 0 ? { reason } : {}
|
|
447
519
|
});
|
|
448
520
|
if (!out.ok) log(`plune: could not close run ${runId} (${out.detail || out.kind}).`);
|
|
521
|
+
else if (typeof out.body.detached === "number" && out.body.detached > 0) {
|
|
522
|
+
log(`plune: ${out.body.detached} test case(s) marked detached \u2014 this full run no longer reports them.`);
|
|
523
|
+
}
|
|
449
524
|
}
|
|
450
525
|
summarise();
|
|
451
526
|
},
|
|
@@ -470,10 +545,120 @@ function resultKey(testId, retry) {
|
|
|
470
545
|
const plain = `${testId}#${retry}`;
|
|
471
546
|
return plain.length <= RESULT_KEY_MAX ? plain : `${sha256(testId).slice(0, HASH_CHARS)}#${retry}`;
|
|
472
547
|
}
|
|
548
|
+
function failureOf(attempt) {
|
|
549
|
+
const error = chosen(attempt);
|
|
550
|
+
const headline = error === void 0 ? void 0 : firstLine(error.text);
|
|
551
|
+
const steps = chainOf(attempt.steps);
|
|
552
|
+
const location = error === void 0 ? void 0 : fromRoot(placeOf(error, attempt.testFile), attempt.repoRoot);
|
|
553
|
+
const artifacts = attempt.attachments.filter((a) => a.path !== void 0 && a.name !== "" && !a.name.startsWith("_") && a.contentType !== METADATA_TYPE).map(({ name, contentType }) => contentType === void 0 ? { name } : { name, contentType });
|
|
554
|
+
const ciUrl = webLink(attempt.buildHref);
|
|
555
|
+
const failure = {
|
|
556
|
+
...headline !== void 0 ? { headline } : {},
|
|
557
|
+
...steps.length > 0 ? { steps } : {},
|
|
558
|
+
...location !== void 0 ? { location } : {},
|
|
559
|
+
...artifacts.length > 0 ? { artifacts } : {},
|
|
560
|
+
...ciUrl !== void 0 ? { ciUrl } : {}
|
|
561
|
+
};
|
|
562
|
+
return Object.keys(failure).length === 0 ? void 0 : failure;
|
|
563
|
+
}
|
|
564
|
+
function repoRootOf(dir, stopAt) {
|
|
565
|
+
for (let here = resolve(dir); ; here = dirname3(here)) {
|
|
566
|
+
if (existsSync2(join3(here, ".git"))) return here;
|
|
567
|
+
if (here === stopAt || dirname3(here) === here) return void 0;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
function errorContextOf(attempt, home = homedir2()) {
|
|
571
|
+
let text = stripVTControlCharacters(
|
|
572
|
+
attempt.errors.map((e) => e.text).filter((t) => t !== "").join("\n\n")
|
|
573
|
+
).replaceAll("\x1B", "");
|
|
574
|
+
const root = attempt.repoRoot === void 0 ? void 0 : pathIn(attempt.repoRoot);
|
|
575
|
+
if (root !== void 0) text = text.replace(new RegExp(`${root.source}[\\\\/]`, root.flags), "");
|
|
576
|
+
const own = pathIn(home);
|
|
577
|
+
if (own !== void 0) text = text.replace(new RegExp(`${own.source}(?![\\w.-])`, own.flags), "~");
|
|
578
|
+
if (attempt.repoRoot === void 0) text = text.replace(ANY_HOME, "~");
|
|
579
|
+
return cut(text);
|
|
580
|
+
}
|
|
581
|
+
var TEXT_LIMIT = 524288;
|
|
582
|
+
var ANY_HOME = /(?<=^|[\s'"`(=,[])(?:file:\/\/\/?)?(?:\/home\/|\/Users\/|[A-Za-z]:[\\/]Users[\\/])[^\\/\s'"`:*?<>|]+/g;
|
|
583
|
+
function pathIn(path3) {
|
|
584
|
+
const parts = path3.split(/[\\/]+/);
|
|
585
|
+
while (parts.length > 1 && parts.at(-1) === "") parts.pop();
|
|
586
|
+
if (!parts.some((part) => part !== "" && !/^[A-Za-z]:$/.test(part))) return void 0;
|
|
587
|
+
const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]");
|
|
588
|
+
return new RegExp(`(?:file:\\/\\/\\/?)?${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
|
|
589
|
+
}
|
|
590
|
+
function cut(text) {
|
|
591
|
+
if (Buffer.byteLength(text) <= TEXT_LIMIT) return text;
|
|
592
|
+
const lines = text.split("\n");
|
|
593
|
+
const size = lines.map((line) => Buffer.byteLength(line) + 1);
|
|
594
|
+
const budget = TEXT_LIMIT - Buffer.byteLength(omitted(lines.length));
|
|
595
|
+
let used = 0;
|
|
596
|
+
let head = 0;
|
|
597
|
+
let tail = lines.length;
|
|
598
|
+
while (head < tail && used + size[head] <= budget / 2) used += size[head++];
|
|
599
|
+
while (tail > head && used + size[tail - 1] <= budget) used += size[--tail];
|
|
600
|
+
return [...lines.slice(0, head), omitted(tail - head), ...lines.slice(tail)].join("\n");
|
|
601
|
+
}
|
|
602
|
+
var omitted = (lines) => `\u2026[omitted ${lines} lines]\u2026`;
|
|
603
|
+
var METADATA_TYPE = "application/plune.metadata+json";
|
|
604
|
+
var REPO_RELATIVE = /^(?![A-Za-z][A-Za-z0-9+.-]*:)(?![\\/~])(?!(?:.*[\\/])?\.\.(?:[\\/]|$)).+$/;
|
|
605
|
+
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
606
|
+
var firstLine = (text) => stripVTControlCharacters(text).split("\n").map((line) => line.trim()).find((line) => line !== "");
|
|
607
|
+
function chosen({ status, errors }) {
|
|
608
|
+
if (status === "timedOut") {
|
|
609
|
+
const timeout = errors.findIndex((e) => firstLine(e.text)?.startsWith("Test timeout of ") === true);
|
|
610
|
+
if (timeout !== -1 && timeout + 1 < errors.length) return errors[timeout + 1];
|
|
611
|
+
}
|
|
612
|
+
return errors[0];
|
|
613
|
+
}
|
|
614
|
+
function chainOf(steps) {
|
|
615
|
+
const chain = [];
|
|
616
|
+
for (let failed = steps.find((s) => s.failed); failed !== void 0; failed = failed.steps.find((s) => s.failed)) {
|
|
617
|
+
chain.push(failed.title);
|
|
618
|
+
}
|
|
619
|
+
return chain;
|
|
620
|
+
}
|
|
621
|
+
function placeOf(error, testFile) {
|
|
622
|
+
const own = normal(testFile);
|
|
623
|
+
let first;
|
|
624
|
+
for (const line of stripVTControlCharacters(error.text).split("\n")) {
|
|
625
|
+
const frame = FRAME.exec(line);
|
|
626
|
+
if (frame === null) continue;
|
|
627
|
+
const place = { file: fileOf(frame[1]), line: Number(frame[2]), column: Number(frame[3]) };
|
|
628
|
+
if (normal(place.file) === own) return place;
|
|
629
|
+
if (first === void 0 && !normal(place.file).includes("/node_modules/")) first = place;
|
|
630
|
+
}
|
|
631
|
+
return error.location ?? first;
|
|
632
|
+
}
|
|
633
|
+
function fileOf(raw) {
|
|
634
|
+
if (!raw.startsWith("file://")) return raw;
|
|
635
|
+
const path3 = decodeURIComponent(raw.slice("file://".length));
|
|
636
|
+
return /^\/[A-Za-z]:\//.test(path3) ? path3.slice(1) : path3;
|
|
637
|
+
}
|
|
638
|
+
var normal = (path3) => posix.normalize(path3.replace(/\\/g, "/")).replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`);
|
|
639
|
+
function fromRoot(place, root) {
|
|
640
|
+
if (place === void 0 || root === void 0 || !Number.isInteger(place.line) || place.line < 1) return void 0;
|
|
641
|
+
const base = normal(root).replace(/\/+$/, "");
|
|
642
|
+
const file = normal(place.file);
|
|
643
|
+
if (!file.startsWith(`${base}/`)) return void 0;
|
|
644
|
+
const relative = file.slice(base.length + 1);
|
|
645
|
+
if (!REPO_RELATIVE.test(relative)) return void 0;
|
|
646
|
+
const column = place.column !== void 0 && Number.isInteger(place.column) && place.column >= 1 ? place.column : void 0;
|
|
647
|
+
return column === void 0 ? { file: relative, line: place.line } : { file: relative, line: place.line, column };
|
|
648
|
+
}
|
|
649
|
+
function webLink(href) {
|
|
650
|
+
if (href === void 0) return void 0;
|
|
651
|
+
try {
|
|
652
|
+
const { protocol } = new URL(href);
|
|
653
|
+
return protocol === "http:" || protocol === "https:" ? href : void 0;
|
|
654
|
+
} catch {
|
|
655
|
+
return void 0;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
473
658
|
|
|
474
659
|
// src/index.ts
|
|
475
660
|
var SOURCE = "playwright";
|
|
476
|
-
function
|
|
661
|
+
function fileOf2(test) {
|
|
477
662
|
for (let suite = test.parent; suite !== void 0; suite = suite.parent) {
|
|
478
663
|
if (suite.type === "file") return suite.title.replace(/\\/g, "/");
|
|
479
664
|
}
|
|
@@ -489,13 +674,13 @@ function titlesOf(test) {
|
|
|
489
674
|
function keysFor(test) {
|
|
490
675
|
return [
|
|
491
676
|
{ kind: "playwright-id", value: test.id },
|
|
492
|
-
{ kind: "path-title", value: [
|
|
677
|
+
{ kind: "path-title", value: [fileOf2(test), ...titlesOf(test)].join("#") }
|
|
493
678
|
];
|
|
494
679
|
}
|
|
495
|
-
var
|
|
680
|
+
var METADATA_TYPE2 = "application/plune.metadata+json";
|
|
496
681
|
var TOKEN = /@P([A-Za-z0-9_-]+)/;
|
|
497
682
|
function metadataOf(result) {
|
|
498
|
-
const found = result.attachments.find((a) => a.contentType ===
|
|
683
|
+
const found = result.attachments.find((a) => a.contentType === METADATA_TYPE2);
|
|
499
684
|
if (found === void 0) return void 0;
|
|
500
685
|
try {
|
|
501
686
|
const raw = found.body !== void 0 ? found.body.toString("utf8") : found.path !== void 0 ? readFileSync2(found.path, "utf8") : void 0;
|
|
@@ -511,14 +696,43 @@ function statedIdOf(test, metadata) {
|
|
|
511
696
|
if (token !== void 0) return token;
|
|
512
697
|
return metadata?.id !== void 0 && metadata.id !== "" ? metadata.id : void 0;
|
|
513
698
|
}
|
|
514
|
-
|
|
515
|
-
|
|
699
|
+
var NOT_FAILED = /* @__PURE__ */ new Set(["passed", "skipped"]);
|
|
700
|
+
function textOf(error) {
|
|
701
|
+
const message = error.message || error.value || "";
|
|
702
|
+
if (!error.stack && !error.location) return message;
|
|
703
|
+
const lines = error.stack?.split("\n") ?? [];
|
|
704
|
+
const at = lines.findIndex((line) => line.startsWith(" at "));
|
|
705
|
+
const tokens = [(at === -1 ? lines : lines.slice(0, at)).join("\n") || message];
|
|
706
|
+
if (error.snippet) tokens.push("", stripVTControlCharacters2(error.snippet));
|
|
707
|
+
if (at !== -1) tokens.push(lines.slice(at).join("\n"));
|
|
708
|
+
if (error.cause) tokens.push(`[cause]: ${textOf(error.cause)}`);
|
|
709
|
+
return tokens.join("\n");
|
|
710
|
+
}
|
|
711
|
+
function declared(steps) {
|
|
712
|
+
return steps.filter((step) => step.category === "test.step").map((step) => ({ title: step.title, failed: step.error !== void 0, steps: declared(step.steps) }));
|
|
713
|
+
}
|
|
714
|
+
function attemptOf(test, result, ctx) {
|
|
715
|
+
return {
|
|
716
|
+
status: result.status,
|
|
717
|
+
errors: result.errors.map((e) => ({ text: textOf(e), ...e.location !== void 0 ? { location: e.location } : {} })),
|
|
718
|
+
steps: declared(result.steps ?? []),
|
|
719
|
+
attachments: result.attachments.map(({ name, contentType, path: path3 }) => ({
|
|
720
|
+
name,
|
|
721
|
+
contentType,
|
|
722
|
+
...path3 !== void 0 ? { path: path3 } : {}
|
|
723
|
+
})),
|
|
724
|
+
...ctx.buildHref !== void 0 ? { buildHref: ctx.buildHref } : {},
|
|
725
|
+
testFile: test.location.file,
|
|
726
|
+
...ctx.repoRoot !== void 0 ? { repoRoot: ctx.repoRoot } : {}
|
|
727
|
+
};
|
|
516
728
|
}
|
|
517
|
-
function pendingFrom(test, result) {
|
|
729
|
+
function pendingFrom(test, result, ctx) {
|
|
518
730
|
const metadata = metadataOf(result);
|
|
519
731
|
const pluneId = statedIdOf(test, metadata);
|
|
520
732
|
const expected = test.expectedStatus;
|
|
521
|
-
const
|
|
733
|
+
const attempt = attemptOf(test, result, ctx);
|
|
734
|
+
const errorContext = errorContextOf(attempt);
|
|
735
|
+
const failure = NOT_FAILED.has(result.status) ? void 0 : failureOf(attempt);
|
|
522
736
|
const startedAt = result.startTime;
|
|
523
737
|
return {
|
|
524
738
|
resultKey: resultKey(test.id, result.retry),
|
|
@@ -532,7 +746,7 @@ function pendingFrom(test, result) {
|
|
|
532
746
|
title: titlesOf(test).join(" \u203A "),
|
|
533
747
|
// The line as well as the file. A reviewer's first move on an unknown test is to open it, and
|
|
534
748
|
// `specRef` is the only thing the entry carries that can take them there.
|
|
535
|
-
specRef: `${
|
|
749
|
+
specRef: `${fileOf2(test)}:${test.location.line}`,
|
|
536
750
|
source: SOURCE,
|
|
537
751
|
// The runner's own word, untouched. Mapping it is the platform's job and a project's setting.
|
|
538
752
|
rawStatus: result.status,
|
|
@@ -546,7 +760,8 @@ function pendingFrom(test, result) {
|
|
|
546
760
|
retry: result.retry,
|
|
547
761
|
worker: String(result.workerIndex)
|
|
548
762
|
},
|
|
549
|
-
...errorContext !== "" ? { errorContext } : {}
|
|
763
|
+
...errorContext !== "" ? { errorContext } : {},
|
|
764
|
+
...failure !== void 0 ? { failure } : {}
|
|
550
765
|
};
|
|
551
766
|
}
|
|
552
767
|
var PluneReporter = class {
|
|
@@ -558,6 +773,9 @@ var PluneReporter = class {
|
|
|
558
773
|
chain = Promise.resolve();
|
|
559
774
|
keepOpen = false;
|
|
560
775
|
complained = false;
|
|
776
|
+
/** Kept whole: `metadata.ci` is written into it after `onConfigure`, so it is read at the run's opening. */
|
|
777
|
+
config = null;
|
|
778
|
+
context = {};
|
|
561
779
|
constructor(options = {}) {
|
|
562
780
|
this.options = options;
|
|
563
781
|
}
|
|
@@ -571,6 +789,9 @@ var PluneReporter = class {
|
|
|
571
789
|
}
|
|
572
790
|
onConfigure(config) {
|
|
573
791
|
this.keepOpen = config.shard !== null && config.shard !== void 0 || readEnv().keepOpen;
|
|
792
|
+
this.config = config;
|
|
793
|
+
const repoRoot = config.rootDir === void 0 ? void 0 : repoRootOf(config.rootDir);
|
|
794
|
+
if (repoRoot !== void 0) this.context = { repoRoot };
|
|
574
795
|
}
|
|
575
796
|
/**
|
|
576
797
|
* Only the list is taken here; the run opens on the first result. `onBegin` also fires for
|
|
@@ -584,6 +805,10 @@ var PluneReporter = class {
|
|
|
584
805
|
}
|
|
585
806
|
open() {
|
|
586
807
|
if (this.session === null) {
|
|
808
|
+
const ci = this.config?.metadata?.["ci"];
|
|
809
|
+
const buildHref = typeof ci === "object" && ci !== null ? ci.buildHref : void 0;
|
|
810
|
+
if (typeof buildHref === "string") this.context = { ...this.context, buildHref };
|
|
811
|
+
const ciUrl = webLink(this.context.buildHref);
|
|
587
812
|
this.session = startRun(
|
|
588
813
|
{
|
|
589
814
|
...this.options.apiUrl !== void 0 ? { apiUrl: this.options.apiUrl } : {},
|
|
@@ -591,7 +816,7 @@ var PluneReporter = class {
|
|
|
591
816
|
...this.options.externalKey !== void 0 ? { externalKey: this.options.externalKey } : {},
|
|
592
817
|
...this.options.batchSize !== void 0 ? { batchSize: this.options.batchSize } : {},
|
|
593
818
|
...this.options.fallbackPath !== void 0 ? { fallbackPath: this.options.fallbackPath } : {},
|
|
594
|
-
meta: { runner: SOURCE }
|
|
819
|
+
meta: { runner: SOURCE, ...ciUrl !== void 0 ? { ciUrl } : {} }
|
|
595
820
|
},
|
|
596
821
|
this.declared
|
|
597
822
|
);
|
|
@@ -601,7 +826,7 @@ var PluneReporter = class {
|
|
|
601
826
|
onTestEnd(test, result) {
|
|
602
827
|
const session = this.open();
|
|
603
828
|
this.chain = this.chain.then(async () => {
|
|
604
|
-
(await session).add(pendingFrom(test, result));
|
|
829
|
+
(await session).add(pendingFrom(test, result, this.context));
|
|
605
830
|
}).catch((err) => this.giveUp(err));
|
|
606
831
|
}
|
|
607
832
|
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.6",
|
|
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.0"
|
|
42
42
|
},
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|