reporting-labs 0.6.16 → 0.6.18
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 +104 -5
- package/dist/cypress/index.d.ts +163 -0
- package/dist/cypress/index.js +623 -0
- package/dist/cypress/support.d.ts +21 -0
- package/dist/cypress/support.js +357 -0
- package/dist/explain.js +112 -0
- package/dist/template.html +1 -1
- package/dist/template.js +1 -1
- package/dist/wdio/finalize.d.ts +2 -39
- package/dist/wdio/finalize.js +3 -102
- package/dist/write-report.d.ts +51 -0
- package/dist/write-report.js +149 -0
- package/package.json +13 -1
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* reportingLabs support file for Cypress: runs in the browser, next to your tests.
|
|
4
|
+
*
|
|
5
|
+
* // cypress/support/e2e.js
|
|
6
|
+
* import 'reporting-labs/cypress/support';
|
|
7
|
+
*
|
|
8
|
+
* For every attempt of every test it collects what the Node-side plugin cannot see, and hands it over in an
|
|
9
|
+
* afterEach hook (cy.task, not logged):
|
|
10
|
+
* - the Cypress commands as steps (cy.get → type / click, assertions), hooks grouped, timings, the failing step
|
|
11
|
+
* - cy.request calls with their request and response, and the app's own fetch / XHR calls, for the API tab
|
|
12
|
+
* - the error of every attempt with Cypress's code frame (the Node side only gets the last one)
|
|
13
|
+
* - meta({ owner, priority, … }) called in the test
|
|
14
|
+
* - with @badeball/cypress-cucumber-preprocessor: the Gherkin steps (Given / When / Then) with the commands each ran,
|
|
15
|
+
* Before / After hooks, the steps a failure left unrun, and the scenario's line, tags, example row, data tables
|
|
16
|
+
* A value typed into a password field is masked here; everything else is masked by the plugin with the report's
|
|
17
|
+
* masking rules. Nothing in this file may ever fail a test: every handler is guarded.
|
|
18
|
+
*
|
|
19
|
+
* In a spec: import { meta } from 'reporting-labs/cypress/support'; … meta({ owner: 'asha', priority: 'P1' });
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.meta = meta;
|
|
23
|
+
const TASK = 'reportingLabs:attempt';
|
|
24
|
+
const ENABLED_FLAG = 'reportingLabsEnabled';
|
|
25
|
+
let logs = [];
|
|
26
|
+
let currentMeta = {};
|
|
27
|
+
/** Meta for the running test: priority, severity, owner, feature, story, issue… The same keys as meta() in Playwright. */
|
|
28
|
+
function meta(values) {
|
|
29
|
+
try {
|
|
30
|
+
if (values && typeof values === 'object')
|
|
31
|
+
Object.assign(currentMeta, values);
|
|
32
|
+
}
|
|
33
|
+
catch { /* never fail a test */ }
|
|
34
|
+
}
|
|
35
|
+
const guard = (fn) => { try {
|
|
36
|
+
fn();
|
|
37
|
+
}
|
|
38
|
+
catch { /* never fail a test */ } };
|
|
39
|
+
if (typeof Cypress !== 'undefined') {
|
|
40
|
+
Cypress.on('test:before:run', () => guard(() => { logs = []; currentMeta = {}; }));
|
|
41
|
+
Cypress.on('log:added', (_attrs, log) => guard(() => {
|
|
42
|
+
const runnable = Cypress.state && Cypress.state('runnable');
|
|
43
|
+
const hook = runnable && runnable.type === 'hook' ? String(runnable.hookName || runnable.title || 'hook') : undefined;
|
|
44
|
+
const el = log.get('$el');
|
|
45
|
+
const field = el && el[0];
|
|
46
|
+
const masked = log.get('name') === 'type' && !!field && /^(password)$/i.test(String(field.type || ''));
|
|
47
|
+
logs.push({ log, start: toMs(log.get('wallClockStartedAt')) || Date.now(), hook, masked });
|
|
48
|
+
}));
|
|
49
|
+
afterEach(function () {
|
|
50
|
+
// only when the plugin is registered in setupNodeEvents (it sets this flag); otherwise cy.task would fail the test
|
|
51
|
+
let enabled = false;
|
|
52
|
+
try {
|
|
53
|
+
enabled = typeof Cypress.expose === 'function' ? !!Cypress.expose(ENABLED_FLAG) : !!Cypress.env(ENABLED_FLAG);
|
|
54
|
+
}
|
|
55
|
+
catch { /* not enabled */ }
|
|
56
|
+
if (!enabled)
|
|
57
|
+
return;
|
|
58
|
+
let payload;
|
|
59
|
+
try {
|
|
60
|
+
payload = build(this.currentTest);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// log: false keeps it out of the command log; a failed handover must not fail the test
|
|
66
|
+
cy.task(TASK, payload, { log: false, timeout: 20000 });
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function build(t) {
|
|
70
|
+
const start = toMs(t.wallClockStartedAt) || (logs[0]?.start ?? Date.now());
|
|
71
|
+
const duration = typeof t.duration === 'number' ? t.duration : Math.max(0, Date.now() - start);
|
|
72
|
+
const err = t.err ? {
|
|
73
|
+
message: String(t.err.message ?? t.err),
|
|
74
|
+
stack: t.err.stack ? String(t.err.stack) : undefined,
|
|
75
|
+
codeFrame: t.err.codeFrame ? { line: t.err.codeFrame.line, column: t.err.codeFrame.column, relativeFile: t.err.codeFrame.relativeFile, frame: t.err.codeFrame.frame } : undefined,
|
|
76
|
+
} : undefined;
|
|
77
|
+
const retry = typeof t.currentRetry === 'function' ? t.currentRetry() : (t._currentRetry ?? 0);
|
|
78
|
+
return {
|
|
79
|
+
spec: Cypress.spec && (Cypress.spec.relative || Cypress.spec.name),
|
|
80
|
+
titlePath: typeof t.titlePath === 'function' ? t.titlePath() : [t.title],
|
|
81
|
+
retry, state: t.state, start, duration, err,
|
|
82
|
+
steps: steps(start + duration, err?.message, t),
|
|
83
|
+
api: api(),
|
|
84
|
+
meta: currentMeta,
|
|
85
|
+
gherkin: gherkin(t),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const clean = (s) => String(s ?? '').replace(/\*\*/g, '').replace(/\s+/g, ' ').trim();
|
|
89
|
+
const SKIP = new Set(['new url', 'page load', 'route', 'xhr', 'fetch', 'task', 'log']);
|
|
90
|
+
const HOOKS = /^(Before|After|BeforeStep|AfterStep|BeforeAll|AfterAll)$/;
|
|
91
|
+
/** Commands as steps: hooks grouped, chained commands under their parent, assertions under what they check, commands
|
|
92
|
+
* inside a log group (a Gherkin step, cy.within, a custom command that opens a group) under that group. */
|
|
93
|
+
function steps(end, errMsg, t) {
|
|
94
|
+
const g = scenario(t);
|
|
95
|
+
const items = logs.filter(c => {
|
|
96
|
+
const name = c.log.get('name');
|
|
97
|
+
if (SKIP.has(name) && name !== 'route')
|
|
98
|
+
return false;
|
|
99
|
+
if (c.log.get('event'))
|
|
100
|
+
return false; // page loads, url changes, the app's own fetch / XHR (those go to the API tab)
|
|
101
|
+
if (c.log.get('hidden'))
|
|
102
|
+
return false;
|
|
103
|
+
if (g && name === 'DataTable')
|
|
104
|
+
return false; // sent with the scenario (see gherkin())
|
|
105
|
+
return true;
|
|
106
|
+
});
|
|
107
|
+
const out = [];
|
|
108
|
+
const parents = new Map(); // chainerId → parent step
|
|
109
|
+
const groups = new Map(); // log id of a group → its step
|
|
110
|
+
const up = new Map(); // step → the step it is under
|
|
111
|
+
// a step's time and failure count for every step it is under
|
|
112
|
+
const add = (parent, step) => {
|
|
113
|
+
parent.steps.push(step);
|
|
114
|
+
up.set(step, parent);
|
|
115
|
+
for (let p = parent; p; p = up.get(p)) {
|
|
116
|
+
p.duration += step.duration;
|
|
117
|
+
if (step.error)
|
|
118
|
+
p.error = step.error;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
let hookStep, hookName;
|
|
122
|
+
let ran = 0; // Gherkin steps that started (the rest of the scenario's steps did not run)
|
|
123
|
+
items.forEach((c, i) => {
|
|
124
|
+
const next = items[i + 1];
|
|
125
|
+
const name = String(c.log.get('name') || '');
|
|
126
|
+
let message = clean(c.log.get('message'));
|
|
127
|
+
if (c.masked)
|
|
128
|
+
message = '****';
|
|
129
|
+
if (name === 'request' && !message)
|
|
130
|
+
message = clean(display(c.log)); // "POST 200 /api/users"
|
|
131
|
+
const isAssert = name === 'assert';
|
|
132
|
+
const group = !!c.log.get('groupStart');
|
|
133
|
+
const inGroup = groups.get(String(c.log.get('group') ?? ''));
|
|
134
|
+
const gherkinHook = !!g && group && HOOKS.test(name.trim());
|
|
135
|
+
const gherkinStep = !!g && group && !gherkinHook && /^\*\*[\s\S]*\*\*$/.test(String(c.log.get('message') ?? '').trim());
|
|
136
|
+
const step = {
|
|
137
|
+
title: gherkinHook ? `${name.trim()} hook${message ? ': ' + message : ''}`
|
|
138
|
+
: gherkinStep ? `${name.trim()} ${message}`
|
|
139
|
+
: name === 'route' ? clean(routeTitle(c.log)) : isAssert ? message : `${name}${message ? ' ' + message : ''}`,
|
|
140
|
+
category: gherkinHook ? 'hook' : gherkinStep ? 'test.step' : isAssert ? 'assert' : 'cy',
|
|
141
|
+
duration: Math.max(0, (next ? next.start : end) - c.start),
|
|
142
|
+
steps: [],
|
|
143
|
+
};
|
|
144
|
+
if (gherkinStep && !inGroup)
|
|
145
|
+
ran++;
|
|
146
|
+
if (c.log.get('state') === 'failed')
|
|
147
|
+
step.error = clean(errMsg || c.log.get('err')?.message || 'failed');
|
|
148
|
+
// the hook it ran in: one step per hook, the commands inside
|
|
149
|
+
let container;
|
|
150
|
+
if (c.hook) {
|
|
151
|
+
if (!hookStep || hookName !== c.hook) {
|
|
152
|
+
hookName = c.hook;
|
|
153
|
+
hookStep = { title: `${camel(c.hook)} hook`, category: 'hook', duration: 0, steps: [] };
|
|
154
|
+
out.push(hookStep);
|
|
155
|
+
}
|
|
156
|
+
container = hookStep;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
hookStep = undefined;
|
|
160
|
+
hookName = undefined;
|
|
161
|
+
}
|
|
162
|
+
const chainer = String(c.log.get('chainerId') || '');
|
|
163
|
+
const parent = c.log.get('type') === 'child' ? parents.get(chainer) : undefined;
|
|
164
|
+
const under = parent ?? inGroup ?? container;
|
|
165
|
+
if (under)
|
|
166
|
+
add(under, step);
|
|
167
|
+
else
|
|
168
|
+
out.push(step);
|
|
169
|
+
if (!parent && chainer)
|
|
170
|
+
parents.set(chainer, step);
|
|
171
|
+
if (group)
|
|
172
|
+
groups.set(String(c.log.get('id') ?? ''), step);
|
|
173
|
+
});
|
|
174
|
+
// Cucumber stops a scenario at the first failing step: the steps after it are listed, greyed out. A step whose
|
|
175
|
+
// definition returned "pending" is greyed out too.
|
|
176
|
+
if (g && t && t.state === 'pending') {
|
|
177
|
+
const last = [...out].reverse().find(x => x.category === 'test.step');
|
|
178
|
+
if (last && !last.error)
|
|
179
|
+
last.status = 'skipped';
|
|
180
|
+
}
|
|
181
|
+
if (g)
|
|
182
|
+
for (const ps of g.pickle.steps.slice(ran))
|
|
183
|
+
out.push({ title: `${keywordOf(g, ps)} ${ps.text}`, category: 'test.step', duration: 0, status: 'skipped', steps: [] });
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
function camel(hookName) {
|
|
187
|
+
const m = /^(before|after) (each|all)$/i.exec(hookName.replace(/"/g, '').replace(/ hook.*$/i, '').trim());
|
|
188
|
+
return m ? m[1].toLowerCase() + (m[2].toLowerCase() === 'each' ? 'Each' : 'All') : hookName;
|
|
189
|
+
}
|
|
190
|
+
function routeTitle(log) {
|
|
191
|
+
const p = props(log);
|
|
192
|
+
return `intercept ${p.Method ?? ''} ${p.URL ?? p.Matcher ?? ''}${p.Alias ? ' as @' + p.Alias : ''}`;
|
|
193
|
+
}
|
|
194
|
+
/** The text Cypress shows on the command line, e.g. "POST 200 /api/users" for cy.request. */
|
|
195
|
+
function display(log) {
|
|
196
|
+
try {
|
|
197
|
+
const rp = log.get('renderProps');
|
|
198
|
+
const v = typeof rp === 'function' ? rp() : rp;
|
|
199
|
+
return String(v?.message ?? '');
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return '';
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function toMs(v) {
|
|
206
|
+
if (!v)
|
|
207
|
+
return 0;
|
|
208
|
+
const n = v instanceof Date ? v.getTime() : new Date(v).getTime();
|
|
209
|
+
return Number.isFinite(n) ? n : 0;
|
|
210
|
+
}
|
|
211
|
+
function props(log) {
|
|
212
|
+
try {
|
|
213
|
+
const cp = typeof log.invoke === 'function' ? log.invoke('consoleProps') : log.get('consoleProps');
|
|
214
|
+
const v = typeof cp === 'function' ? cp() : cp;
|
|
215
|
+
return (v && (v.props ?? v)) || {};
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return {};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** cy.request (with request and response) and the app's fetch / XHR calls. */
|
|
222
|
+
function api() {
|
|
223
|
+
const out = [];
|
|
224
|
+
for (const c of logs) {
|
|
225
|
+
const name = c.log.get('name');
|
|
226
|
+
if (name !== 'request' && name !== 'xhr' && name !== 'fetch')
|
|
227
|
+
continue;
|
|
228
|
+
const p = props(c.log);
|
|
229
|
+
if (c.log.get('event') || name !== 'request') {
|
|
230
|
+
// the app's own fetch / XHR: method, URL, status once answered; headers and body when Cypress kept them
|
|
231
|
+
const shown = display(c.log); // "GET 200 /api/users" once answered
|
|
232
|
+
const status = Number(p['Response Status Code'] ?? p.Status ?? (shown.match(/^\w+\s+(\d{3})\b/) || [])[1]) || undefined;
|
|
233
|
+
if (p.URL)
|
|
234
|
+
out.push({ method: String(p.Method || shown.split(' ')[0] || 'GET').toUpperCase(), url: String(p.URL), status,
|
|
235
|
+
requestHeaders: p['Request Headers'], requestBody: parse(p['Request Body']), responseHeaders: p['Response Headers'], responseBody: parse(p['Response Body']) });
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const reqs = Array.isArray(p.Requests) ? p.Requests : p.Request ? [p.Request] : [];
|
|
239
|
+
const yielded = p.Yielded || {};
|
|
240
|
+
for (const r of reqs.length ? reqs : [{}]) {
|
|
241
|
+
const url = r['Request URL'] ?? yielded.url ?? p.URL;
|
|
242
|
+
if (!url)
|
|
243
|
+
continue;
|
|
244
|
+
out.push({
|
|
245
|
+
method: String(r['Request Method'] ?? display(c.log).split(' ')[0] ?? 'GET').toUpperCase() || 'GET',
|
|
246
|
+
url: String(url),
|
|
247
|
+
status: Number(r['Response Status'] ?? yielded.status) || undefined,
|
|
248
|
+
duration: typeof yielded.duration === 'number' ? yielded.duration : undefined,
|
|
249
|
+
requestHeaders: r['Request Headers'], requestBody: parse(r['Request Body']),
|
|
250
|
+
responseHeaders: r['Response Headers'], responseBody: parse(r['Response Body'] ?? yielded.body),
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
function parse(v) {
|
|
257
|
+
if (typeof v !== 'string')
|
|
258
|
+
return v;
|
|
259
|
+
try {
|
|
260
|
+
return JSON.parse(v);
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
return v;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const astCache = new WeakMap();
|
|
267
|
+
/** The scenario this test runs, or undefined (not a feature file, or the state belongs to another test). */
|
|
268
|
+
function scenario(t) {
|
|
269
|
+
try {
|
|
270
|
+
const ts = globalThis.testState;
|
|
271
|
+
const pickle = ts && ts.pickle;
|
|
272
|
+
if (!pickle || !ts.gherkinDocument || !Array.isArray(pickle.steps))
|
|
273
|
+
return undefined;
|
|
274
|
+
const title = String((t && t.title) || '');
|
|
275
|
+
const name = String(pickle.name || '');
|
|
276
|
+
if (title && name && title !== name && !title.startsWith(name + ' (example #'))
|
|
277
|
+
return undefined;
|
|
278
|
+
let ast = astCache.get(ts.gherkinDocument);
|
|
279
|
+
if (!ast) {
|
|
280
|
+
ast = index(ts.gherkinDocument);
|
|
281
|
+
astCache.set(ts.gherkinDocument, ast);
|
|
282
|
+
}
|
|
283
|
+
return { doc: ts.gherkinDocument, pickle, step: ts.pickleStep, ast };
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/** Every Background / Scenario step, Scenario and Examples row of the feature by its id. */
|
|
290
|
+
function index(doc) {
|
|
291
|
+
const m = new Map();
|
|
292
|
+
const visit = (children, rule) => {
|
|
293
|
+
for (const ch of children || []) {
|
|
294
|
+
const bg = ch.background;
|
|
295
|
+
if (bg)
|
|
296
|
+
for (const st of bg.steps || [])
|
|
297
|
+
m.set(st.id, { step: st });
|
|
298
|
+
const sc = ch.scenario;
|
|
299
|
+
if (sc) {
|
|
300
|
+
m.set(sc.id, { scenario: sc, rule });
|
|
301
|
+
for (const st of sc.steps || [])
|
|
302
|
+
m.set(st.id, { step: st });
|
|
303
|
+
for (const ex of sc.examples || [])
|
|
304
|
+
for (const row of ex.tableBody || [])
|
|
305
|
+
m.set(row.id, { row, examples: ex });
|
|
306
|
+
}
|
|
307
|
+
if (ch.rule)
|
|
308
|
+
visit(ch.rule.children, ch.rule);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
visit(doc.feature && doc.feature.children);
|
|
312
|
+
return m;
|
|
313
|
+
}
|
|
314
|
+
function keywordOf(g, ps) {
|
|
315
|
+
const node = g.ast.get(ps && ps.astNodeIds && ps.astNodeIds[0]);
|
|
316
|
+
return String((node && node.step && node.step.keyword) || '').trim() || '*';
|
|
317
|
+
}
|
|
318
|
+
function lineOf(g, ps) {
|
|
319
|
+
const node = g.ast.get(ps && ps.astNodeIds && ps.astNodeIds[0]);
|
|
320
|
+
return node && node.step && node.step.location ? node.step.location.line : undefined;
|
|
321
|
+
}
|
|
322
|
+
/** What the report needs about the scenario: where it is, its tags, its example row, data tables and doc strings. */
|
|
323
|
+
function gherkin(t) {
|
|
324
|
+
const g = scenario(t);
|
|
325
|
+
if (!g)
|
|
326
|
+
return undefined;
|
|
327
|
+
const ids = g.pickle.astNodeIds || [];
|
|
328
|
+
const sc = g.ast.get(ids[0]) || {};
|
|
329
|
+
const row = ids.length > 1 ? g.ast.get(ids[ids.length - 1]) : undefined;
|
|
330
|
+
const f = g.doc.feature || {};
|
|
331
|
+
const out = {
|
|
332
|
+
feature: f.name, rule: sc.rule && sc.rule.name,
|
|
333
|
+
keyword: sc.scenario && sc.scenario.keyword,
|
|
334
|
+
line: (row && row.row && row.row.location && row.row.location.line) || (sc.scenario && sc.scenario.location && sc.scenario.location.line),
|
|
335
|
+
tags: (g.pickle.tags || []).map((x) => String(x.name)),
|
|
336
|
+
};
|
|
337
|
+
if (row && row.row && row.examples) {
|
|
338
|
+
out.example = { header: (row.examples.tableHeader && row.examples.tableHeader.cells || []).map((c) => String(c.value)), values: (row.row.cells || []).map((c) => String(c.value)) };
|
|
339
|
+
}
|
|
340
|
+
const args = [];
|
|
341
|
+
for (const ps of g.pickle.steps) {
|
|
342
|
+
const a = ps.argument;
|
|
343
|
+
if (!a)
|
|
344
|
+
continue;
|
|
345
|
+
const step = `${keywordOf(g, ps)} ${ps.text}`;
|
|
346
|
+
if (a.dataTable)
|
|
347
|
+
args.push({ step, table: (a.dataTable.rows || []).map((r) => (r.cells || []).map((c) => String(c.value))) });
|
|
348
|
+
else if (a.docString)
|
|
349
|
+
args.push({ step, docString: String(a.docString.content ?? '') });
|
|
350
|
+
}
|
|
351
|
+
if (args.length)
|
|
352
|
+
out.args = args;
|
|
353
|
+
// the step that was running when the test stopped: failed, or returned "pending"
|
|
354
|
+
if (g.step && (t.state === 'failed' || t.state === 'pending'))
|
|
355
|
+
out.stoppedAt = { step: `${keywordOf(g, g.step)} ${g.step.text}`, line: lineOf(g, g.step), state: t.state };
|
|
356
|
+
return out;
|
|
357
|
+
}
|
package/dist/explain.js
CHANGED
|
@@ -55,6 +55,10 @@ function explainError(raw) {
|
|
|
55
55
|
// ── The browser process died (memory, too many workers): infrastructure, not the app or the test ──
|
|
56
56
|
if (/Target crashed|Page crashed|page has crashed|Renderer process crashed|tab crashed|session deleted because of page crash|chrome not reachable|Browsing context has been discarded/i.test(msg))
|
|
57
57
|
return out('crashed', 'The browser crashed while the test was running.', 'Not a bug in the app or the test: the browser process died, usually from memory pressure or too many parallel workers. Re-run it; if it keeps happening, lower workers or give the machine more memory.', { action });
|
|
58
|
+
// ── Cypress (and chai-style assertions): only messages in Cypress's own wording reach these rules ──
|
|
59
|
+
const cy = explainCypress(msg, out);
|
|
60
|
+
if (cy)
|
|
61
|
+
return cy;
|
|
58
62
|
// ── Strict mode ──────────────────────────────────────────────────────────
|
|
59
63
|
m = msg.match(/strict mode violation: (.+?) resolved to (\d+) elements/s);
|
|
60
64
|
if (m)
|
|
@@ -162,3 +166,111 @@ function explainError(raw) {
|
|
|
162
166
|
return out('thrown', short(first.replace(/^Error: /, '')), 'The test (or a helper) threw this error on purpose or via a failed check. The stack trace below points at the line.');
|
|
163
167
|
return out('thrown', short(first), 'See the full message and stack trace below.');
|
|
164
168
|
}
|
|
169
|
+
/** Cypress messages: `Timed out retrying after 4000ms: …`, `cy.click()` failed because …, cy.request / cy.visit /
|
|
170
|
+
* cy.wait failures, uncaught application errors, and chai assertions (`expected 'a' to equal 'b'`). */
|
|
171
|
+
function explainCypress(msg, out) {
|
|
172
|
+
const body = msg.replace(/^(?:AssertionError|CypressError|Error):\s*/, '');
|
|
173
|
+
const retry = body.match(/^Timed out retrying after (\d+)ms:\s*/);
|
|
174
|
+
const timeoutMs = retry ? Number(retry[1]) : undefined;
|
|
175
|
+
const text = retry ? body.slice(retry[0].length) : body;
|
|
176
|
+
const within = timeoutMs ? ' within ' + secs(timeoutMs) : '';
|
|
177
|
+
const cmd = pick(text, /`?(cy\.\w+)\(\)`?\s+(?:failed|timed out|could not)/);
|
|
178
|
+
const isCy = !!retry || !!cmd || /CypressError|originated from your application code|for your remote page to load|error preparing this test file|^`?cy\.\w+\(\)/.test(msg);
|
|
179
|
+
const chai = text.match(/^expected ([\s\S]+?) (?:not to|to(?: (not))?) (deeply equal|have length|have text|have value|equal|eql|be|have|include|contain|match|exist)\b\s*([\s\S]*)$/);
|
|
180
|
+
// ── Cucumber (@badeball/cypress-cucumber-preprocessor): a step with no step definition, or with several ──
|
|
181
|
+
let g = text.match(/Step implementation missing for:? "?([^\n]+?)"?\.?\s*(?:\n|$)/);
|
|
182
|
+
if (g)
|
|
183
|
+
return out('script', `The step "${short(g[1], 90)}" has no step definition.`, 'Add a Given / When / Then for it in your step definitions (the error shows a snippet), or check the stepDefinitions paths in the preprocessor config.', { label: 'Step not defined' });
|
|
184
|
+
g = text.match(/Multiple matching step definitions for:? "?([^\n]+?)"?\s*(?:\n|$)/);
|
|
185
|
+
if (g)
|
|
186
|
+
return out('script', `More than one step definition matches "${short(g[1], 90)}".`, 'Make the step texts or their expressions differ, so exactly one step definition matches.', { label: 'Step defined twice' });
|
|
187
|
+
if (!isCy && !chai)
|
|
188
|
+
return undefined;
|
|
189
|
+
// ── the spec file itself could not be bundled / loaded: no test in it ran ──
|
|
190
|
+
if (/error preparing this test file/.test(msg)) {
|
|
191
|
+
const why = pick(msg, /Module not found: Error: ([^\n]+?)(?: in '[^']*')?$/m) ?? pick(msg, /^((?:SyntaxError|TypeError|ReferenceError|Error):(?! Webpack)[^\n]+)$/m);
|
|
192
|
+
return out('script', `The spec file could not be loaded${why ? ': ' + short(why, 110) : ''}. No test in it ran.`, 'Fix the import path or the syntax error in the spec (or in a file it imports).');
|
|
193
|
+
}
|
|
194
|
+
// ── the app threw, not the test ──
|
|
195
|
+
if (/originated from your application code, not from Cypress/.test(msg)) {
|
|
196
|
+
const appErr = pick(msg, /^\s*>\s*(.+)$/m);
|
|
197
|
+
return out('script', `The application threw an uncaught error${appErr ? ': ' + short(appErr, 100) : ''}. Cypress fails the test when the app throws.`, 'Fix the error in the app, or if it is expected, ignore it with Cypress.on(\'uncaught:exception\', () => false) for that test.');
|
|
198
|
+
}
|
|
199
|
+
// ── element lookups ──
|
|
200
|
+
let m = text.match(/Expected to find element: `?([^`\n]+?)`?, but never found it/);
|
|
201
|
+
if (m)
|
|
202
|
+
return out('not-found', `${m[1]} was not on the page${within}.`, 'Check the selector, and whether the element is inside an iframe, behind a login, or only shown after a click.', { locator: m[1], timeoutMs });
|
|
203
|
+
m = text.match(/Expected to find content: '([^']*)'(?: within the (?:element|selector): ([^\n]+?))?,? but never did/);
|
|
204
|
+
if (m)
|
|
205
|
+
return out('not-found', `The text "${short(m[1], 60)}" did not appear${m[2] ? ' inside ' + short(m[2].replace(/`/g, ''), 60) : ''}${within}.`, 'Check the expected text (case, spaces) and whether the page finished loading.', { locator: m[2]?.replace(/`/g, ''), timeoutMs });
|
|
206
|
+
m = text.match(/Expected not to find element: `?([^`\n]+?)`?, but it was continuously found/);
|
|
207
|
+
if (m)
|
|
208
|
+
return out('assertion', `${m[1]} was still on the page${within}, but should have gone.`, 'Something kept it on screen. Check the step that should remove or hide it.', { locator: m[1], timeoutMs });
|
|
209
|
+
m = text.match(/Not enough elements found\. Found '(\d+)', expected '(\d+)'|Too many elements found\. Found '(\d+)', expected '(\d+)'/);
|
|
210
|
+
if (m)
|
|
211
|
+
return out('assertion', `The selector matched ${m[1] ?? m[3]} elements, expected ${m[2] ?? m[4]}${within}.`, 'The list may not have finished loading, or the selector also matches other elements.', { timeoutMs });
|
|
212
|
+
// ── actions: cy.click() failed because this element … ──
|
|
213
|
+
if (cmd && /failed because/.test(text)) {
|
|
214
|
+
const el = pick(text, /this element:?\s*\n*\s*`?(<[^`\n]+>)`?/) ?? pick(text, /`(<[^`\n]+>)`/);
|
|
215
|
+
const base = { action: cmd, locator: el, timeoutMs };
|
|
216
|
+
if (/is being covered by another element/.test(text)) {
|
|
217
|
+
const by = pick(text, /covered by another element:?\s*\n*\s*`?(<[^`\n]+>)`?/);
|
|
218
|
+
return out('blocked', `${cmd}() could not reach ${el ?? 'the element'}: ${by ? short(by, 60) : 'another element'} is on top of it.`, 'A dialog, banner, overlay or spinner is in the way. Close or wait for it first.', base);
|
|
219
|
+
}
|
|
220
|
+
if (/is not visible/.test(text))
|
|
221
|
+
return out('not-visible', `${cmd}() could not use ${el ?? 'the element'} because it is not visible.`, 'It may be hidden by CSS, off screen in a closed menu, or still animating in.', base);
|
|
222
|
+
if (/is disabled/.test(text))
|
|
223
|
+
return out('disabled', `${cmd}() could not use ${el ?? 'the element'} because it is disabled.`, 'The form may need another field filled first, or the app is still busy.', base);
|
|
224
|
+
if (/page updated while this command was executing|detached from the DOM/.test(text))
|
|
225
|
+
return out('detached', `The element was re-rendered while ${cmd}() was using it.`, 'The UI replaced the element. Query it again after the change, or wait for the update to finish.', base);
|
|
226
|
+
if (/can only be called on|requires a DOM element|requires a valid subject|can only be called on a single element/.test(text))
|
|
227
|
+
return out('wrong-element', `${cmd}() was used on something it does not work on.`, 'Check the command before it: the subject may be several elements, or not an element at all.', base);
|
|
228
|
+
}
|
|
229
|
+
// ── cy.request / cy.visit / cy.wait ──
|
|
230
|
+
if (cmd === 'cy.request') {
|
|
231
|
+
const url = pick(text, /failed on:\s*\n+\s*(https?:\/\/\S+)/);
|
|
232
|
+
const st = text.match(/>\s*(\d{3}):\s*([^\n]*)/);
|
|
233
|
+
if (/timed out waiting/.test(text))
|
|
234
|
+
return out('api', `The API request${url ? ' to ' + url : ''} did not answer in time.`, 'The API may be slow or hanging. Check its logs, or raise the timeout of cy.request.', { action: cmd, url });
|
|
235
|
+
if (st)
|
|
236
|
+
return out('api', `The API answered ${st[1]}${st[2] ? ' ' + st[2].trim() : ''}${url ? ' for ' + url : ''}.`, Number(st[1]) >= 500 ? 'A server error: check the API logs for this request.' : 'Check the request (URL, auth, body). If this status is expected, pass failOnStatusCode: false.', { action: cmd, url });
|
|
237
|
+
if (/failed without a response|ECONNREFUSED|ENOTFOUND/.test(text))
|
|
238
|
+
return out('network', `The API${url ? ' at ' + url : ''} could not be reached.`, 'Check the URL and that the API is up. In CI, make sure it starts before the tests.', { action: cmd, url });
|
|
239
|
+
}
|
|
240
|
+
if (cmd === 'cy.visit' || /for your remote page to load/.test(text)) {
|
|
241
|
+
const url = pick(text, /failed trying to load:\s*\n+\s*(https?:\/\/\S+)/);
|
|
242
|
+
const st = text.match(/>\s*(\d{3}):\s*([^\n]*)/);
|
|
243
|
+
if (/for your remote page to load/.test(text))
|
|
244
|
+
return out('navigation', `The page did not finish loading${pick(text, /waiting `?(\d+)ms`?/) ? ' within ' + secs(Number(pick(text, /waiting `?(\d+)ms`?/))) : ''}.`, 'The app may be slow or stuck on a request. Raise pageLoadTimeout only if the page is really that slow.', { action: 'cy.visit', url });
|
|
245
|
+
if (/failed without a response|ECONNREFUSED|ENOTFOUND|ECONNRESET/.test(text))
|
|
246
|
+
return out('network', `The browser could not reach ${url ?? 'the site'}.`, 'Check baseUrl and that the app is running. In CI, make sure the web server starts before the tests.', { action: 'cy.visit', url });
|
|
247
|
+
if (st)
|
|
248
|
+
return out('navigation', `${url ?? 'The page'} answered ${st[1]}${st[2] ? ' ' + st[2].trim() : ''}.`, 'Check the URL. If this status is expected, pass failOnStatusCode: false to cy.visit.', { action: 'cy.visit', url });
|
|
249
|
+
}
|
|
250
|
+
m = text.match(/`?cy\.wait\(\)`? timed out waiting `?(\d+)ms`? for the \w+ (request|response) to the route: `?([^`\s.]+)`?/);
|
|
251
|
+
if (m)
|
|
252
|
+
return out('api', `No ${m[2]} for the route "${m[3]}" came within ${secs(Number(m[1]))}.`, m[2] === 'request' ? 'The app never made that call: check the cy.intercept() pattern (method, URL) and that the action triggering it ran.' : 'The call was made but did not answer in time: check the API.', { action: 'cy.wait', timeoutMs: Number(m[1]) });
|
|
253
|
+
if (cmd === 'cy.task' && /failed with the following error/.test(text))
|
|
254
|
+
return out('script', `The task ${pick(text, /cy\.task\('([^']+)'/) ?? ''} threw in the Cypress Node process.`.replace('task ', 'task '), 'See the full message below; the task code lives in setupNodeEvents.', { action: 'cy.task' });
|
|
255
|
+
// ── assertions (chai / should) ──
|
|
256
|
+
if (chai) {
|
|
257
|
+
const [, actual, notAfter, verb, restRaw] = chai;
|
|
258
|
+
const not = notAfter || (/^expected [\s\S]+? not to /.test(text) ? 'not ' : undefined);
|
|
259
|
+
const rest = restRaw.split('\n')[0].replace(/,\s*but[\s\S]*$/, '').replace(/ in the DOM$/, '').trim();
|
|
260
|
+
const butWas = pick(text, /but the (?:text|value) was '([^']*)'/);
|
|
261
|
+
const el = /^'?<[^>]+>'?$/.test(actual.trim()) ? actual.replace(/'/g, '') : undefined;
|
|
262
|
+
const base = { locator: el, timeoutMs };
|
|
263
|
+
if (verb === 'exist')
|
|
264
|
+
return out(not ? 'assertion' : 'not-found', not ? `${el ?? short(actual, 60)} still existed${within}.` : `${el ?? short(actual, 60)} did not exist${within}.`, not ? 'Something kept it on the page. Check the step that should remove it.' : 'Check the selector and whether the element appears only after another step.', base);
|
|
265
|
+
if (verb === 'be' && /^'?visible'?$/.test(rest) && !not)
|
|
266
|
+
return out('not-visible', `${el ?? 'The element'} was expected to be visible${within} but was not.`, 'It may still be loading, be hidden by CSS, or sit inside a closed menu or dialog.', base);
|
|
267
|
+
if ((verb === 'have text' || verb === 'have value') && butWas !== undefined)
|
|
268
|
+
return out('assertion', `${el ?? 'The element'} had the wrong ${verb === 'have text' ? 'text' : 'value'}: expected ${short(rest, 60)}, got '${short(butWas, 60)}'.`, 'Compare expected and received below. A copy change, a data change or a timing issue are the usual causes.', base);
|
|
269
|
+
if (/equal|eql/.test(verb) && !not)
|
|
270
|
+
return out('assertion', `Expected ${short(rest, 70)}, got ${short(actual, 70)}.`, 'Compare the two values in the full message below.', base);
|
|
271
|
+
if (/include|contain|match/.test(verb))
|
|
272
|
+
return out('assertion', `${short(actual, 70)} did ${not ? '' : 'not '}${verb === 'match' ? 'match' : 'contain'} ${short(rest, 70)}${within}.`, /^'https?:/.test(actual) ? 'The page may not have navigated yet, or went somewhere else (a redirect, a login screen, an error page).' : 'Compare the two values in the full message below.', base);
|
|
273
|
+
return out('assertion', `An assertion did not pass: expected ${short(actual, 60)} to ${not ?? ''}${verb} ${short(rest, 60)}${within}.`.replace(/\s+\./, '.'), 'See the full message below.', base);
|
|
274
|
+
}
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
package/dist/template.html
CHANGED
|
@@ -1712,7 +1712,7 @@ function select(id, quiet){
|
|
|
1712
1712
|
function renderDetail(t, d, retryIdx){
|
|
1713
1713
|
d=d||$('#detail'); d.innerHTML='';
|
|
1714
1714
|
const retry = retryIdx==null ? state.retry : retryIdx;
|
|
1715
|
-
d.append(h('div',{class:'crumb'}, [t.file, ...t.path.map(p=>data.bdd&&!/^Feature:/i.test(p)?'Feature: '+p:p)].map(p=>h('span',{},p))),
|
|
1715
|
+
d.append(h('div',{class:'crumb'}, [t.file, ...t.path.map(p=>data.bdd&&!/^(Feature|Rule):/i.test(p)?'Feature: '+p:p)].map(p=>h('span',{},p))),
|
|
1716
1716
|
h('div',{class:'titlebar'}, h('h3',{},t.title), h('div',{class:'actions'},
|
|
1717
1717
|
h('button',{class:'btn',onclick:e=>copyText(location.href.split('#')[0]+'#t='+t.id,e.currentTarget,'Link copied')},'Copy link'),
|
|
1718
1718
|
(()=>{ const r=t.results[t.results.length-1]; const e=r&&r.errors[0]; return e? [h('button',{class:'btn',onclick:ev=>copyText(t.title+'\n'+t.file+':'+t.line+'\n\n'+e.message,ev.currentTarget,'Error copied')},'Copy error'), h('button',{class:'btn primary',onclick:()=>openBugReport(t)},'Bug report')] : null; })(),
|
package/dist/template.js
CHANGED
|
@@ -1778,7 +1778,7 @@ function select(id, quiet){
|
|
|
1778
1778
|
function renderDetail(t, d, retryIdx){
|
|
1779
1779
|
d=d||$('#detail'); d.innerHTML='';
|
|
1780
1780
|
const retry = retryIdx==null ? state.retry : retryIdx;
|
|
1781
|
-
d.append(h('div',{class:'crumb'}, [t.file, ...t.path.map(p=>data.bdd&&!/^Feature:/i.test(p)?'Feature: '+p:p)].map(p=>h('span',{},p))),
|
|
1781
|
+
d.append(h('div',{class:'crumb'}, [t.file, ...t.path.map(p=>data.bdd&&!/^(Feature|Rule):/i.test(p)?'Feature: '+p:p)].map(p=>h('span',{},p))),
|
|
1782
1782
|
h('div',{class:'titlebar'}, h('h3',{},t.title), h('div',{class:'actions'},
|
|
1783
1783
|
h('button',{class:'btn',onclick:e=>copyText(location.href.split('#')[0]+'#t='+t.id,e.currentTarget,'Link copied')},'Copy link'),
|
|
1784
1784
|
(()=>{ const r=t.results[t.results.length-1]; const e=r&&r.errors[0]; return e? [h('button',{class:'btn',onclick:ev=>copyText(t.title+'\n'+t.file+':'+t.line+'\n\n'+e.message,ev.currentTarget,'Error copied')},'Copy error'), h('button',{class:'btn primary',onclick:()=>openBugReport(t)},'Bug report')] : null; })(),
|
package/dist/wdio/finalize.d.ts
CHANGED
|
@@ -1,40 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
outputFile?: string;
|
|
4
|
-
jsonFile?: string;
|
|
5
|
-
emitJson?: boolean;
|
|
6
|
-
pdf?: boolean | {
|
|
7
|
-
file?: string;
|
|
8
|
-
chromePath?: string;
|
|
9
|
-
};
|
|
10
|
-
title?: string;
|
|
11
|
-
logo?: string;
|
|
12
|
-
accent?: string;
|
|
13
|
-
theme?: 'auto' | 'light' | 'dark';
|
|
14
|
-
palette?: 'lab' | 'ocean' | 'ember' | 'mono';
|
|
15
|
-
metadata?: Record<string, string>;
|
|
16
|
-
env?: Record<string, string>;
|
|
17
|
-
sections?: {
|
|
18
|
-
title: string;
|
|
19
|
-
html: string;
|
|
20
|
-
}[];
|
|
21
|
-
customCss?: string;
|
|
22
|
-
dimensions?: string[];
|
|
23
|
-
dimensionOrder?: Record<string, string[]>;
|
|
24
|
-
project?: unknown;
|
|
25
|
-
links?: Record<string, unknown>;
|
|
26
|
-
bdd?: boolean;
|
|
27
|
-
announce?: boolean;
|
|
28
|
-
history?: {
|
|
29
|
-
enabled?: boolean;
|
|
30
|
-
file?: string;
|
|
31
|
-
keep?: number;
|
|
32
|
-
};
|
|
33
|
-
maskKeys?: string[];
|
|
34
|
-
maskValues?: string[];
|
|
35
|
-
maskFromEnv?: boolean;
|
|
36
|
-
embedFonts?: boolean;
|
|
37
|
-
editorLinks?: boolean;
|
|
38
|
-
expandFailedSteps?: boolean;
|
|
39
|
-
}
|
|
1
|
+
import { type WriteReportOptions } from '../write-report';
|
|
2
|
+
export type ReportingLabsCompleteOptions = WriteReportOptions;
|
|
40
3
|
export declare function reportingLabsComplete(options?: ReportingLabsCompleteOptions): Promise<string | undefined>;
|