@planitro/playwright-reporter 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +176 -2
- package/dist/core/src/automationId.d.ts +39 -0
- package/dist/core/src/automationId.js +102 -0
- package/dist/core/src/ci.d.ts +21 -0
- package/dist/core/src/ci.js +143 -0
- package/dist/core/src/http.d.ts +116 -0
- package/dist/core/src/http.js +270 -0
- package/dist/core/src/playwrightJson.d.ts +74 -0
- package/dist/core/src/playwrightJson.js +92 -0
- package/dist/core/src/results.d.ts +69 -0
- package/dist/core/src/results.js +159 -0
- package/dist/core/src/sender.d.ts +45 -0
- package/dist/core/src/sender.js +145 -0
- package/dist/core/src/steps.d.ts +48 -0
- package/dist/core/src/steps.js +482 -0
- package/dist/playwright-reporter/src/index.d.ts +95 -0
- package/dist/playwright-reporter/src/index.js +269 -0
- package/package.json +41 -4
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Logger, PlanitroClient } from "./http";
|
|
2
|
+
import { PendingResult } from "./results";
|
|
3
|
+
export interface SenderOptions {
|
|
4
|
+
client: PlanitroClient;
|
|
5
|
+
/** Resolves to the run id, or undefined when the run could not be created (then everything is dropped). */
|
|
6
|
+
runId: Promise<number | string | undefined>;
|
|
7
|
+
autoCreate: boolean;
|
|
8
|
+
batchSize?: number;
|
|
9
|
+
log: Logger;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Batches results into `POST /runs/:id/results`, then uploads each result's attachments. Results with the same
|
|
13
|
+
* automation_id are deduplicated (worst status wins), also across batches: a worse result re-posts (the server
|
|
14
|
+
* updates the existing result), a better or equal one is dropped. Never throws.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ResultSender {
|
|
17
|
+
private readonly client;
|
|
18
|
+
private readonly runIdP;
|
|
19
|
+
private readonly autoCreate;
|
|
20
|
+
private readonly batchSize;
|
|
21
|
+
private readonly log;
|
|
22
|
+
/** Best result per automation_id seen so far (sent or queued). */
|
|
23
|
+
private readonly best;
|
|
24
|
+
private queue;
|
|
25
|
+
private readonly posts;
|
|
26
|
+
private readonly uploads;
|
|
27
|
+
private disabled;
|
|
28
|
+
private warnedPost;
|
|
29
|
+
readonly resultIds: Map<string, number>;
|
|
30
|
+
unmatched: Set<string>;
|
|
31
|
+
postedCount: number;
|
|
32
|
+
failedPosts: number;
|
|
33
|
+
uploadedAttachments: number;
|
|
34
|
+
constructor(opts: SenderOptions);
|
|
35
|
+
/** Queues a final result. Returns false when it was dropped by dedup. */
|
|
36
|
+
add(r: PendingResult): boolean;
|
|
37
|
+
get queued(): number;
|
|
38
|
+
/** Final statuses (after dedup) of everything handed to the sender. */
|
|
39
|
+
counts(): Record<import("./results").ResultStatus, number>;
|
|
40
|
+
/** Sends everything queued, in batches. Returns once the batches are queued (not sent). */
|
|
41
|
+
flush(): void;
|
|
42
|
+
/** Flushes and waits for every post/upload, up to `timeoutMs`. Returns false on timeout. */
|
|
43
|
+
drain(timeoutMs: number): Promise<boolean>;
|
|
44
|
+
private sendBatch;
|
|
45
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResultSender = void 0;
|
|
4
|
+
const http_1 = require("./http");
|
|
5
|
+
const results_1 = require("./results");
|
|
6
|
+
/**
|
|
7
|
+
* Batches results into `POST /runs/:id/results`, then uploads each result's attachments. Results with the same
|
|
8
|
+
* automation_id are deduplicated (worst status wins), also across batches: a worse result re-posts (the server
|
|
9
|
+
* updates the existing result), a better or equal one is dropped. Never throws.
|
|
10
|
+
*/
|
|
11
|
+
class ResultSender {
|
|
12
|
+
constructor(opts) {
|
|
13
|
+
/** Best result per automation_id seen so far (sent or queued). */
|
|
14
|
+
this.best = new Map();
|
|
15
|
+
this.queue = new Map();
|
|
16
|
+
this.posts = new http_1.SerialQueue();
|
|
17
|
+
this.uploads = new http_1.SerialQueue();
|
|
18
|
+
this.disabled = false;
|
|
19
|
+
this.warnedPost = false;
|
|
20
|
+
this.resultIds = new Map();
|
|
21
|
+
this.unmatched = new Set();
|
|
22
|
+
this.postedCount = 0;
|
|
23
|
+
this.failedPosts = 0;
|
|
24
|
+
this.uploadedAttachments = 0;
|
|
25
|
+
this.client = opts.client;
|
|
26
|
+
this.runIdP = opts.runId;
|
|
27
|
+
this.autoCreate = opts.autoCreate;
|
|
28
|
+
this.batchSize = Math.max(1, Math.min(opts.batchSize ?? 50, results_1.MAX_BATCH));
|
|
29
|
+
this.log = opts.log;
|
|
30
|
+
}
|
|
31
|
+
/** Queues a final result. Returns false when it was dropped by dedup. */
|
|
32
|
+
add(r) {
|
|
33
|
+
if (this.disabled)
|
|
34
|
+
return false;
|
|
35
|
+
const id = r.payload.automation_id;
|
|
36
|
+
if (!(0, results_1.shouldReplace)(this.best.get(id), r.payload)) {
|
|
37
|
+
const cur = this.best.get(id);
|
|
38
|
+
if (cur && cur.status === r.payload.status && r.payload.retries > cur.retries) {
|
|
39
|
+
// Same status on another project but flakier: keep the higher retry count if not yet sent.
|
|
40
|
+
const q = this.queue.get(id);
|
|
41
|
+
if (q)
|
|
42
|
+
q.payload.retries = r.payload.retries;
|
|
43
|
+
cur.retries = r.payload.retries;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
this.best.set(id, r.payload);
|
|
48
|
+
this.queue.set(id, r);
|
|
49
|
+
if (this.queue.size >= this.batchSize)
|
|
50
|
+
this.flush();
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
get queued() {
|
|
54
|
+
return this.queue.size;
|
|
55
|
+
}
|
|
56
|
+
/** Final statuses (after dedup) of everything handed to the sender. */
|
|
57
|
+
counts() {
|
|
58
|
+
return (0, results_1.countStatuses)(this.best.values());
|
|
59
|
+
}
|
|
60
|
+
/** Sends everything queued, in batches. Returns once the batches are queued (not sent). */
|
|
61
|
+
flush() {
|
|
62
|
+
while (this.queue.size > 0) {
|
|
63
|
+
const batch = [];
|
|
64
|
+
for (const [id, r] of this.queue) {
|
|
65
|
+
batch.push(r);
|
|
66
|
+
this.queue.delete(id);
|
|
67
|
+
if (batch.length >= this.batchSize)
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
this.posts.push(() => this.sendBatch(batch));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Flushes and waits for every post/upload, up to `timeoutMs`. Returns false on timeout. */
|
|
74
|
+
async drain(timeoutMs) {
|
|
75
|
+
this.flush();
|
|
76
|
+
let timer;
|
|
77
|
+
const timeout = new Promise((resolve) => {
|
|
78
|
+
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
79
|
+
});
|
|
80
|
+
const done = (async () => {
|
|
81
|
+
await this.posts.idle();
|
|
82
|
+
await this.uploads.idle();
|
|
83
|
+
return true;
|
|
84
|
+
})();
|
|
85
|
+
const ok = await Promise.race([done, timeout]);
|
|
86
|
+
if (timer)
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
return ok;
|
|
89
|
+
}
|
|
90
|
+
async sendBatch(batch) {
|
|
91
|
+
if (this.disabled)
|
|
92
|
+
return;
|
|
93
|
+
const runId = await this.runIdP;
|
|
94
|
+
if (runId === undefined) {
|
|
95
|
+
this.disabled = true;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const res = await this.client.postResults(runId, batch.map((b) => b.payload), this.autoCreate);
|
|
100
|
+
this.postedCount += batch.length;
|
|
101
|
+
for (const u of res?.unmatched ?? [])
|
|
102
|
+
this.unmatched.add(u);
|
|
103
|
+
const byId = new Map();
|
|
104
|
+
for (const r of res?.results ?? []) {
|
|
105
|
+
if (r && typeof r.result_id === "number")
|
|
106
|
+
byId.set(r.automation_id, r.result_id);
|
|
107
|
+
}
|
|
108
|
+
for (const b of batch) {
|
|
109
|
+
const resultId = byId.get(b.payload.automation_id);
|
|
110
|
+
if (resultId === undefined)
|
|
111
|
+
continue;
|
|
112
|
+
this.resultIds.set(b.payload.automation_id, resultId);
|
|
113
|
+
if (b.attachments.length === 0)
|
|
114
|
+
continue;
|
|
115
|
+
const atts = b.attachments;
|
|
116
|
+
this.uploads.push(async () => {
|
|
117
|
+
for (const a of atts) {
|
|
118
|
+
try {
|
|
119
|
+
if (await this.client.uploadAttachment(runId, resultId, a, this.log))
|
|
120
|
+
this.uploadedAttachments++;
|
|
121
|
+
}
|
|
122
|
+
catch (e) {
|
|
123
|
+
this.log.warn(`could not upload attachment "${a.name}": ${e.message}`);
|
|
124
|
+
if (e instanceof http_1.PlanitroError && (e.status === 402 || e.status === 413))
|
|
125
|
+
return; // quota: stop trying
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
this.failedPosts += batch.length;
|
|
133
|
+
const err = e;
|
|
134
|
+
if (!this.warnedPost) {
|
|
135
|
+
this.log.warn(`could not send ${batch.length} result(s): ${err.message}`);
|
|
136
|
+
this.warnedPost = true;
|
|
137
|
+
}
|
|
138
|
+
if (err instanceof http_1.PlanitroError && err.fatal) {
|
|
139
|
+
this.disabled = true;
|
|
140
|
+
this.log.warn("stopped reporting to Planitro for this run.");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.ResultSender = ResultSender;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a Playwright step tree into readable test case steps and expected results (PTR-863).
|
|
3
|
+
*
|
|
4
|
+
* - Tests with `test.step(...)` steps: their titles are the steps (nested steps prefixed with "– ").
|
|
5
|
+
* - Otherwise the action log is used: Navigate/Click/Fill/Check/… become steps, `expect(...)` assertions become
|
|
6
|
+
* expected results ("\"Save\" is visible").
|
|
7
|
+
* - Hooks, fixtures, attachments, HTTP calls (`GET "/me"`) and raw JSON titles are dropped; API setup calls are
|
|
8
|
+
* summarised in one leading "Set up test data (N API calls)" line.
|
|
9
|
+
*
|
|
10
|
+
* Works with the reporter's `TestStep` objects (which have `category`) and with JSON / HTML report step trees
|
|
11
|
+
* (which may not): every kind is also detected from the title.
|
|
12
|
+
*/
|
|
13
|
+
/** One step of a Playwright step tree (TestStep, JSON report step, or HTML report step). */
|
|
14
|
+
export interface StepNode {
|
|
15
|
+
title: string;
|
|
16
|
+
category?: string;
|
|
17
|
+
steps?: StepNode[];
|
|
18
|
+
/** HTML report: consecutive identical steps collapsed into one. */
|
|
19
|
+
count?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface CaseSteps {
|
|
22
|
+
steps: string[];
|
|
23
|
+
expected: string[];
|
|
24
|
+
}
|
|
25
|
+
export interface ConvertStepsOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Every node without a category is a `test.step` (the JSON reporter only writes `test.step` steps).
|
|
28
|
+
* Hooks and fixtures are still recognised by title.
|
|
29
|
+
*/
|
|
30
|
+
onlyTestSteps?: boolean;
|
|
31
|
+
maxSteps?: number;
|
|
32
|
+
maxExpected?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare const MAX_CASE_STEPS = 30;
|
|
35
|
+
export declare const MAX_CASE_EXPECTED = 15;
|
|
36
|
+
/** True when `s` is a Playwright locator description like `getByTestId('x').first()`. */
|
|
37
|
+
export declare function isLocatorText(s: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Readable name for a locator: `getByRole('button', { name: 'Save' })` → `the "Save" button`,
|
|
40
|
+
* `getByText('X')` → `"X"`, `getByTestId('board-filters-button')` → `the board filters button`.
|
|
41
|
+
* Chains use their last, most specific part. Anything else comes back unchanged.
|
|
42
|
+
*/
|
|
43
|
+
export declare function prettifyLocator(s: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Converts a Playwright step tree into `{ steps, expected }` for a test case. Both are empty when the tree has
|
|
46
|
+
* nothing readable (e.g. a test that only calls APIs).
|
|
47
|
+
*/
|
|
48
|
+
export declare function convertPlaywrightSteps(roots: ReadonlyArray<StepNode> | undefined, options?: ConvertStepsOptions): CaseSteps;
|