@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,482 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Turns a Playwright step tree into readable test case steps and expected results (PTR-863).
|
|
4
|
+
*
|
|
5
|
+
* - Tests with `test.step(...)` steps: their titles are the steps (nested steps prefixed with "– ").
|
|
6
|
+
* - Otherwise the action log is used: Navigate/Click/Fill/Check/… become steps, `expect(...)` assertions become
|
|
7
|
+
* expected results ("\"Save\" is visible").
|
|
8
|
+
* - Hooks, fixtures, attachments, HTTP calls (`GET "/me"`) and raw JSON titles are dropped; API setup calls are
|
|
9
|
+
* summarised in one leading "Set up test data (N API calls)" line.
|
|
10
|
+
*
|
|
11
|
+
* Works with the reporter's `TestStep` objects (which have `category`) and with JSON / HTML report step trees
|
|
12
|
+
* (which may not): every kind is also detected from the title.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MAX_CASE_EXPECTED = exports.MAX_CASE_STEPS = void 0;
|
|
16
|
+
exports.isLocatorText = isLocatorText;
|
|
17
|
+
exports.prettifyLocator = prettifyLocator;
|
|
18
|
+
exports.convertPlaywrightSteps = convertPlaywrightSteps;
|
|
19
|
+
exports.MAX_CASE_STEPS = 30;
|
|
20
|
+
exports.MAX_CASE_EXPECTED = 15;
|
|
21
|
+
const MAX_LINE = 200;
|
|
22
|
+
const HOOK_RE = /^(before hooks|after hooks|worker cleanup|(before|after)(each|all) hook\b|(before|after) (each|all) hook\b)/i;
|
|
23
|
+
const FIXTURE_RE = /^fixture\b|^fixture:/i;
|
|
24
|
+
const ATTACH_RE = /^attach\s+"/i;
|
|
25
|
+
const HTTP_RE = /^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|FETCH)\s+"/;
|
|
26
|
+
const OLD_HTTP_RE = /^(apiRequestContext|apiRequest|request|apiResponse)\.\w+/;
|
|
27
|
+
const EXPECT_RE = /^expect\s+"/i;
|
|
28
|
+
const OLD_EXPECT_RE = /^expect(\.poll|\.soft|\.not)*\.(\w+)/;
|
|
29
|
+
const ACTION_RE = /^(Navigate to|Click|Double click|Fill|Type|Check|Uncheck|Select option|Press|Hover|Set input files|Drag and drop|Drag|Tap|Clear(?! (cookies|permissions|console|page))|Focus|Go back|Go forward|Reload)\b/;
|
|
30
|
+
const OLD_ACTION_RE = /^(page|frame|locator|elementHandle|keyboard|mouse|touchscreen)\.(\w+)\((.*)\)$/s;
|
|
31
|
+
/** Other Playwright API titles: dropped, and never mistaken for a test.step when there is no category. */
|
|
32
|
+
const API_RE = new RegExp("^(" +
|
|
33
|
+
[
|
|
34
|
+
// Exact Playwright titles (protocolMetainfo), kept narrow so user step titles like "Create an issue" stay steps.
|
|
35
|
+
"Wait for (timeout|selector|function|state|navigation|load state|event|url|response|request)",
|
|
36
|
+
"Evaluate", "Screenshot", "Query (selector|count)", "Is (visible|hidden|enabled|editable|disabled|checked)$",
|
|
37
|
+
"Get (text|storage|response|property|page|JSON|JS|input|inner|HTML|content|owner|network|frame|cookies|console|bounding|attribute)",
|
|
38
|
+
"Create (page|context|request context|CDP session)", "Launch (browser|persistent|electron)", "Close (page|context|browser)",
|
|
39
|
+
"Route (requests|WebSockets)", "Unroute", "Bounding box", "Scroll into view", "Mouse (wheel|up|down|move)",
|
|
40
|
+
"Set (viewport|extra|storage|overlay|offline|HTTP|geolocation|content)", "Add (cookies|init|script|style)",
|
|
41
|
+
"Clear (cookies|permissions|console|page)", "Grant permissions", "Expose binding", "Dispatch event", "Select text",
|
|
42
|
+
"Emulate media", "Aria snapshot", "Fulfill request", "Continue request", "Abort request", "Bring to front",
|
|
43
|
+
"(Start|Stop) (tracing|server|screencast|JS|CSS|browser)", "Pause$", "Resume$", "PDF$", "Highlight element",
|
|
44
|
+
"Long tap", "Accept dialog", "Dismiss dialog", "Connect (over|to|WebSocket)", "Expect screenshot",
|
|
45
|
+
].join("|") +
|
|
46
|
+
")");
|
|
47
|
+
const OLD_API_RE = /^(page|frame|locator|elementHandle|browserContext|browser|browserType|keyboard|mouse|tracing|worker|route|request|response|webSocket|electron|android)\.\w+/;
|
|
48
|
+
function looksLikeJson(t) {
|
|
49
|
+
const s = t.trim();
|
|
50
|
+
return (s.startsWith("{") || s.startsWith("[")) && /["\]}]\s*$/.test(s) && (s.includes('":') || s.length > 1);
|
|
51
|
+
}
|
|
52
|
+
function classify(n, onlyTestSteps) {
|
|
53
|
+
const t = (n.title ?? "").trim();
|
|
54
|
+
const c = n.category;
|
|
55
|
+
if (c === "hook" || HOOK_RE.test(t))
|
|
56
|
+
return "hook";
|
|
57
|
+
if (c === "fixture" || FIXTURE_RE.test(t))
|
|
58
|
+
return "fixture";
|
|
59
|
+
if (c === "attach" || c === "test.attach" || ATTACH_RE.test(t))
|
|
60
|
+
return "attach";
|
|
61
|
+
if (looksLikeJson(t))
|
|
62
|
+
return "json";
|
|
63
|
+
if (c === "test.step" || c === "test.step.skip")
|
|
64
|
+
return "step";
|
|
65
|
+
if (c === "expect")
|
|
66
|
+
return "expect";
|
|
67
|
+
if (c === "pw:api") {
|
|
68
|
+
if (HTTP_RE.test(t) || OLD_HTTP_RE.test(t))
|
|
69
|
+
return "http";
|
|
70
|
+
if (ACTION_RE.test(t) || OLD_ACTION_RE.test(t))
|
|
71
|
+
return "action";
|
|
72
|
+
return "api";
|
|
73
|
+
}
|
|
74
|
+
if (c)
|
|
75
|
+
return "api"; // unknown category: never a step
|
|
76
|
+
if (onlyTestSteps)
|
|
77
|
+
return "step";
|
|
78
|
+
if (HTTP_RE.test(t) || OLD_HTTP_RE.test(t))
|
|
79
|
+
return "http";
|
|
80
|
+
if (EXPECT_RE.test(t) || OLD_EXPECT_RE.test(t))
|
|
81
|
+
return "expect";
|
|
82
|
+
if (ACTION_RE.test(t))
|
|
83
|
+
return "action";
|
|
84
|
+
if (API_RE.test(t) || OLD_API_RE.test(t))
|
|
85
|
+
return t.match(OLD_ACTION_RE) && oldAction(t) ? "action" : "api";
|
|
86
|
+
return "step";
|
|
87
|
+
}
|
|
88
|
+
// ---------- locators ----------
|
|
89
|
+
/** Splits `a('x').b({ y: 'z' }).c()` into top-level call segments, respecting quotes and brackets. */
|
|
90
|
+
function splitChain(s) {
|
|
91
|
+
const out = [];
|
|
92
|
+
let depth = 0;
|
|
93
|
+
let quote = "";
|
|
94
|
+
let cur = "";
|
|
95
|
+
for (let i = 0; i < s.length; i++) {
|
|
96
|
+
const ch = s[i];
|
|
97
|
+
if (quote) {
|
|
98
|
+
cur += ch;
|
|
99
|
+
if (ch === "\\" && i + 1 < s.length) {
|
|
100
|
+
cur += s[++i];
|
|
101
|
+
}
|
|
102
|
+
else if (ch === quote)
|
|
103
|
+
quote = "";
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
107
|
+
quote = ch;
|
|
108
|
+
cur += ch;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (ch === "(" || ch === "{" || ch === "[")
|
|
112
|
+
depth++;
|
|
113
|
+
if (ch === ")" || ch === "}" || ch === "]")
|
|
114
|
+
depth--;
|
|
115
|
+
if (ch === "." && depth === 0) {
|
|
116
|
+
out.push(cur);
|
|
117
|
+
cur = "";
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
cur += ch;
|
|
121
|
+
}
|
|
122
|
+
out.push(cur);
|
|
123
|
+
return out.map((x) => x.trim()).filter(Boolean);
|
|
124
|
+
}
|
|
125
|
+
/** First string (or regex) literal in `s`, unescaped. */
|
|
126
|
+
function firstLiteral(s) {
|
|
127
|
+
const m = s.match(/^\s*(?:'((?:[^'\\]|\\.)*)'|"((?:[^"\\]|\\.)*)"|`((?:[^`\\]|\\.)*)`|\/((?:[^/\\]|\\.)+)\/[a-z]*)/);
|
|
128
|
+
if (!m)
|
|
129
|
+
return undefined;
|
|
130
|
+
const v = m[1] ?? m[2] ?? m[3] ?? m[4] ?? "";
|
|
131
|
+
return v.replace(/\\(.)/g, "$1");
|
|
132
|
+
}
|
|
133
|
+
/** `name: 'Save'` inside an options object. */
|
|
134
|
+
function optionLiteral(args, key) {
|
|
135
|
+
const i = args.search(new RegExp(`\\b${key}\\s*:`));
|
|
136
|
+
if (i < 0)
|
|
137
|
+
return undefined;
|
|
138
|
+
return firstLiteral(args.slice(i).replace(new RegExp(`^${key}\\s*:`), ""));
|
|
139
|
+
}
|
|
140
|
+
const ROLE_NAMES = {
|
|
141
|
+
menuitem: "menu item",
|
|
142
|
+
menuitemcheckbox: "menu item",
|
|
143
|
+
menuitemradio: "menu item",
|
|
144
|
+
textbox: "field",
|
|
145
|
+
searchbox: "search box",
|
|
146
|
+
combobox: "dropdown",
|
|
147
|
+
listbox: "list",
|
|
148
|
+
option: "option",
|
|
149
|
+
checkbox: "checkbox",
|
|
150
|
+
radio: "radio button",
|
|
151
|
+
spinbutton: "number field",
|
|
152
|
+
gridcell: "cell",
|
|
153
|
+
columnheader: "column header",
|
|
154
|
+
rowheader: "row header",
|
|
155
|
+
tabpanel: "tab panel",
|
|
156
|
+
treeitem: "tree item",
|
|
157
|
+
alertdialog: "dialog",
|
|
158
|
+
};
|
|
159
|
+
function words(id) {
|
|
160
|
+
return id
|
|
161
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
162
|
+
.replace(/[-_.:]+/g, " ")
|
|
163
|
+
.replace(/\s+/g, " ")
|
|
164
|
+
.trim()
|
|
165
|
+
.toLowerCase();
|
|
166
|
+
}
|
|
167
|
+
function shortCss(css) {
|
|
168
|
+
const s = css.trim();
|
|
169
|
+
return s.length > 40 ? s.slice(0, 39) + "…" : s;
|
|
170
|
+
}
|
|
171
|
+
const LOCATOR_SEG = /^(getBy\w+|locator|frameLocator|contentFrame|first|last|nth|filter|and|or|describe)\(/;
|
|
172
|
+
/** True when `s` is a Playwright locator description like `getByTestId('x').first()`. */
|
|
173
|
+
function isLocatorText(s) {
|
|
174
|
+
const segs = splitChain(s);
|
|
175
|
+
return segs.length > 0 && segs.every((x) => LOCATOR_SEG.test(x) || x === "page");
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Readable name for a locator: `getByRole('button', { name: 'Save' })` → `the "Save" button`,
|
|
179
|
+
* `getByText('X')` → `"X"`, `getByTestId('board-filters-button')` → `the board filters button`.
|
|
180
|
+
* Chains use their last, most specific part. Anything else comes back unchanged.
|
|
181
|
+
*/
|
|
182
|
+
function prettifyLocator(s) {
|
|
183
|
+
const text = s.trim();
|
|
184
|
+
if (!isLocatorText(text))
|
|
185
|
+
return text;
|
|
186
|
+
const segs = splitChain(text).filter((x) => /^(getBy\w+|locator)\(/.test(x));
|
|
187
|
+
const last = segs[segs.length - 1];
|
|
188
|
+
if (!last)
|
|
189
|
+
return text;
|
|
190
|
+
const m = last.match(/^(\w+)\(([\s\S]*)\)$/);
|
|
191
|
+
if (!m)
|
|
192
|
+
return text;
|
|
193
|
+
const [, fn, args] = m;
|
|
194
|
+
const lit = firstLiteral(args);
|
|
195
|
+
switch (fn) {
|
|
196
|
+
case "getByRole": {
|
|
197
|
+
const role = lit ?? "element";
|
|
198
|
+
const noun = ROLE_NAMES[role] ?? role;
|
|
199
|
+
const name = optionLiteral(args, "name");
|
|
200
|
+
return name !== undefined ? `the "${name}" ${noun}` : `the ${noun}`;
|
|
201
|
+
}
|
|
202
|
+
case "getByText":
|
|
203
|
+
case "getByLabel":
|
|
204
|
+
case "getByTitle":
|
|
205
|
+
return lit !== undefined ? `"${lit}"` : text;
|
|
206
|
+
case "getByPlaceholder":
|
|
207
|
+
return lit !== undefined ? `the "${lit}" field` : text;
|
|
208
|
+
case "getByAltText":
|
|
209
|
+
return lit !== undefined ? `the "${lit}" image` : text;
|
|
210
|
+
case "getByTestId":
|
|
211
|
+
return lit !== undefined ? `the ${words(lit)}` : text;
|
|
212
|
+
case "locator":
|
|
213
|
+
return lit !== undefined ? shortCss(lit) : text;
|
|
214
|
+
default:
|
|
215
|
+
return text;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// ---------- actions ----------
|
|
219
|
+
/** `"value" rest` → [value, rest] (Playwright quotes with escapeWithQuotes). */
|
|
220
|
+
function leadingQuoted(s) {
|
|
221
|
+
const m = s.match(/^"((?:[^"\\]|\\.)*)"\s*([\s\S]*)$/);
|
|
222
|
+
if (!m)
|
|
223
|
+
return undefined;
|
|
224
|
+
return [m[1].replace(/\\(.)/g, "$1"), m[2]];
|
|
225
|
+
}
|
|
226
|
+
function clip(s, max = MAX_LINE) {
|
|
227
|
+
const t = s.replace(/\s+/g, " ").trim();
|
|
228
|
+
return t.length > max ? t.slice(0, max - 1) + "…" : t;
|
|
229
|
+
}
|
|
230
|
+
function capitalize(s) {
|
|
231
|
+
return s ? s[0].toUpperCase() + s.slice(1) : s;
|
|
232
|
+
}
|
|
233
|
+
function target(rest) {
|
|
234
|
+
return rest.trim() ? prettifyLocator(rest) : "";
|
|
235
|
+
}
|
|
236
|
+
function withTarget(verb, rest, prep = "") {
|
|
237
|
+
const t = target(rest);
|
|
238
|
+
return t ? `${verb} ${prep ? prep + " " : ""}${t}` : verb;
|
|
239
|
+
}
|
|
240
|
+
/** Readable line for a Playwright action title (new `Click getBy…` format). */
|
|
241
|
+
function actionLine(title) {
|
|
242
|
+
const t = title.trim();
|
|
243
|
+
let m;
|
|
244
|
+
if ((m = t.match(/^Navigate to\s+([\s\S]*)$/))) {
|
|
245
|
+
const q = leadingQuoted(m[1]);
|
|
246
|
+
return `Go to ${q ? q[0] : m[1].trim()}`;
|
|
247
|
+
}
|
|
248
|
+
if ((m = t.match(/^(Fill|Type)\s+([\s\S]*)$/))) {
|
|
249
|
+
const q = leadingQuoted(m[2]);
|
|
250
|
+
if (!q)
|
|
251
|
+
return withTarget(m[1], m[2]);
|
|
252
|
+
const [value, rest] = q;
|
|
253
|
+
const tgt = target(rest);
|
|
254
|
+
if (m[1] === "Fill") {
|
|
255
|
+
if (value === "")
|
|
256
|
+
return tgt ? `Clear ${tgt}` : "Clear the field";
|
|
257
|
+
return tgt ? `Fill ${tgt} with "${value}"` : `Fill in "${value}"`;
|
|
258
|
+
}
|
|
259
|
+
return tgt ? `Type "${value}" into ${tgt}` : `Type "${value}"`;
|
|
260
|
+
}
|
|
261
|
+
if ((m = t.match(/^Press\s+([\s\S]*)$/))) {
|
|
262
|
+
const q = leadingQuoted(m[1]);
|
|
263
|
+
if (!q)
|
|
264
|
+
return withTarget("Press", m[1]);
|
|
265
|
+
const tgt = target(q[1]);
|
|
266
|
+
return tgt ? `Press ${q[0]} in ${tgt}` : `Press ${q[0]}`;
|
|
267
|
+
}
|
|
268
|
+
if ((m = t.match(/^Double click\b\s*([\s\S]*)$/)))
|
|
269
|
+
return withTarget("Double-click", m[1]);
|
|
270
|
+
if ((m = t.match(/^Click\b\s*([\s\S]*)$/)))
|
|
271
|
+
return withTarget("Click", m[1]);
|
|
272
|
+
if ((m = t.match(/^Uncheck\b\s*([\s\S]*)$/)))
|
|
273
|
+
return withTarget("Uncheck", m[1]);
|
|
274
|
+
if ((m = t.match(/^Check\b\s*([\s\S]*)$/)))
|
|
275
|
+
return withTarget("Check", m[1]);
|
|
276
|
+
if ((m = t.match(/^Select option\b\s*([\s\S]*)$/)))
|
|
277
|
+
return withTarget("Select an option", m[1], "in");
|
|
278
|
+
if ((m = t.match(/^Hover\b\s*([\s\S]*)$/)))
|
|
279
|
+
return withTarget("Hover", m[1], "over");
|
|
280
|
+
if ((m = t.match(/^Set input files\b\s*([\s\S]*)$/)))
|
|
281
|
+
return withTarget("Upload a file", m[1], "to");
|
|
282
|
+
if ((m = t.match(/^Drag and drop\b\s*([\s\S]*)$/)))
|
|
283
|
+
return withTarget("Drag and drop", m[1]);
|
|
284
|
+
if ((m = t.match(/^Drag\b\s*([\s\S]*)$/)))
|
|
285
|
+
return withTarget("Drag", m[1]);
|
|
286
|
+
if ((m = t.match(/^Tap\b\s*([\s\S]*)$/)))
|
|
287
|
+
return withTarget("Tap", m[1]);
|
|
288
|
+
if ((m = t.match(/^Clear\b\s*([\s\S]*)$/)))
|
|
289
|
+
return withTarget("Clear", m[1]);
|
|
290
|
+
if ((m = t.match(/^Focus\b\s*([\s\S]*)$/)))
|
|
291
|
+
return withTarget("Focus", m[1]);
|
|
292
|
+
if (/^Go back\b/.test(t))
|
|
293
|
+
return "Go back";
|
|
294
|
+
if (/^Go forward\b/.test(t))
|
|
295
|
+
return "Go forward";
|
|
296
|
+
if (/^Reload\b/.test(t))
|
|
297
|
+
return "Reload the page";
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
const OLD_VERBS = {
|
|
301
|
+
goto: "Navigate to",
|
|
302
|
+
click: "Click",
|
|
303
|
+
dblclick: "Double click",
|
|
304
|
+
fill: "Fill",
|
|
305
|
+
type: "Type",
|
|
306
|
+
pressSequentially: "Type",
|
|
307
|
+
check: "Check",
|
|
308
|
+
uncheck: "Uncheck",
|
|
309
|
+
setChecked: "Check",
|
|
310
|
+
selectOption: "Select option",
|
|
311
|
+
press: "Press",
|
|
312
|
+
hover: "Hover",
|
|
313
|
+
setInputFiles: "Set input files",
|
|
314
|
+
dragTo: "Drag",
|
|
315
|
+
dragAndDrop: "Drag and drop",
|
|
316
|
+
tap: "Tap",
|
|
317
|
+
clear: "Clear",
|
|
318
|
+
focus: "Focus",
|
|
319
|
+
goBack: "Go back",
|
|
320
|
+
goForward: "Go forward",
|
|
321
|
+
reload: "Reload",
|
|
322
|
+
};
|
|
323
|
+
/** Older Playwright titles: `page.goto(/x)`, `locator.click(getByTestId('a'))`. */
|
|
324
|
+
function oldAction(title) {
|
|
325
|
+
const m = title.match(OLD_ACTION_RE);
|
|
326
|
+
if (!m)
|
|
327
|
+
return undefined;
|
|
328
|
+
const verb = OLD_VERBS[m[2]];
|
|
329
|
+
if (!verb)
|
|
330
|
+
return undefined;
|
|
331
|
+
const arg = m[3].trim();
|
|
332
|
+
if (verb === "Navigate to")
|
|
333
|
+
return `Go to ${arg}`;
|
|
334
|
+
return actionLine(arg ? `${verb} ${arg}` : verb);
|
|
335
|
+
}
|
|
336
|
+
// ---------- assertions ----------
|
|
337
|
+
function matcherWords(name) {
|
|
338
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase();
|
|
339
|
+
}
|
|
340
|
+
/** Sentence for an assertion: subject + matcher (+ "not"). Undefined when there is nothing readable to say. */
|
|
341
|
+
function expectSentence(matcher, subjectRaw) {
|
|
342
|
+
let m = matcher.trim().replace(/\(.*\)$/, "");
|
|
343
|
+
let not = false;
|
|
344
|
+
const mods = m.split(/\s+/);
|
|
345
|
+
m = mods.pop() ?? "";
|
|
346
|
+
for (const x of mods)
|
|
347
|
+
if (x === "not")
|
|
348
|
+
not = true;
|
|
349
|
+
const subject = subjectRaw.trim() ? prettifyLocator(subjectRaw) : "";
|
|
350
|
+
const page = { toHaveURL: "The page URL", toHaveTitle: "The page title" };
|
|
351
|
+
if (!subject) {
|
|
352
|
+
if (page[m])
|
|
353
|
+
return `${page[m]} is ${not ? "not " : ""}as expected`;
|
|
354
|
+
if (m === "toHaveScreenshot")
|
|
355
|
+
return `The page ${not ? "does not look" : "looks"} as expected`;
|
|
356
|
+
return undefined; // expect(value).toBe(…): nothing readable without the source
|
|
357
|
+
}
|
|
358
|
+
const s = capitalize(subject);
|
|
359
|
+
if (m === "toHaveScreenshot")
|
|
360
|
+
return `${s} ${not ? "does not look" : "looks"} as expected`;
|
|
361
|
+
if (m === "toMatchAriaSnapshot")
|
|
362
|
+
return `${s} ${not ? "does not match" : "matches"} the expected structure`;
|
|
363
|
+
if (m === "toBeHidden")
|
|
364
|
+
return `${s} is ${not ? "visible" : "hidden"}`;
|
|
365
|
+
if (m === "toBeAttached")
|
|
366
|
+
return `${s} is ${not ? "not " : ""}on the page`;
|
|
367
|
+
if (m === "toBeInViewport")
|
|
368
|
+
return `${s} is ${not ? "not " : ""}in view`;
|
|
369
|
+
let r;
|
|
370
|
+
if ((r = m.match(/^toBe(\w+)$/)))
|
|
371
|
+
return `${s} is ${not ? "not " : ""}${matcherWords(r[1])}`;
|
|
372
|
+
if ((r = m.match(/^toHave(\w+)$/)))
|
|
373
|
+
return `${s} ${not ? "does not have" : "has"} the expected ${matcherWords(r[1])}`;
|
|
374
|
+
if ((r = m.match(/^toContain(\w+)$/)))
|
|
375
|
+
return `${s} ${not ? "does not contain" : "contains"} the expected ${matcherWords(r[1])}`;
|
|
376
|
+
if (/^to\w+$/.test(m))
|
|
377
|
+
return `${s}: ${not ? "not " : ""}${matcherWords(m.slice(2))}`;
|
|
378
|
+
return undefined;
|
|
379
|
+
}
|
|
380
|
+
function expectLine(n) {
|
|
381
|
+
const t = (n.title ?? "").trim();
|
|
382
|
+
const q = t.match(/^Expect\s+"((?:[^"\\]|\\.)*)"\s*([\s\S]*)$/i);
|
|
383
|
+
if (q) {
|
|
384
|
+
const matcher = q[1].replace(/\\(.)/g, "$1");
|
|
385
|
+
if (/^(poll |soft )*(not )?toBeOK$/.test(matcher))
|
|
386
|
+
return undefined; // API response checks are setup
|
|
387
|
+
return expectSentence(matcher, q[2]);
|
|
388
|
+
}
|
|
389
|
+
const old = t.match(OLD_EXPECT_RE);
|
|
390
|
+
if (old) {
|
|
391
|
+
const not = /\.not\./.test(t);
|
|
392
|
+
return expectSentence(`${not ? "not " : ""}${old[2]}`, "");
|
|
393
|
+
}
|
|
394
|
+
// expect(x, "custom message") → the message is the title.
|
|
395
|
+
return t ? t : undefined;
|
|
396
|
+
}
|
|
397
|
+
function push(lines, text, count = 1) {
|
|
398
|
+
if (!text)
|
|
399
|
+
return;
|
|
400
|
+
const t = clip(text);
|
|
401
|
+
if (!t)
|
|
402
|
+
return;
|
|
403
|
+
const last = lines[lines.length - 1];
|
|
404
|
+
if (last && last.text === t)
|
|
405
|
+
last.count += count;
|
|
406
|
+
else
|
|
407
|
+
lines.push({ text: t, count });
|
|
408
|
+
}
|
|
409
|
+
function hasTestSteps(nodes, only) {
|
|
410
|
+
for (const n of nodes ?? []) {
|
|
411
|
+
const k = classify(n, only);
|
|
412
|
+
if (k === "hook" || k === "fixture")
|
|
413
|
+
continue;
|
|
414
|
+
if (k === "step")
|
|
415
|
+
return true;
|
|
416
|
+
if (hasTestSteps(n.steps, only))
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
function render(lines, max) {
|
|
422
|
+
const out = lines.map((l) => (l.count > 1 ? `${l.text} ×${l.count}` : l.text));
|
|
423
|
+
if (out.length <= max)
|
|
424
|
+
return out;
|
|
425
|
+
const extra = out.length - max;
|
|
426
|
+
return [...out.slice(0, max), `… ${extra} more`];
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Converts a Playwright step tree into `{ steps, expected }` for a test case. Both are empty when the tree has
|
|
430
|
+
* nothing readable (e.g. a test that only calls APIs).
|
|
431
|
+
*/
|
|
432
|
+
function convertPlaywrightSteps(roots, options = {}) {
|
|
433
|
+
const only = !!options.onlyTestSteps;
|
|
434
|
+
const maxSteps = options.maxSteps ?? exports.MAX_CASE_STEPS;
|
|
435
|
+
const maxExpected = options.maxExpected ?? exports.MAX_CASE_EXPECTED;
|
|
436
|
+
const nodes = (roots ?? []).filter((n) => n && typeof n.title === "string");
|
|
437
|
+
const steps = [];
|
|
438
|
+
const expected = [];
|
|
439
|
+
let apiCalls = 0;
|
|
440
|
+
const stepMode = hasTestSteps(nodes, only);
|
|
441
|
+
const walk = (list, depth) => {
|
|
442
|
+
for (const n of list ?? []) {
|
|
443
|
+
if (!n || typeof n.title !== "string")
|
|
444
|
+
continue;
|
|
445
|
+
const k = classify(n, only);
|
|
446
|
+
const count = Math.max(1, Math.round(n.count ?? 1));
|
|
447
|
+
switch (k) {
|
|
448
|
+
case "hook":
|
|
449
|
+
case "fixture":
|
|
450
|
+
case "attach":
|
|
451
|
+
case "json":
|
|
452
|
+
case "api":
|
|
453
|
+
break;
|
|
454
|
+
case "http":
|
|
455
|
+
apiCalls += count;
|
|
456
|
+
break;
|
|
457
|
+
case "expect":
|
|
458
|
+
push(expected, expectLine(n), count);
|
|
459
|
+
break;
|
|
460
|
+
case "action":
|
|
461
|
+
if (!stepMode)
|
|
462
|
+
push(steps, actionLine(n.title) ?? oldAction(n.title.trim()), count);
|
|
463
|
+
break;
|
|
464
|
+
case "step":
|
|
465
|
+
if (stepMode) {
|
|
466
|
+
push(steps, `${"– ".repeat(depth)}${n.title.trim()}`, count);
|
|
467
|
+
walk(n.steps, depth + 1);
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
walk(n.steps, depth);
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
walk(nodes, 0);
|
|
477
|
+
const outSteps = render(steps, maxSteps);
|
|
478
|
+
if (!stepMode && apiCalls > 0 && (outSteps.length > 0 || expected.length > 0)) {
|
|
479
|
+
outSteps.unshift(`Set up test data (${apiCalls} API call${apiCalls === 1 ? "" : "s"})`);
|
|
480
|
+
}
|
|
481
|
+
return { steps: outSteps, expected: render(expected, maxExpected) };
|
|
482
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult } from "@playwright/test/reporter";
|
|
2
|
+
import { Env, GitRunner } from "../../core/src/ci";
|
|
3
|
+
import { Logger } from "../../core/src/http";
|
|
4
|
+
import { AttachmentMode, PendingResult } from "../../core/src/results";
|
|
5
|
+
export { buildPlaywrightId, stripCaseTags, extractCaseTags, buildTags } from "../../core/src/automationId";
|
|
6
|
+
export { detectCi, defaultRunName } from "../../core/src/ci";
|
|
7
|
+
export { mapOutcome, mapPlaywrightStatus, shouldReplace, statusRank } from "../../core/src/results";
|
|
8
|
+
export { convertPlaywrightSteps, prettifyLocator } from "../../core/src/steps";
|
|
9
|
+
export interface PlanitroReporterOptions {
|
|
10
|
+
/** Planitro base URL, e.g. `https://planitro.app`. Env: `PLANITRO_URL`. */
|
|
11
|
+
url?: string;
|
|
12
|
+
/** Project API key (`pltr_…`, scope `tests:write`). Env: `PLANITRO_API_KEY`. */
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
/** Run name. Env: `PLANITRO_RUN_NAME`. Default `<branch> · <short sha>` or `Local run <date>`. */
|
|
15
|
+
runName?: string;
|
|
16
|
+
/** Release name (`v1.8.0`) or id. Env: `PLANITRO_RELEASE`. */
|
|
17
|
+
release?: string;
|
|
18
|
+
/** Create cases for unknown automation ids. Env: `PLANITRO_AUTO_CREATE`. Default true. */
|
|
19
|
+
autoCreate?: boolean;
|
|
20
|
+
/** Report into this existing run and do not complete it (sharding). Env: `PLANITRO_RUN_ID`. */
|
|
21
|
+
runId?: string | number;
|
|
22
|
+
/** Which attachments to upload: `failures` (default), `all`, `none` (or true/false). Env: `PLANITRO_UPLOAD_ATTACHMENTS`. */
|
|
23
|
+
uploadAttachments?: AttachmentMode | boolean;
|
|
24
|
+
/** Results per request (max 500). Default 50. */
|
|
25
|
+
batchSize?: number;
|
|
26
|
+
/** Send queued results at least this often. Default 2000 ms. */
|
|
27
|
+
flushIntervalMs?: number;
|
|
28
|
+
/** Max time onEnd waits for pending requests. Default 60000 ms. */
|
|
29
|
+
endTimeoutMs?: number;
|
|
30
|
+
/** HTTP retries for network errors / 429 / 5xx. Default 3. */
|
|
31
|
+
retries?: number;
|
|
32
|
+
/** Testing hooks. */
|
|
33
|
+
env?: Env;
|
|
34
|
+
logger?: Logger;
|
|
35
|
+
git?: GitRunner;
|
|
36
|
+
}
|
|
37
|
+
interface ResolvedOptions {
|
|
38
|
+
url?: string;
|
|
39
|
+
apiKey?: string;
|
|
40
|
+
runName?: string;
|
|
41
|
+
release?: string;
|
|
42
|
+
autoCreate: boolean;
|
|
43
|
+
runId?: string;
|
|
44
|
+
uploadAttachments: AttachmentMode;
|
|
45
|
+
batchSize: number;
|
|
46
|
+
flushIntervalMs: number;
|
|
47
|
+
endTimeoutMs: number;
|
|
48
|
+
retries: number;
|
|
49
|
+
}
|
|
50
|
+
/** Options win over environment variables. */
|
|
51
|
+
export declare function resolveOptions(o: PlanitroReporterOptions, env: Env): ResolvedOptions;
|
|
52
|
+
/** Titles of the describe blocks around a test, outermost first. */
|
|
53
|
+
export declare function describeTitles(test: TestCase): string[];
|
|
54
|
+
/**
|
|
55
|
+
* Is this the last attempt Playwright will make for the test? A failed attempt with retries left is followed
|
|
56
|
+
* by another one, so it is held back. `test.outcome()` already accounts for `test.fail()` (expected failures).
|
|
57
|
+
*/
|
|
58
|
+
export declare function isFinalAttempt(test: TestCase, result: TestResult): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Playwright reporter that sends results to Planitro Tests. Never fails or throws into the test run: every
|
|
61
|
+
* Planitro problem is logged as a warning and swallowed.
|
|
62
|
+
*
|
|
63
|
+
* Tests that run in several Playwright projects (chromium + firefox) share one automation_id and therefore one
|
|
64
|
+
* Planitro case; the run keeps the WORST status of them (failed > passed > skipped).
|
|
65
|
+
*/
|
|
66
|
+
export default class PlanitroReporter implements Reporter {
|
|
67
|
+
private readonly opts;
|
|
68
|
+
private readonly env;
|
|
69
|
+
private readonly log;
|
|
70
|
+
private readonly git;
|
|
71
|
+
private client?;
|
|
72
|
+
private sender?;
|
|
73
|
+
private config?;
|
|
74
|
+
private runIdP?;
|
|
75
|
+
private resolveRunId?;
|
|
76
|
+
private started;
|
|
77
|
+
private runUrl?;
|
|
78
|
+
private external;
|
|
79
|
+
private timer?;
|
|
80
|
+
/** Latest non-final attempt per test id, sent at onEnd if no later attempt arrives (interrupted runs). */
|
|
81
|
+
private readonly pending;
|
|
82
|
+
private readonly enabled;
|
|
83
|
+
constructor(options?: PlanitroReporterOptions);
|
|
84
|
+
printsToStdio(): boolean;
|
|
85
|
+
onBegin(config: FullConfig, _suite: Suite): void;
|
|
86
|
+
/** Starts (once) the run creation, or adopts PLANITRO_RUN_ID. */
|
|
87
|
+
private startRun;
|
|
88
|
+
onTestBegin(_test: TestCase, _result: TestResult): void;
|
|
89
|
+
private createRun;
|
|
90
|
+
onTestEnd(test: TestCase, result: TestResult): void;
|
|
91
|
+
/** Builds the payload for a test's final attempt. */
|
|
92
|
+
toPending(test: TestCase, result: TestResult): PendingResult;
|
|
93
|
+
onEnd(_result: FullResult): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
export { PlanitroReporter };
|