@plune-ai/playwright 0.2.6 → 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 +1 -1
- package/dist/index.cjs +46 -32
- package/dist/index.js +46 -32
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ That is the whole setup. Options, if you want them:
|
|
|
38
38
|
```
|
|
39
39
|
|
|
40
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
|
|
41
|
+
writes every reporter's options into its JSON report, so a token set here travels with any such
|
|
42
42
|
report a CI job keeps as an artifact.
|
|
43
43
|
|
|
44
44
|
## From CI, without editing the config
|
package/dist/index.cjs
CHANGED
|
@@ -152,7 +152,11 @@ function createClient(opts) {
|
|
|
152
152
|
}
|
|
153
153
|
if (res.ok) {
|
|
154
154
|
if (res.status === 204) return { ok: true, status: res.status, body: void 0 };
|
|
155
|
-
|
|
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
|
+
}
|
|
156
160
|
}
|
|
157
161
|
const detail = scrub(await detailOf(res));
|
|
158
162
|
const kind = classify(res.status);
|
|
@@ -486,15 +490,18 @@ async function startRun(passed, declared2) {
|
|
|
486
490
|
const out = await client.post(`/v1/runs/${runId}/results`, {
|
|
487
491
|
results: part
|
|
488
492
|
});
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
stats.
|
|
492
|
-
stats.
|
|
493
|
-
stats.
|
|
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;
|
|
494
499
|
progress();
|
|
495
500
|
continue;
|
|
496
501
|
}
|
|
497
|
-
if (out.
|
|
502
|
+
if (out.ok) {
|
|
503
|
+
log("plune: could not send results (the answer carried no counts).");
|
|
504
|
+
} else if (out.kind === "auth") {
|
|
498
505
|
log('plune: the API token was refused \u2014 run "plune login" with a fresh one.');
|
|
499
506
|
offline = true;
|
|
500
507
|
} else if (out.kind === "conflict") {
|
|
@@ -579,12 +586,13 @@ function resultKey(testId, retry) {
|
|
|
579
586
|
const plain = `${testId}#${retry}`;
|
|
580
587
|
return plain.length <= RESULT_KEY_MAX ? plain : `${sha256(testId).slice(0, HASH_CHARS)}#${retry}`;
|
|
581
588
|
}
|
|
582
|
-
function failureOf(attempt) {
|
|
589
|
+
function failureOf(attempt, home = (0, import_os2.homedir)()) {
|
|
583
590
|
const error = chosen(attempt);
|
|
584
|
-
const
|
|
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;
|
|
585
593
|
const steps = chainOf(attempt.steps);
|
|
586
594
|
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 &&
|
|
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 !== "");
|
|
588
596
|
const ciUrl = webLink(attempt.buildHref);
|
|
589
597
|
const failure = {
|
|
590
598
|
...headline !== void 0 ? { headline } : {},
|
|
@@ -602,30 +610,36 @@ function repoRootOf(dir, stopAt) {
|
|
|
602
610
|
}
|
|
603
611
|
}
|
|
604
612
|
function errorContextOf(attempt, home = (0, import_os2.homedir)()) {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
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), "");
|
|
610
620
|
const own = pathIn(home);
|
|
611
|
-
if (own !== void 0) text = text.replace(new RegExp(`${own.source}(?![\\w.-])`, own.flags), "~");
|
|
612
|
-
if (
|
|
613
|
-
return
|
|
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;
|
|
614
624
|
}
|
|
625
|
+
var PATH_START = "(?<![\\w.~%/\\\\-])";
|
|
615
626
|
var TEXT_LIMIT = 524288;
|
|
616
|
-
var
|
|
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;
|
|
617
630
|
function pathIn(path3) {
|
|
618
631
|
const parts = path3.split(/[\\/]+/);
|
|
619
632
|
while (parts.length > 1 && parts.at(-1) === "") parts.pop();
|
|
620
633
|
if (!parts.some((part) => part !== "" && !/^[A-Za-z]:$/.test(part))) return void 0;
|
|
621
|
-
const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]");
|
|
634
|
+
const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]+");
|
|
622
635
|
return new RegExp(`(?:file:\\/\\/\\/?)?${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
|
|
623
636
|
}
|
|
637
|
+
var fileNameOf = (name) => /^(?:file:\/\/|[\\/]|~[\\/]|[A-Za-z]:[\\/])/.test(name) ? name.split(/[\\/]/).pop() ?? "" : name;
|
|
624
638
|
function cut(text) {
|
|
625
|
-
if (
|
|
639
|
+
if (jsonBytes(text) <= TEXT_LIMIT) return text;
|
|
626
640
|
const lines = text.split("\n");
|
|
627
|
-
const size = lines.map((line) =>
|
|
628
|
-
const budget = TEXT_LIMIT -
|
|
641
|
+
const size = lines.map((line) => jsonBytes(line) + 2);
|
|
642
|
+
const budget = TEXT_LIMIT - jsonBytes(omitted(lines.length));
|
|
629
643
|
let used = 0;
|
|
630
644
|
let head = 0;
|
|
631
645
|
let tail = lines.length;
|
|
@@ -637,6 +651,7 @@ var omitted = (lines) => `\u2026[omitted ${lines} lines]\u2026`;
|
|
|
637
651
|
var METADATA_TYPE = "application/plune.metadata+json";
|
|
638
652
|
var REPO_RELATIVE = /^(?![A-Za-z][A-Za-z0-9+.-]*:)(?![\\/~])(?!(?:.*[\\/])?\.\.(?:[\\/]|$)).+$/;
|
|
639
653
|
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
654
|
+
var FRAME_MAX = 8192;
|
|
640
655
|
var firstLine = (text) => (0, import_util.stripVTControlCharacters)(text).split("\n").map((line) => line.trim()).find((line) => line !== "");
|
|
641
656
|
function chosen({ status, errors }) {
|
|
642
657
|
if (status === "timedOut") {
|
|
@@ -656,6 +671,7 @@ function placeOf(error, testFile) {
|
|
|
656
671
|
const own = normal(testFile);
|
|
657
672
|
let first;
|
|
658
673
|
for (const line of (0, import_util.stripVTControlCharacters)(error.text).split("\n")) {
|
|
674
|
+
if (line.length > FRAME_MAX) continue;
|
|
659
675
|
const frame = FRAME.exec(line);
|
|
660
676
|
if (frame === null) continue;
|
|
661
677
|
const place = { file: fileOf(frame[1]), line: Number(frame[2]), column: Number(frame[3]) };
|
|
@@ -666,7 +682,11 @@ function placeOf(error, testFile) {
|
|
|
666
682
|
}
|
|
667
683
|
function fileOf(raw) {
|
|
668
684
|
if (!raw.startsWith("file://")) return raw;
|
|
669
|
-
|
|
685
|
+
let path3 = raw.slice("file://".length);
|
|
686
|
+
try {
|
|
687
|
+
path3 = decodeURIComponent(path3);
|
|
688
|
+
} catch {
|
|
689
|
+
}
|
|
670
690
|
return /^\/[A-Za-z]:\//.test(path3) ? path3.slice(1) : path3;
|
|
671
691
|
}
|
|
672
692
|
var normal = (path3) => import_path2.posix.normalize(path3.replace(/\\/g, "/")).replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`);
|
|
@@ -681,13 +701,7 @@ function fromRoot(place, root) {
|
|
|
681
701
|
return column === void 0 ? { file: relative, line: place.line } : { file: relative, line: place.line, column };
|
|
682
702
|
}
|
|
683
703
|
function webLink(href) {
|
|
684
|
-
|
|
685
|
-
try {
|
|
686
|
-
const { protocol } = new URL(href);
|
|
687
|
-
return protocol === "http:" || protocol === "https:" ? href : void 0;
|
|
688
|
-
} catch {
|
|
689
|
-
return void 0;
|
|
690
|
-
}
|
|
704
|
+
return href !== void 0 && /^https?:\/\//i.test(href) && URL.canParse(href) ? href : void 0;
|
|
691
705
|
}
|
|
692
706
|
|
|
693
707
|
// src/index.ts
|
|
@@ -860,7 +874,7 @@ var PluneReporter = class {
|
|
|
860
874
|
onTestEnd(test, result) {
|
|
861
875
|
const session = this.open();
|
|
862
876
|
this.chain = this.chain.then(async () => {
|
|
863
|
-
(await session).add(pendingFrom(test, result, this.context));
|
|
877
|
+
await (await session).add(pendingFrom(test, result, this.context));
|
|
864
878
|
}).catch((err) => this.giveUp(err));
|
|
865
879
|
}
|
|
866
880
|
async onEnd(_result) {
|
package/dist/index.js
CHANGED
|
@@ -118,7 +118,11 @@ function createClient(opts) {
|
|
|
118
118
|
}
|
|
119
119
|
if (res.ok) {
|
|
120
120
|
if (res.status === 204) return { ok: true, status: res.status, body: void 0 };
|
|
121
|
-
|
|
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
|
+
}
|
|
122
126
|
}
|
|
123
127
|
const detail = scrub(await detailOf(res));
|
|
124
128
|
const kind = classify(res.status);
|
|
@@ -452,15 +456,18 @@ async function startRun(passed, declared2) {
|
|
|
452
456
|
const out = await client.post(`/v1/runs/${runId}/results`, {
|
|
453
457
|
results: part
|
|
454
458
|
});
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
stats.
|
|
458
|
-
stats.
|
|
459
|
-
stats.
|
|
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;
|
|
460
465
|
progress();
|
|
461
466
|
continue;
|
|
462
467
|
}
|
|
463
|
-
if (out.
|
|
468
|
+
if (out.ok) {
|
|
469
|
+
log("plune: could not send results (the answer carried no counts).");
|
|
470
|
+
} else if (out.kind === "auth") {
|
|
464
471
|
log('plune: the API token was refused \u2014 run "plune login" with a fresh one.');
|
|
465
472
|
offline = true;
|
|
466
473
|
} else if (out.kind === "conflict") {
|
|
@@ -545,12 +552,13 @@ function resultKey(testId, retry) {
|
|
|
545
552
|
const plain = `${testId}#${retry}`;
|
|
546
553
|
return plain.length <= RESULT_KEY_MAX ? plain : `${sha256(testId).slice(0, HASH_CHARS)}#${retry}`;
|
|
547
554
|
}
|
|
548
|
-
function failureOf(attempt) {
|
|
555
|
+
function failureOf(attempt, home = homedir2()) {
|
|
549
556
|
const error = chosen(attempt);
|
|
550
|
-
const
|
|
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;
|
|
551
559
|
const steps = chainOf(attempt.steps);
|
|
552
560
|
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 &&
|
|
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 !== "");
|
|
554
562
|
const ciUrl = webLink(attempt.buildHref);
|
|
555
563
|
const failure = {
|
|
556
564
|
...headline !== void 0 ? { headline } : {},
|
|
@@ -568,30 +576,36 @@ function repoRootOf(dir, stopAt) {
|
|
|
568
576
|
}
|
|
569
577
|
}
|
|
570
578
|
function errorContextOf(attempt, home = homedir2()) {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
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), "");
|
|
576
586
|
const own = pathIn(home);
|
|
577
|
-
if (own !== void 0) text = text.replace(new RegExp(`${own.source}(?![\\w.-])`, own.flags), "~");
|
|
578
|
-
if (
|
|
579
|
-
return
|
|
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;
|
|
580
590
|
}
|
|
591
|
+
var PATH_START = "(?<![\\w.~%/\\\\-])";
|
|
581
592
|
var TEXT_LIMIT = 524288;
|
|
582
|
-
var
|
|
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;
|
|
583
596
|
function pathIn(path3) {
|
|
584
597
|
const parts = path3.split(/[\\/]+/);
|
|
585
598
|
while (parts.length > 1 && parts.at(-1) === "") parts.pop();
|
|
586
599
|
if (!parts.some((part) => part !== "" && !/^[A-Za-z]:$/.test(part))) return void 0;
|
|
587
|
-
const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]");
|
|
600
|
+
const escaped = parts.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("[\\\\/]+");
|
|
588
601
|
return new RegExp(`(?:file:\\/\\/\\/?)?${escaped}`, /^[A-Za-z]:$/.test(parts[0]) ? "gi" : "g");
|
|
589
602
|
}
|
|
603
|
+
var fileNameOf = (name) => /^(?:file:\/\/|[\\/]|~[\\/]|[A-Za-z]:[\\/])/.test(name) ? name.split(/[\\/]/).pop() ?? "" : name;
|
|
590
604
|
function cut(text) {
|
|
591
|
-
if (
|
|
605
|
+
if (jsonBytes(text) <= TEXT_LIMIT) return text;
|
|
592
606
|
const lines = text.split("\n");
|
|
593
|
-
const size = lines.map((line) =>
|
|
594
|
-
const budget = TEXT_LIMIT -
|
|
607
|
+
const size = lines.map((line) => jsonBytes(line) + 2);
|
|
608
|
+
const budget = TEXT_LIMIT - jsonBytes(omitted(lines.length));
|
|
595
609
|
let used = 0;
|
|
596
610
|
let head = 0;
|
|
597
611
|
let tail = lines.length;
|
|
@@ -603,6 +617,7 @@ var omitted = (lines) => `\u2026[omitted ${lines} lines]\u2026`;
|
|
|
603
617
|
var METADATA_TYPE = "application/plune.metadata+json";
|
|
604
618
|
var REPO_RELATIVE = /^(?![A-Za-z][A-Za-z0-9+.-]*:)(?![\\/~])(?!(?:.*[\\/])?\.\.(?:[\\/]|$)).+$/;
|
|
605
619
|
var FRAME = /^\s+at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
620
|
+
var FRAME_MAX = 8192;
|
|
606
621
|
var firstLine = (text) => stripVTControlCharacters(text).split("\n").map((line) => line.trim()).find((line) => line !== "");
|
|
607
622
|
function chosen({ status, errors }) {
|
|
608
623
|
if (status === "timedOut") {
|
|
@@ -622,6 +637,7 @@ function placeOf(error, testFile) {
|
|
|
622
637
|
const own = normal(testFile);
|
|
623
638
|
let first;
|
|
624
639
|
for (const line of stripVTControlCharacters(error.text).split("\n")) {
|
|
640
|
+
if (line.length > FRAME_MAX) continue;
|
|
625
641
|
const frame = FRAME.exec(line);
|
|
626
642
|
if (frame === null) continue;
|
|
627
643
|
const place = { file: fileOf(frame[1]), line: Number(frame[2]), column: Number(frame[3]) };
|
|
@@ -632,7 +648,11 @@ function placeOf(error, testFile) {
|
|
|
632
648
|
}
|
|
633
649
|
function fileOf(raw) {
|
|
634
650
|
if (!raw.startsWith("file://")) return raw;
|
|
635
|
-
|
|
651
|
+
let path3 = raw.slice("file://".length);
|
|
652
|
+
try {
|
|
653
|
+
path3 = decodeURIComponent(path3);
|
|
654
|
+
} catch {
|
|
655
|
+
}
|
|
636
656
|
return /^\/[A-Za-z]:\//.test(path3) ? path3.slice(1) : path3;
|
|
637
657
|
}
|
|
638
658
|
var normal = (path3) => posix.normalize(path3.replace(/\\/g, "/")).replace(/^([a-z]):/, (_, drive) => `${drive.toUpperCase()}:`);
|
|
@@ -647,13 +667,7 @@ function fromRoot(place, root) {
|
|
|
647
667
|
return column === void 0 ? { file: relative, line: place.line } : { file: relative, line: place.line, column };
|
|
648
668
|
}
|
|
649
669
|
function webLink(href) {
|
|
650
|
-
|
|
651
|
-
try {
|
|
652
|
-
const { protocol } = new URL(href);
|
|
653
|
-
return protocol === "http:" || protocol === "https:" ? href : void 0;
|
|
654
|
-
} catch {
|
|
655
|
-
return void 0;
|
|
656
|
-
}
|
|
670
|
+
return href !== void 0 && /^https?:\/\//i.test(href) && URL.canParse(href) ? href : void 0;
|
|
657
671
|
}
|
|
658
672
|
|
|
659
673
|
// src/index.ts
|
|
@@ -826,7 +840,7 @@ var PluneReporter = class {
|
|
|
826
840
|
onTestEnd(test, result) {
|
|
827
841
|
const session = this.open();
|
|
828
842
|
this.chain = this.chain.then(async () => {
|
|
829
|
-
(await session).add(pendingFrom(test, result, this.context));
|
|
843
|
+
await (await session).add(pendingFrom(test, result, this.context));
|
|
830
844
|
}).catch((err) => this.giveUp(err));
|
|
831
845
|
}
|
|
832
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.14.
|
|
41
|
+
"@plune-ai/cli": "0.14.1"
|
|
42
42
|
},
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|