@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,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlanitroReporter = exports.prettifyLocator = exports.convertPlaywrightSteps = exports.statusRank = exports.shouldReplace = exports.mapPlaywrightStatus = exports.mapOutcome = exports.defaultRunName = exports.detectCi = exports.buildTags = exports.extractCaseTags = exports.stripCaseTags = exports.buildPlaywrightId = void 0;
|
|
4
|
+
exports.resolveOptions = resolveOptions;
|
|
5
|
+
exports.describeTitles = describeTitles;
|
|
6
|
+
exports.isFinalAttempt = isFinalAttempt;
|
|
7
|
+
const automationId_1 = require("../../core/src/automationId");
|
|
8
|
+
const ci_1 = require("../../core/src/ci");
|
|
9
|
+
const http_1 = require("../../core/src/http");
|
|
10
|
+
const results_1 = require("../../core/src/results");
|
|
11
|
+
const sender_1 = require("../../core/src/sender");
|
|
12
|
+
const steps_1 = require("../../core/src/steps");
|
|
13
|
+
var automationId_2 = require("../../core/src/automationId");
|
|
14
|
+
Object.defineProperty(exports, "buildPlaywrightId", { enumerable: true, get: function () { return automationId_2.buildPlaywrightId; } });
|
|
15
|
+
Object.defineProperty(exports, "stripCaseTags", { enumerable: true, get: function () { return automationId_2.stripCaseTags; } });
|
|
16
|
+
Object.defineProperty(exports, "extractCaseTags", { enumerable: true, get: function () { return automationId_2.extractCaseTags; } });
|
|
17
|
+
Object.defineProperty(exports, "buildTags", { enumerable: true, get: function () { return automationId_2.buildTags; } });
|
|
18
|
+
var ci_2 = require("../../core/src/ci");
|
|
19
|
+
Object.defineProperty(exports, "detectCi", { enumerable: true, get: function () { return ci_2.detectCi; } });
|
|
20
|
+
Object.defineProperty(exports, "defaultRunName", { enumerable: true, get: function () { return ci_2.defaultRunName; } });
|
|
21
|
+
var results_2 = require("../../core/src/results");
|
|
22
|
+
Object.defineProperty(exports, "mapOutcome", { enumerable: true, get: function () { return results_2.mapOutcome; } });
|
|
23
|
+
Object.defineProperty(exports, "mapPlaywrightStatus", { enumerable: true, get: function () { return results_2.mapPlaywrightStatus; } });
|
|
24
|
+
Object.defineProperty(exports, "shouldReplace", { enumerable: true, get: function () { return results_2.shouldReplace; } });
|
|
25
|
+
Object.defineProperty(exports, "statusRank", { enumerable: true, get: function () { return results_2.statusRank; } });
|
|
26
|
+
var steps_2 = require("../../core/src/steps");
|
|
27
|
+
Object.defineProperty(exports, "convertPlaywrightSteps", { enumerable: true, get: function () { return steps_2.convertPlaywrightSteps; } });
|
|
28
|
+
Object.defineProperty(exports, "prettifyLocator", { enumerable: true, get: function () { return steps_2.prettifyLocator; } });
|
|
29
|
+
function str(v) {
|
|
30
|
+
if (v === undefined || v === null)
|
|
31
|
+
return undefined;
|
|
32
|
+
const s = String(v).trim();
|
|
33
|
+
return s ? s : undefined;
|
|
34
|
+
}
|
|
35
|
+
function num(v, fallback, min, max) {
|
|
36
|
+
const n = typeof v === "number" ? v : Number(v);
|
|
37
|
+
if (!Number.isFinite(n) || v === undefined || v === null || v === "")
|
|
38
|
+
return fallback;
|
|
39
|
+
return Math.min(max, Math.max(min, Math.round(n)));
|
|
40
|
+
}
|
|
41
|
+
/** Options win over environment variables. */
|
|
42
|
+
function resolveOptions(o, env) {
|
|
43
|
+
return {
|
|
44
|
+
url: str(o.url) ?? str(env.PLANITRO_URL),
|
|
45
|
+
apiKey: str(o.apiKey) ?? str(env.PLANITRO_API_KEY),
|
|
46
|
+
runName: str(o.runName) ?? str(env.PLANITRO_RUN_NAME),
|
|
47
|
+
release: str(o.release) ?? str(env.PLANITRO_RELEASE),
|
|
48
|
+
autoCreate: o.autoCreate !== undefined ? (0, results_1.parseBool)(o.autoCreate, true) : (0, results_1.parseBool)(env.PLANITRO_AUTO_CREATE, true),
|
|
49
|
+
runId: str(o.runId) ?? str(env.PLANITRO_RUN_ID),
|
|
50
|
+
uploadAttachments: o.uploadAttachments !== undefined
|
|
51
|
+
? (0, results_1.parseAttachmentMode)(o.uploadAttachments)
|
|
52
|
+
: (0, results_1.parseAttachmentMode)(env.PLANITRO_UPLOAD_ATTACHMENTS),
|
|
53
|
+
batchSize: num(o.batchSize, 50, 1, 500),
|
|
54
|
+
flushIntervalMs: num(o.flushIntervalMs, 2000, 50, 600_000),
|
|
55
|
+
endTimeoutMs: num(o.endTimeoutMs, 60_000, 1000, 3_600_000),
|
|
56
|
+
retries: num(o.retries, 3, 0, 10),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Titles of the describe blocks around a test, outermost first. */
|
|
60
|
+
function describeTitles(test) {
|
|
61
|
+
const out = [];
|
|
62
|
+
let s = test.parent;
|
|
63
|
+
while (s && s.type === "describe") {
|
|
64
|
+
out.unshift(s.title);
|
|
65
|
+
s = s.parent;
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Is this the last attempt Playwright will make for the test? A failed attempt with retries left is followed
|
|
71
|
+
* by another one, so it is held back. `test.outcome()` already accounts for `test.fail()` (expected failures).
|
|
72
|
+
*/
|
|
73
|
+
function isFinalAttempt(test, result) {
|
|
74
|
+
if (result.status === "interrupted")
|
|
75
|
+
return true;
|
|
76
|
+
if (result.retry >= test.retries)
|
|
77
|
+
return true;
|
|
78
|
+
return test.outcome() !== "unexpected";
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Playwright reporter that sends results to Planitro Tests. Never fails or throws into the test run: every
|
|
82
|
+
* Planitro problem is logged as a warning and swallowed.
|
|
83
|
+
*
|
|
84
|
+
* Tests that run in several Playwright projects (chromium + firefox) share one automation_id and therefore one
|
|
85
|
+
* Planitro case; the run keeps the WORST status of them (failed > passed > skipped).
|
|
86
|
+
*/
|
|
87
|
+
class PlanitroReporter {
|
|
88
|
+
constructor(options = {}) {
|
|
89
|
+
this.started = false;
|
|
90
|
+
this.external = false;
|
|
91
|
+
/** Latest non-final attempt per test id, sent at onEnd if no later attempt arrives (interrupted runs). */
|
|
92
|
+
this.pending = new Map();
|
|
93
|
+
this.env = options.env ?? process.env;
|
|
94
|
+
this.log = options.logger ?? http_1.consoleLogger;
|
|
95
|
+
this.git = options.git ?? ci_1.defaultGit;
|
|
96
|
+
this.opts = resolveOptions(options, this.env);
|
|
97
|
+
this.enabled = !!(this.opts.url && this.opts.apiKey);
|
|
98
|
+
}
|
|
99
|
+
printsToStdio() {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
onBegin(config, _suite) {
|
|
103
|
+
try {
|
|
104
|
+
this.config = config;
|
|
105
|
+
if (!this.enabled) {
|
|
106
|
+
this.log.info("reporting disabled (set PLANITRO_URL and PLANITRO_API_KEY to enable).");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
this.client = new http_1.PlanitroClient({
|
|
110
|
+
url: this.opts.url,
|
|
111
|
+
apiKey: this.opts.apiKey,
|
|
112
|
+
retries: this.opts.retries,
|
|
113
|
+
userAgent: "@planitro/playwright-reporter",
|
|
114
|
+
});
|
|
115
|
+
// The run is created when the first test starts (not here), so `--list` or a run with no tests
|
|
116
|
+
// leaves no empty run behind.
|
|
117
|
+
this.runIdP = new Promise((resolve) => {
|
|
118
|
+
this.resolveRunId = resolve;
|
|
119
|
+
});
|
|
120
|
+
if (this.opts.runId) {
|
|
121
|
+
this.external = true;
|
|
122
|
+
this.startRun();
|
|
123
|
+
}
|
|
124
|
+
this.sender = new sender_1.ResultSender({
|
|
125
|
+
client: this.client,
|
|
126
|
+
runId: this.runIdP,
|
|
127
|
+
autoCreate: this.opts.autoCreate,
|
|
128
|
+
batchSize: this.opts.batchSize,
|
|
129
|
+
log: this.log,
|
|
130
|
+
});
|
|
131
|
+
this.timer = setInterval(() => this.sender?.flush(), this.opts.flushIntervalMs);
|
|
132
|
+
this.timer.unref?.();
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
this.log.warn(`reporter setup failed: ${e.message}`);
|
|
136
|
+
this.sender = undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Starts (once) the run creation, or adopts PLANITRO_RUN_ID. */
|
|
140
|
+
startRun() {
|
|
141
|
+
const resolve = this.resolveRunId;
|
|
142
|
+
if (!resolve)
|
|
143
|
+
return;
|
|
144
|
+
this.resolveRunId = undefined;
|
|
145
|
+
this.started = true;
|
|
146
|
+
resolve(this.external ? this.opts.runId : this.createRun());
|
|
147
|
+
}
|
|
148
|
+
onTestBegin(_test, _result) {
|
|
149
|
+
if (this.sender)
|
|
150
|
+
this.startRun();
|
|
151
|
+
}
|
|
152
|
+
async createRun() {
|
|
153
|
+
try {
|
|
154
|
+
const ci = (0, ci_1.detectCi)(this.env, this.git);
|
|
155
|
+
const name = this.opts.runName ?? (0, ci_1.defaultRunName)(ci);
|
|
156
|
+
const res = await this.client.createRun({
|
|
157
|
+
name,
|
|
158
|
+
release: this.opts.release,
|
|
159
|
+
build: ci.build,
|
|
160
|
+
commit: ci.commit,
|
|
161
|
+
branch: ci.branch,
|
|
162
|
+
ci_url: ci.ci_url,
|
|
163
|
+
});
|
|
164
|
+
if (!res || typeof res.run_id !== "number")
|
|
165
|
+
throw new http_1.PlanitroError("unexpected response creating the run");
|
|
166
|
+
this.runUrl = res.url;
|
|
167
|
+
return res.run_id;
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
this.log.warn(`could not create a test run, results will not be reported: ${e.message}`);
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
onTestEnd(test, result) {
|
|
175
|
+
if (!this.sender)
|
|
176
|
+
return;
|
|
177
|
+
try {
|
|
178
|
+
if (!isFinalAttempt(test, result)) {
|
|
179
|
+
this.pending.set(test.id, { test, result });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.pending.delete(test.id);
|
|
183
|
+
this.startRun();
|
|
184
|
+
this.sender.add(this.toPending(test, result));
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
this.log.warn(`could not record "${test.title}": ${e.message}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** Builds the payload for a test's final attempt. */
|
|
191
|
+
toPending(test, result) {
|
|
192
|
+
const testDir = test.parent?.project?.()?.testDir ?? this.config?.rootDir;
|
|
193
|
+
const file = (0, automationId_1.relativePosix)(test.location.file, testDir);
|
|
194
|
+
const describes = describeTitles(test);
|
|
195
|
+
const ids = (0, automationId_1.buildPlaywrightId)(file, describes, test.title);
|
|
196
|
+
const status = (0, results_1.mapOutcome)(test.outcome());
|
|
197
|
+
const err = status === "failed" ? result.errors?.[0] ?? result.error : undefined;
|
|
198
|
+
const payload = {
|
|
199
|
+
automation_id: ids.automationId,
|
|
200
|
+
title: ids.title,
|
|
201
|
+
suite_path: ids.suitePath,
|
|
202
|
+
status,
|
|
203
|
+
duration_ms: Math.max(0, Math.round(result.duration)),
|
|
204
|
+
retries: result.retry,
|
|
205
|
+
error_message: (0, results_1.truncate)(err?.message ?? err?.value ?? null),
|
|
206
|
+
error_stack: (0, results_1.truncate)(err?.stack ?? null),
|
|
207
|
+
tags: (0, automationId_1.buildTags)(test.tags, [...describes, test.title]),
|
|
208
|
+
};
|
|
209
|
+
if (status === "passed") {
|
|
210
|
+
// Readable steps for the case (PTR-863): test.step titles, else the action log.
|
|
211
|
+
const cs = (0, steps_1.convertPlaywrightSteps)((result.steps ?? []));
|
|
212
|
+
if (cs.steps.length > 0 || cs.expected.length > 0) {
|
|
213
|
+
payload.steps = cs.steps;
|
|
214
|
+
payload.expected = cs.expected;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return { payload, attachments: (0, results_1.selectAttachments)(this.opts.uploadAttachments, status, result.attachments) };
|
|
218
|
+
}
|
|
219
|
+
async onEnd(_result) {
|
|
220
|
+
if (this.timer)
|
|
221
|
+
clearInterval(this.timer);
|
|
222
|
+
const sender = this.sender;
|
|
223
|
+
if (!sender)
|
|
224
|
+
return;
|
|
225
|
+
try {
|
|
226
|
+
if (!this.started) {
|
|
227
|
+
this.resolveRunId?.(undefined);
|
|
228
|
+
this.log.info("no tests ran, no run created.");
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
// Attempts that never got their retry (interrupted / maxFailures) are reported as they ended.
|
|
232
|
+
for (const { test, result } of this.pending.values())
|
|
233
|
+
sender.add(this.toPending(test, result));
|
|
234
|
+
this.pending.clear();
|
|
235
|
+
const drained = await sender.drain(this.opts.endTimeoutMs);
|
|
236
|
+
if (!drained)
|
|
237
|
+
this.log.warn(`gave up waiting for Planitro after ${Math.round(this.opts.endTimeoutMs / 1000)} s.`);
|
|
238
|
+
const runId = await this.runIdP;
|
|
239
|
+
if (runId === undefined)
|
|
240
|
+
return;
|
|
241
|
+
if (sender.unmatched.size > 0) {
|
|
242
|
+
this.log.warn(`${sender.unmatched.size} test(s) matched no case (auto-create is off).`);
|
|
243
|
+
}
|
|
244
|
+
const local = sender.counts();
|
|
245
|
+
if (this.external) {
|
|
246
|
+
this.log.info(`reported ${sender.postedCount} result(s) to run #${runId} (${local.passed} passed, ${local.failed} failed); run left open.`);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
let summary = { passed: local.passed, failed: local.failed };
|
|
250
|
+
let url = this.runUrl;
|
|
251
|
+
try {
|
|
252
|
+
const run = await this.client.completeRun(runId);
|
|
253
|
+
if (run?.summary) {
|
|
254
|
+
summary = { passed: run.summary.passed ?? summary.passed, failed: run.summary.failed ?? summary.failed };
|
|
255
|
+
}
|
|
256
|
+
url = run?.url ?? url;
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
this.log.warn(`could not complete run #${runId}: ${e.message}`);
|
|
260
|
+
}
|
|
261
|
+
this.log.info(`run ${url ?? `#${runId}`} — ${summary.passed} passed, ${summary.failed} failed`);
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
this.log.warn(`reporting failed: ${e.message}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
exports.default = PlanitroReporter;
|
|
269
|
+
exports.PlanitroReporter = PlanitroReporter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planitro/playwright-reporter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Playwright reporter that sends test results to Planitro Tests (test management)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/SnowyFoxStudios/Planitro.git",
|
|
9
|
+
"directory": "packages/playwright-reporter"
|
|
10
|
+
},
|
|
11
|
+
"main": "dist/playwright-reporter/src/index.js",
|
|
12
|
+
"types": "dist/playwright-reporter/src/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/playwright-reporter/src/index.d.ts",
|
|
16
|
+
"default": "./dist/playwright-reporter/src/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.json",
|
|
25
|
+
"prepack": "npm run build"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"playwright",
|
|
29
|
+
"reporter",
|
|
30
|
+
"planitro",
|
|
31
|
+
"test-management"
|
|
32
|
+
],
|
|
33
|
+
"homepage": "https://planitro.app/help/tests/automated-tests",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@playwright/test": ">=1.42.0"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
43
|
+
}
|