@piwitests/reporter 0.69.0 → 0.70.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.
@@ -1,72 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/internal/capture/inspect-on-failure.ts
21
- var inspect_on_failure_exports = {};
22
- __export(inspect_on_failure_exports, {
23
- environmentalSkipReason: () => environmentalSkipReason,
24
- inspectionGateFromTestInfo: () => inspectionGateFromTestInfo,
25
- shouldInspectOnFailure: () => shouldInspectOnFailure
26
- });
27
- module.exports = __toCommonJS(inspect_on_failure_exports);
28
-
29
- // src/internal/support/ci.ts
30
- function detectCi(env) {
31
- return Boolean(
32
- env.JENKINS_URL || env.GITHUB_ACTIONS || env.GITLAB_CI || env.CIRCLECI || env.TRAVIS || env.TF_BUILD || env.BITBUCKET_BUILD_NUMBER || env.TEAMCITY_VERSION || env.CODEBUILD_BUILD_ID || env.bamboo_buildKey || env.CI && env.CI.toLowerCase() !== "false" && env.CI !== "0"
33
- );
34
- }
35
-
36
- // src/internal/capture/inspect-on-failure.ts
37
- function shouldInspectOnFailure(gate) {
38
- if (gate.enabled !== "true") return false;
39
- if (gate.ci) return false;
40
- if (gate.headless !== false) return false;
41
- if (gate.status !== "failed" && gate.status !== "timedOut") return false;
42
- if (gate.status === gate.expectedStatus) return false;
43
- return gate.retry >= gate.retries;
44
- }
45
- function environmentalSkipReason(gate) {
46
- if (gate.enabled !== "true") return null;
47
- if (gate.status !== "failed" && gate.status !== "timedOut") return null;
48
- if (gate.status === gate.expectedStatus) return null;
49
- if (gate.ci) return "running under CI \u2014 this is a headed, local-only feature";
50
- if (gate.headless !== false) {
51
- return "the browser is headless \u2014 re-run with --headed (or set use: { headless: false })";
52
- }
53
- return null;
54
- }
55
- function inspectionGateFromTestInfo(testInfo, enabled = process.env.PIWI_INSPECT_ON_FAIL) {
56
- const use = testInfo.project?.use ?? {};
57
- return {
58
- enabled,
59
- ci: detectCi(process.env),
60
- status: testInfo.status,
61
- expectedStatus: testInfo.expectedStatus,
62
- headless: use.headless,
63
- retry: testInfo.retry,
64
- retries: testInfo.project?.retries ?? 0
65
- };
66
- }
67
- // Annotate the CommonJS export names for ESM import in node:
68
- 0 && (module.exports = {
69
- environmentalSkipReason,
70
- inspectionGateFromTestInfo,
71
- shouldInspectOnFailure
72
- });
@@ -1,368 +0,0 @@
1
- /**
2
- * Shared types for locator healing — the in-runtime capture + storage of
3
- * alternative locators for every element interaction.
4
- *
5
- * The single source of truth: the dashboard app re-exports these via
6
- * `#shared/locator-healing.types`, and the reporter bundles them at build time.
7
- */
8
- /** A ranked alternative locator suggestion. */
9
- interface RankedLocator {
10
- locator: string;
11
- method: string;
12
- args: Record<string, unknown>;
13
- /** 0-100 stability score. data-testid=100, semantic CSS=35-40, hash-suffixed=10. */
14
- score: number;
15
- /**
16
- * True when a human confirmed this alternative in the reporter's
17
- * failure-time locator picker (`pickLocatorOnFailure`). A confirmed pick is
18
- * surfaced distinctly and preferred as the recommended fix.
19
- */
20
- pickedByUser?: boolean;
21
- /** When the pick was saved from the dashboard's snapshot picker, ISO 8601. */
22
- pickedAt?: string;
23
- }
24
- /**
25
- * Match counts for candidate selectors, probed against the live DOM at capture
26
- * time. A count > 1 marks the selector ambiguous (strict-mode violation).
27
- */
28
- interface SelectorCounts {
29
- testId?: number;
30
- id?: number;
31
- name?: number;
32
- classes?: Record<string, number>;
33
- /** How many elements share this element's role *and* exact accessible name (`getByRole(role, { name })` without `exact` also matches names that contain it). Absent when unknown (an older capture, or a probe run without the structural pass). */
34
- roleName?: number;
35
- /** Of the `roleName` matches, how many are visible (a laid-out box, or an `offsetParent`) — what `getByRole(role, { name }).visible()` would match. Absent when unknown. */
36
- visibleRoleName?: number;
37
- /** How many elements `getByText` would match on this element's text, counted no further than 2. Absent when unknown. */
38
- text?: number;
39
- /** How many elements share this element's `placeholder` — what `getByPlaceholder` would really match. Absent when unknown. */
40
- placeholder?: number;
41
- /** How many elements share this element's `alt` — what `getByAltText` would really match. Absent when unknown. */
42
- alt?: number;
43
- /** How many elements share this element's `title` — what `getByTitle` would really match. Absent when unknown. */
44
- title?: number;
45
- }
46
- /**
47
- * The element's position among same-role elements in the document at capture
48
- * time — a name-independent structural identity used to re-find a renamed
49
- * element on the failing page.
50
- */
51
- interface RolePosition {
52
- role: string;
53
- /** How many elements resolved to this role, document-wide. */
54
- count: number;
55
- /** The captured element's 0-based index among them, in document order. */
56
- index: number;
57
- /** For headings: how many same-role elements share this element's level. */
58
- levelCount?: number;
59
- }
60
- /**
61
- * An anchor-worthy ancestor of the captured element — one carrying a stable
62
- * hook (test id, id, explicit role, aria-label, or a landmark tag) that a
63
- * scoped alternative locator can chain from. Nearest ancestors first.
64
- */
65
- interface AncestorAnchor {
66
- tag: string;
67
- /** Hops from the element (1 = direct parent). */
68
- depth: number;
69
- testId: string | null;
70
- id: string | null;
71
- /** Explicit role attribute, if any. */
72
- role: string | null;
73
- ariaLabel: string | null;
74
- /** Same-role matches for the captured element within this ancestor. */
75
- scopedRoleCount?: number;
76
- /**
77
- * Matches for the captured element's text within this ancestor. A role-less
78
- * leaf (a price `<span>`, a status badge) has no role to scope, so this is
79
- * what tells a chain that resolves to one element from one that does not.
80
- */
81
- scopedTextCount?: number;
82
- /** Document-wide match count for this ancestor's own data-testid. */
83
- testIdCount?: number;
84
- /** Document-wide match count for this ancestor's own id. */
85
- idCount?: number;
86
- /** Document-wide count of elements resolving to this ancestor's landmark/explicit role. */
87
- roleCount?: number;
88
- /**
89
- * A stable non-testid `data-*` hook on this ancestor (`data-product="43"`,
90
- * `data-row-id="7"`). Many apps identify a repeated card or row this way and
91
- * nothing else, so without it the only locator left is one that matches every
92
- * card on the page.
93
- */
94
- dataAttr?: {
95
- name: string;
96
- value: string;
97
- };
98
- /** Document-wide match count for `dataAttr` as an attribute selector. */
99
- dataAttrCount?: number;
100
- /**
101
- * Text inside this ancestor that tells it apart from its same-role siblings —
102
- * the product name in a card, the customer name in a table row. A repeated
103
- * container carries no unique hook of its own, so this is what makes
104
- * `getByRole('listitem').filter({ hasText: 'Keyboard' })` land on one of them.
105
- */
106
- filterText?: string;
107
- /** How many elements of this ancestor's role contain `filterText`. */
108
- filterRoleCount?: number;
109
- }
110
- /** Raw element attributes captured after a successful action. */
111
- interface ElementAttributes {
112
- tagName: string;
113
- attributes: Record<string, string | null>;
114
- /** Visible text, truncated to 80 chars. */
115
- textContent: string | null;
116
- /** Browser-computed accessible name from ariaSnapshot(). */
117
- accessibleName: string | null;
118
- /** Center point of the element's bounding box — spatial discriminator. */
119
- center: {
120
- x: number;
121
- y: number;
122
- } | null;
123
- /** True when the element has an associated <label> — gates getByLabel. */
124
- hasLabel?: boolean;
125
- /** Text of the elements `aria-labelledby` points at, else of the first associated `<label>` — what names a form field. Absent when the probe did not read it. */
126
- labelText?: string | null;
127
- /** Live-page uniqueness probe results for candidate selectors. */
128
- selectorCounts?: SelectorCounts;
129
- /** Position among same-role elements — powers name-free and renamed-element healing. */
130
- rolePosition?: RolePosition | null;
131
- /** Anchor-worthy ancestors, nearest first — power ancestor-scoped alternatives. */
132
- ancestors?: AncestorAnchor[];
133
- }
134
- /** One captured element interaction (per locator call site). */
135
- interface LocatorSnapshot {
136
- /** The Playwright step location — unique, stable identity of this call site. */
137
- location: string | null;
138
- /** The locator the test code actually used. */
139
- used: {
140
- method: string;
141
- /** All args passed to the locator method. */
142
- args: unknown[];
143
- /** Original step title, for round-tripping. */
144
- raw: string;
145
- };
146
- /** Element attributes — null for gap entries (failed actions). */
147
- element: {
148
- tagName: string;
149
- attributes: Record<string, string | null>;
150
- textContent: string | null;
151
- accessibleName: string | null;
152
- center: {
153
- x: number;
154
- y: number;
155
- } | null;
156
- /** Position among same-role elements at capture time (newer reporters only). */
157
- rolePosition?: RolePosition | null;
158
- /** Anchor-worthy ancestors, nearest first (newer reporters only). */
159
- ancestors?: AncestorAnchor[];
160
- } | null;
161
- /** Computed alternative locators, ranked by stability score (max 10). */
162
- alternatives: RankedLocator[];
163
- }
164
-
165
- /**
166
- * Locator generation — pure functions for building ranked alternative locators
167
- * from element attributes. The single source of truth shared by the server, the
168
- * dashboard SPA, the interactive DOM snapshot picker (which runs in the
169
- * browser), and the Playwright reporter (which bundles this at build time).
170
- */
171
-
172
- /** Implicit ARIA role for an HTML tag (when no explicit `role` is set). */
173
- declare const TAG_TO_ROLE: Record<string, string>;
174
- /** Implicit ARIA role for an `<input>` keyed by its `type` attribute. */
175
- declare const INPUT_TYPE_TO_ROLE: Record<string, string>;
176
- /** Element attributes captured by the probe. */
177
- declare const CAPTURED_ATTRIBUTES: string[];
178
- declare function resolveAriaRole(attrs: ElementAttributes): string | null;
179
- declare function headingLevel(attrs: ElementAttributes, role: string | null): number | null;
180
- declare function classifyCssStability(className: string): number;
181
- declare function isAutoGenerated(value: string): boolean;
182
- interface GenerateOptions {
183
- /**
184
- * The element's role from an accessibility model, for a caller that has one:
185
- * every role candidate uses it instead of `resolveAriaRole(attrs)`, and null
186
- * means the element has none. `rolePosition` and the anchors' scoped role
187
- * counts must then describe this role.
188
- */
189
- role?: string | null;
190
- /**
191
- * The attribute `getByTestId` reads in the project (Playwright's
192
- * `testIdAttribute`); `data-testid` when null or absent. The element's
193
- * `getByTestId` candidate comes from it, and so do the anchors', whose
194
- * `testId` and `testIdCount` the probe reads from the same attribute
195
- * (`ProbeArg.testIdAttribute`). No `locator()` candidate selects on it, since
196
- * `getByTestId` does; any other attribute, `data-testid` included, is an
197
- * ordinary one.
198
- */
199
- testIdAttribute?: string | null;
200
- }
201
- declare function generateAlternatives(attrs: ElementAttributes, options?: GenerateOptions): RankedLocator[];
202
- /**
203
- * Approximate the accessible name from probed attributes, in the order the
204
- * accessible-name computation applies: `aria-labelledby` (resolved by the probe
205
- * into `labelText`), `aria-label`, then — for a form field — its `<label>`, or —
206
- * for anything else — its text, then `title` and `placeholder`.
207
- *
208
- * A form field is never named by its own text: a `<select>`'s text is its
209
- * options and a `<textarea>`'s is its value.
210
- */
211
- declare function approximateAccessibleName(attrs: ElementAttributes): string | null;
212
-
213
- /**
214
- * Reporter-local locator healing.
215
- *
216
- * The pure surface — alternative generation, stability scoring, ARIA-role
217
- * resolution, the role maps and the captured-attribute whitelist — lives in
218
- * `@piwitests/core` (bundled into `dist/` at build time, so nothing
219
- * monorepo-relative leaks into the published package). It is re-exported from
220
- * here so existing importers (`capture-fixtures.ts`, `pick-on-failure.ts`, the
221
- * unit tests) keep importing it from this module.
222
- *
223
- * This module keeps only the reporter-only runtime: call-site capture (needs the
224
- * Node stack), snapshot dedupe, the fixture-proxy method surface, and the
225
- * failure-time locator suggestion + rendering.
226
- */
227
-
228
- /**
229
- * Drop repeated captures of the same call site before attaching: a loop (or a
230
- * page-object method called repeatedly) produces one snapshot per action, but
231
- * the server keeps only the latest per location anyway. Keeps the last
232
- * element-bearing snapshot per location — falling back to the last placeholder
233
- * when no capture resolved, so the location still counts as "seen this run"
234
- * for the server's stale-location purge. Entries with no location pass through.
235
- */
236
- declare function dedupeSnapshotsByLocation(snaps: LocatorSnapshot[]): LocatorSnapshot[];
237
- /**
238
- * Page-level locator-building methods wrapped by the capture proxy. Imported by
239
- * both the capture fixtures (`capture-fixtures.ts`) and the dogfooding
240
- * `application/tests/fixtures.ts` so the two stay in sync (a prior drift missed
241
- * `scrollIntoViewIfNeeded`).
242
- */
243
- declare const LOCATOR_METHODS: string[];
244
- /**
245
- * Methods that can be chained onto a wrapped locator. Locator-creating chains
246
- * (those also in `LOCATOR_METHODS`) update the origin; positional/filter chains
247
- * (`first`, `nth`, `filter`, …) narrow without changing locator identity.
248
- */
249
- declare const CHAIN_METHODS: string[];
250
- /** Locator action methods that trigger element capture. */
251
- declare const ACTION_METHODS: string[];
252
- /** Chain methods that create a new locator scope (origin tracks the chain call). */
253
- declare const LOCATOR_CREATING_CHAINS: ReadonlySet<string>;
254
- /**
255
- * The private `Locator` method every web-first assertion funnels through:
256
- * `expect(locator).toBeVisible()` and friends all resolve to
257
- * `locator._expect(expression, { isNot, timeout, … })` on the locator instance
258
- * the test passed to `expect()` — which, under the capture fixtures, is the
259
- * wrapped proxy. Intercepting it is what lets assertion-only locators build
260
- * healing history. The funnel is unchanged across Playwright 1.40 → current;
261
- * if a future version renames it the interception silently never fires and
262
- * assertions behave exactly as without the proxy.
263
- */
264
- declare const EXPECT_METHOD = "_expect";
265
- /**
266
- * Web-first assertion expressions whose PASS proves the target element
267
- * resolved — the assertion-side equivalent of a successful action, and the
268
- * capture hook for locators only ever used in `expect()`.
269
- *
270
- * Deliberately excluded:
271
- * - absence assertions (`to.be.hidden`, `to.be.detached`): passing means the
272
- * element may not exist at all — nothing to probe;
273
- * - multi-element assertions (`to.have.count`, the `*.array` text/class
274
- * forms, `to.have.values`): the single-element probe would only hit a
275
- * strict-mode violation;
276
- * - page-level assertions (`to.have.title`, `to.have.url`): they run on an
277
- * internal `:root` locator that carries no healing value.
278
- * Negated calls (`.not.…`, `isNot: true`) are skipped at the call site — a
279
- * passing negative assertion proves nothing about the element resolving.
280
- */
281
- declare const EXPECT_CAPTURE_EXPRESSIONS: ReadonlySet<string>;
282
- /**
283
- * Extract the accessible name from a YAML-like ariaSnapshot() output.
284
- *
285
- * Format example:
286
- * - button "Submit order"
287
- * - heading "Welcome, Alice"
288
- * - textbox "Email" [ref=e12]
289
- * - generic
290
- *
291
- * Returns the first quoted string after the role, or null if none found.
292
- */
293
- declare function extractAccessibleName(ariaSnapshot: string | null): string | null;
294
- /** Tags whose accessible name comes from an associated `<label>`. */
295
- declare const FORM_FIELD_TAGS: ReadonlySet<string>;
296
- /** The subset of a probe result the accessible-name shortcut reads. */
297
- interface NameSource {
298
- tagName: string;
299
- attributes: Record<string, string | null>;
300
- textContent: string | null;
301
- labelText?: string | null;
302
- }
303
- /**
304
- * The accessible name when the probed attributes already settle it, or null
305
- * when only the browser can. Capture consults this before spending an
306
- * `ariaSnapshot()` round trip on an element: in each case below the name is
307
- * what the accessible-name computation would return anyway, so the round trip
308
- * would buy nothing.
309
- *
310
- * Deliberately narrow — anything outside these cases (an `aria-labelledby`
311
- * reference, an image named by `alt`, an element with no text) still goes to
312
- * the browser, because a wrong name here becomes a wrong `getByRole` locator.
313
- */
314
- declare function exactAccessibleName(attrs: NameSource, role: string | null): string | null;
315
- /** A failed locator action, used to suggest a fresh locator from the live page. */
316
- interface FailedLocatorInfo {
317
- method: string;
318
- args: unknown[];
319
- /** Test call site (`file:line:col`) of the failed action, when captured. */
320
- location?: string | null;
321
- }
322
- interface LocatorSuggestion {
323
- /** The failed locator rendered as source, e.g. `getByText('Go to page')`. */
324
- failing: string;
325
- /** Fresh locator suggestions for the element's current identity, best first. */
326
- suggestions: string[];
327
- }
328
- /** Render the failed locator back to source for annotation/picker messages. */
329
- declare function renderFailing(failed: FailedLocatorInfo): string;
330
- /**
331
- * Best-effort runtime suggestion for a locator that matched nothing: find the
332
- * element on the *current* page that the failed locator most likely targeted
333
- * (by accessible name similarity, restricted to the failed role when given) and
334
- * return fresh locators for it.
335
- *
336
- * Unlike the server lookup this has no pre-captured fingerprint — only the
337
- * failed locator + the live page — so it's a hint, not a guarantee. Returns null
338
- * for non-name-based locators (testid/CSS), when the targeted name is still
339
- * present (so the failure wasn't a rename), or when no candidate is confident.
340
- */
341
- declare function suggestLocatorsFromAria(failed: FailedLocatorInfo, ariaSnapshot: string | null): LocatorSuggestion | null;
342
- /**
343
- * The local path a stack frame's file names: a `file://` URL (an ES-module suite's frames) through `fileURLToPath`,
344
- * any other path as it is. `windows` reads the URL as Windows does. Null for a URL that names no local file.
345
- */
346
- declare function framePath(file: string, windows?: boolean): string | null;
347
- /**
348
- * A stack frame's file relative to `cwd`, with forward slashes: the form Playwright writes a location in its error
349
- * messages. A file on another drive stays absolute. Null for a URL that names no local file.
350
- */
351
- declare function callSitePath(file: string, cwd?: string, windows?: boolean): string | null;
352
- /**
353
- * Capture the calling test's source location (`file:line:col`) from the current
354
- * stack, for stamping onto a locator snapshot. The path is made cwd-relative so
355
- * it matches the location format Playwright embeds in error messages — which is
356
- * what the server's exact-match healing lookup (`extractErrorLocation`) parses.
357
- *
358
- * Stamping at action *call* time (rather than correlating with `pw:api` step
359
- * indices at step *end* time) avoids three classes of misalignment: `pw:api`
360
- * steps with no wrapped locator (e.g. `page.keyboard.press`), cross-worker step
361
- * interleaving, and concurrent actions reordering by end time.
362
- *
363
- * Returns null when no user frame can be identified — the snapshot keeps
364
- * `location: null` and the server falls back to fingerprint / ARIA lookup.
365
- */
366
- declare function captureCallerLocation(stack?: string): string | null;
367
-
368
- export { ACTION_METHODS, type AncestorAnchor, CAPTURED_ATTRIBUTES, CHAIN_METHODS, EXPECT_CAPTURE_EXPRESSIONS, EXPECT_METHOD, type ElementAttributes, FORM_FIELD_TAGS, type FailedLocatorInfo, INPUT_TYPE_TO_ROLE, LOCATOR_CREATING_CHAINS, LOCATOR_METHODS, type LocatorSnapshot, type LocatorSuggestion, type NameSource, type RankedLocator, type RolePosition, type SelectorCounts, TAG_TO_ROLE, approximateAccessibleName, callSitePath, captureCallerLocation, classifyCssStability, dedupeSnapshotsByLocation, exactAccessibleName, extractAccessibleName, framePath, generateAlternatives, headingLevel, isAutoGenerated, renderFailing, resolveAriaRole, suggestLocatorsFromAria };