@monkeytestai/monkeytester 0.7.0-beta.1 → 0.7.0-beta.2
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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/checks/axe.d.ts +24 -0
- package/dist/checks/axe.d.ts.map +1 -0
- package/dist/checks/axe.js +57 -0
- package/dist/checks/axe.js.map +1 -0
- package/dist/checks/console.d.ts +17 -0
- package/dist/checks/console.d.ts.map +1 -0
- package/dist/checks/console.js +32 -0
- package/dist/checks/console.js.map +1 -0
- package/dist/checks/execute.d.ts +34 -0
- package/dist/checks/execute.d.ts.map +1 -0
- package/dist/checks/execute.js +424 -0
- package/dist/checks/execute.js.map +1 -0
- package/dist/checks/http.d.ts +27 -0
- package/dist/checks/http.d.ts.map +1 -0
- package/dist/checks/http.js +90 -0
- package/dist/checks/http.js.map +1 -0
- package/dist/checks/meta.d.ts +23 -0
- package/dist/checks/meta.d.ts.map +1 -0
- package/dist/checks/meta.js +39 -0
- package/dist/checks/meta.js.map +1 -0
- package/dist/checks/mobile.d.ts +30 -0
- package/dist/checks/mobile.d.ts.map +1 -0
- package/dist/checks/mobile.js +61 -0
- package/dist/checks/mobile.js.map +1 -0
- package/dist/checks/noise.d.ts +10 -0
- package/dist/checks/noise.d.ts.map +1 -0
- package/dist/checks/noise.js +53 -0
- package/dist/checks/noise.js.map +1 -0
- package/dist/checks/plan.d.ts +35 -0
- package/dist/checks/plan.d.ts.map +1 -0
- package/dist/checks/plan.js +108 -0
- package/dist/checks/plan.js.map +1 -0
- package/dist/cli.js +56 -19
- package/dist/cli.js.map +1 -1
- package/dist/depth.d.ts +44 -1
- package/dist/depth.d.ts.map +1 -1
- package/dist/depth.js +38 -3
- package/dist/depth.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/llm/prices.d.ts +17 -0
- package/dist/llm/prices.d.ts.map +1 -0
- package/dist/llm/prices.js +41 -0
- package/dist/llm/prices.js.map +1 -0
- package/dist/monkey.d.ts +6 -0
- package/dist/monkey.d.ts.map +1 -1
- package/dist/monkey.js +22 -4
- package/dist/monkey.js.map +1 -1
- package/dist/planner/dedupe.d.ts.map +1 -1
- package/dist/planner/dedupe.js +18 -2
- package/dist/planner/dedupe.js.map +1 -1
- package/dist/planner/focus.d.ts.map +1 -1
- package/dist/planner/focus.js +16 -5
- package/dist/planner/focus.js.map +1 -1
- package/dist/planner/forms.d.ts.map +1 -1
- package/dist/planner/forms.js +2 -1
- package/dist/planner/forms.js.map +1 -1
- package/dist/planner/index.d.ts +13 -2
- package/dist/planner/index.d.ts.map +1 -1
- package/dist/planner/index.js +68 -7
- package/dist/planner/index.js.map +1 -1
- package/dist/planner/inventory.d.ts +6 -0
- package/dist/planner/inventory.d.ts.map +1 -1
- package/dist/planner/inventory.js +13 -0
- package/dist/planner/inventory.js.map +1 -1
- package/dist/runner/index.d.ts +11 -0
- package/dist/runner/index.d.ts.map +1 -1
- package/dist/runner/index.js +55 -0
- package/dist/runner/index.js.map +1 -1
- package/dist/runner/replay.d.ts.map +1 -1
- package/dist/runner/replay.js +52 -14
- package/dist/runner/replay.js.map +1 -1
- package/dist/trace/serialize.d.ts.map +1 -1
- package/dist/trace/serialize.js +1 -0
- package/dist/trace/serialize.js.map +1 -1
- package/dist/triager/index.d.ts.map +1 -1
- package/dist/triager/index.js +8 -3
- package/dist/triager/index.js.map +1 -1
- package/dist/types.d.ts +35 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.0-beta.2] — 2026-11-01
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Deterministic page checks in `src/checks/`, with no model call. One engine flow per check, reserved id `check-*`, kind `accessibility` or `visual`, and one step per crawled page. The five checks are console errors, same-site failed requests and broken links (about 20 link probes), axe-core WCAG A/AA, mobile overflow and tap targets at 375px, and title / description / lang / viewport / h1. They sit outside the LLM flow budget and are not dropped as phantom flows. Serious or critical axe violations are bugs. Missing `autocomplete` on a login field is minor. Title and viewport gaps are minor. Description, lang, and h1 count are info. Console noise from extensions, third parties, and `isOwnAutomationBug` is ignored. Steps record `tool: 'check'`. Replay re-runs a `check` step, or skips it when the check id is missing.
|
|
15
|
+
- `BASIC_PRESET` from `depth.ts`: 6 pages, 5 LLM flows, engine caps of 5 checks and 6 auth-negative flows, 10s step timeout, 25s flow timeout, 12s page timeout, and a 120s total budget. Past that budget, remaining page checks are skipped instead of failing the run as a timeout. `--depth basic` uses these numbers.
|
|
16
|
+
- The planner asks for a success check and an error or edge check on each form journey. When the plan is thinner than 5 flows and the cap allows it, it asks once more, still only against crawled pages and controls. Quick pass may use a non-submit auth control such as Sign up or Forgot password. Engine flows win when an LLM flow repeats them.
|
|
17
|
+
- `--planner-model <id>` and `MonkeyConfig.plannerModel`. Per-page summaries stay on the cheap model (`gpt-4o-mini` for OpenAI). The runner model is unchanged.
|
|
18
|
+
- `scripts/bakeoff.ts` compares planner models. Each run writes JSON (case count, real bugs, invented flows, false-positive candidates, planner latency, wall time, tokens, and USD) and the process prints a table. Prices live in `MODEL_PRICES`.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Quick pass plans 5 LLM flows instead of 4. `severityIfFails` is copied onto the flow result so triage uses it. A step may set `severity` when a check finding is minor.
|
|
23
|
+
|
|
10
24
|
## [0.7.0-beta.1] — 2026-10-31
|
|
11
25
|
|
|
12
26
|
### Added
|
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ export GEMINI_API_KEY="paste-your-key"
|
|
|
86
86
|
npx monkeytest run https://example.com --depth basic
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
`--depth basic` is the free **Quick pass**:
|
|
89
|
+
`--depth basic` is the free **Quick pass**: 6 pages, 5 LLM flows, and deterministic page checks outside that budget, with a 120 second cap. `standard` and `deep` are the broader presets. `--max` and `--flows` still override the page and flow caps. Import `BASIC_PRESET` from the package for the same numbers.
|
|
90
90
|
|
|
91
91
|
A finished run includes:
|
|
92
92
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* axe-core WCAG A/AA.
|
|
3
|
+
*
|
|
4
|
+
* Serious and critical violations fail the step. Moderate and minor hits
|
|
5
|
+
* are info. Missing `autocomplete` on a login field is minor even when axe
|
|
6
|
+
* ranks that rule as serious.
|
|
7
|
+
*/
|
|
8
|
+
import type { Page } from 'playwright';
|
|
9
|
+
import type { Result } from 'axe-core';
|
|
10
|
+
export interface AxeJudgement {
|
|
11
|
+
serious: {
|
|
12
|
+
id: string;
|
|
13
|
+
impact: string;
|
|
14
|
+
help: string;
|
|
15
|
+
}[];
|
|
16
|
+
/** Missing autocomplete on login fields. Minor, not serious. */
|
|
17
|
+
autocomplete: string[];
|
|
18
|
+
info: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare function splitAxeViolations(violations: Result[]): AxeJudgement;
|
|
21
|
+
export declare function runAxe(page: Page): Promise<AxeJudgement>;
|
|
22
|
+
/** Login fields with no autocomplete attribute. Axe does not always flag the absence. */
|
|
23
|
+
export declare function readMissingLoginAutocomplete(): string[];
|
|
24
|
+
//# sourceMappingURL=axe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axe.d.ts","sourceRoot":"","sources":["../../src/checks/axe.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIvC,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACxD,gEAAgE;IAChE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAID,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,YAAY,CAyBrE;AAED,wBAAsB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAG9D;AAED,yFAAyF;AACzF,wBAAgB,4BAA4B,IAAI,MAAM,EAAE,CAavD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* axe-core WCAG A/AA.
|
|
3
|
+
*
|
|
4
|
+
* Serious and critical violations fail the step. Moderate and minor hits
|
|
5
|
+
* are info. Missing `autocomplete` on a login field is minor even when axe
|
|
6
|
+
* ranks that rule as serious.
|
|
7
|
+
*/
|
|
8
|
+
import AxeBuilder from '@axe-core/playwright';
|
|
9
|
+
const TAGS = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'];
|
|
10
|
+
const LOGIN_FIELD = /type=["']?(?:password|email)|name=["']?(?:email|user|login|password)|autocomplete=["']?(?:username|email|current-password|new-password)/i;
|
|
11
|
+
export function splitAxeViolations(violations) {
|
|
12
|
+
const serious = [];
|
|
13
|
+
const autocomplete = [];
|
|
14
|
+
const info = [];
|
|
15
|
+
for (const violation of violations) {
|
|
16
|
+
const impact = violation.impact || 'minor';
|
|
17
|
+
const loginAutocomplete = violation.id === 'autocomplete-valid' && violation.nodes.some(node => LOGIN_FIELD.test(`${node.html} ${(node.target || []).join(' ')}`));
|
|
18
|
+
if (loginAutocomplete) {
|
|
19
|
+
autocomplete.push(violation.help || 'Login fields are missing autocomplete.');
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (impact === 'serious' || impact === 'critical') {
|
|
23
|
+
serious.push({
|
|
24
|
+
id: violation.id,
|
|
25
|
+
impact,
|
|
26
|
+
help: violation.help || violation.description || violation.id,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
info.push(`${violation.id}: ${violation.help || violation.description || impact}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { serious, autocomplete, info };
|
|
34
|
+
}
|
|
35
|
+
export async function runAxe(page) {
|
|
36
|
+
const results = await new AxeBuilder({ page }).withTags(TAGS).analyze();
|
|
37
|
+
return splitAxeViolations(results.violations);
|
|
38
|
+
}
|
|
39
|
+
/** Login fields with no autocomplete attribute. Axe does not always flag the absence. */
|
|
40
|
+
export function readMissingLoginAutocomplete() {
|
|
41
|
+
const fields = [];
|
|
42
|
+
for (const node of Array.from(document.querySelectorAll('input'))) {
|
|
43
|
+
const el = node;
|
|
44
|
+
if (el.disabled || el.type === 'hidden' || el.type === 'submit' || el.type === 'button')
|
|
45
|
+
continue;
|
|
46
|
+
const type = (el.type || '').toLowerCase();
|
|
47
|
+
const name = `${el.getAttribute('name') || ''} ${el.id || ''}`.toLowerCase();
|
|
48
|
+
const login = type === 'password' || type === 'email' || /user|login|email|password/.test(name);
|
|
49
|
+
if (!login)
|
|
50
|
+
continue;
|
|
51
|
+
if ((el.getAttribute('autocomplete') || '').trim())
|
|
52
|
+
continue;
|
|
53
|
+
fields.push(el.getAttribute('name') || el.id || type);
|
|
54
|
+
}
|
|
55
|
+
return fields;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=axe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axe.js","sourceRoot":"","sources":["../../src/checks/axe.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAI9C,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAS1D,MAAM,WAAW,GAAG,0IAA0I,CAA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+1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First-party console errors and uncaught exceptions on load.
|
|
3
|
+
*/
|
|
4
|
+
import type { ConsoleErrorEvidence } from '../types.js';
|
|
5
|
+
export interface ConsoleHit {
|
|
6
|
+
message: string;
|
|
7
|
+
sourceUrl?: string;
|
|
8
|
+
/** `pageerror` is an uncaught exception. `console` is console.error. */
|
|
9
|
+
kind: 'pageerror' | 'console';
|
|
10
|
+
}
|
|
11
|
+
export interface ConsoleJudgement {
|
|
12
|
+
bugs: ConsoleHit[];
|
|
13
|
+
ignored: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function judgeConsole(hits: ConsoleHit[], pageUrl: string): ConsoleJudgement;
|
|
16
|
+
export declare function consoleEvidence(bugs: ConsoleHit[]): ConsoleErrorEvidence[];
|
|
17
|
+
//# sourceMappingURL=console.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/checks/console.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGxD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wEAAwE;IACxE,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAiBlF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,oBAAoB,EAAE,CAM1E"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First-party console errors and uncaught exceptions on load.
|
|
3
|
+
*/
|
|
4
|
+
import { isIgnoredConsoleMessage } from './noise.js';
|
|
5
|
+
export function judgeConsole(hits, pageUrl) {
|
|
6
|
+
const bugs = [];
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
let ignored = 0;
|
|
9
|
+
for (const hit of hits) {
|
|
10
|
+
const message = hit.message.replace(/\s+/g, ' ').trim();
|
|
11
|
+
if (!message)
|
|
12
|
+
continue;
|
|
13
|
+
if (isIgnoredConsoleMessage(message, hit.sourceUrl, pageUrl)) {
|
|
14
|
+
ignored += 1;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const key = message.slice(0, 180);
|
|
18
|
+
if (seen.has(key))
|
|
19
|
+
continue;
|
|
20
|
+
seen.add(key);
|
|
21
|
+
bugs.push({ ...hit, message });
|
|
22
|
+
}
|
|
23
|
+
return { bugs, ignored };
|
|
24
|
+
}
|
|
25
|
+
export function consoleEvidence(bugs) {
|
|
26
|
+
return bugs.slice(0, 8).map(hit => ({
|
|
27
|
+
message: hit.message.slice(0, 300),
|
|
28
|
+
level: 'error',
|
|
29
|
+
...(hit.sourceUrl ? { url: hit.sourceUrl } : {}),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/checks/console.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAcrD,MAAM,UAAU,YAAY,CAAC,IAAkB,EAAE,OAAe;IAC9D,MAAM,IAAI,GAAiB,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACxD,IAAI,CAAC,OAAO;YAAE,SAAS;QACvB,IAAI,uBAAuB,CAAC,OAAO,EAAE,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;YAC7D,OAAO,IAAI,CAAC,CAAC;YACb,SAAS;QACX,CAAC;QACD,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAClC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAkB;IAChD,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;QAClC,KAAK,EAAE,OAAgB;QACvB,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjD,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run the reserved page checks in one browser pass.
|
|
3
|
+
*
|
|
4
|
+
* Each crawled URL is opened once. Every check type records its own step
|
|
5
|
+
* with `tool: 'check'`. A failure on one page does not skip the other pages.
|
|
6
|
+
* When `deadlineAt` has passed, the remaining pages are skipped. That is
|
|
7
|
+
* not a timeout error.
|
|
8
|
+
*/
|
|
9
|
+
import type { Browser, Page } from 'playwright';
|
|
10
|
+
import type { ConsoleErrorEvidence, FlowResult, NetworkFailureEvidence, PageCheck, StepResult, TestFlow } from '../types.js';
|
|
11
|
+
export interface CheckStepOutcome {
|
|
12
|
+
status: 'passed' | 'failed' | 'skipped';
|
|
13
|
+
observation: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
severity?: 'critical' | 'major' | 'minor';
|
|
16
|
+
consoleErrors?: ConsoleErrorEvidence[];
|
|
17
|
+
networkFailures?: NetworkFailureEvidence[];
|
|
18
|
+
}
|
|
19
|
+
export interface LinkBudget {
|
|
20
|
+
remaining: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ExecuteChecksOptions {
|
|
23
|
+
screenshotsDir: string;
|
|
24
|
+
stepTimeoutMs: number;
|
|
25
|
+
/** Epoch ms. Pages not started by then are skipped. */
|
|
26
|
+
deadlineAt?: number;
|
|
27
|
+
onFlowStart?: (flow: TestFlow) => void;
|
|
28
|
+
onStep?: (flow: TestFlow, result: StepResult) => void;
|
|
29
|
+
onFlowComplete?: (result: FlowResult) => void;
|
|
30
|
+
}
|
|
31
|
+
export declare function replayPageCheck(page: Page, kind: PageCheck, url: string, timeoutMs: number): Promise<CheckStepOutcome>;
|
|
32
|
+
export declare function executePageChecks(browser: Browser, flows: TestFlow[], opts: ExecuteChecksOptions): Promise<FlowResult[]>;
|
|
33
|
+
export declare function shotPath(dir: string, flowId: string, index: number, status: string): string;
|
|
34
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/checks/execute.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAY,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EACV,oBAAoB,EACpB,UAAU,EACV,sBAAsB,EACtB,SAAS,EACT,UAAU,EACV,QAAQ,EAET,MAAM,aAAa,CAAC;AAkBrB,MAAM,W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in one browser pass.
|
|
3
|
+
*
|
|
4
|
+
* Each crawled URL is opened once. Every check type records its own step
|
|
5
|
+
* with `tool: 'check'`. A failure on one page does not skip the other pages.
|
|
6
|
+
* When `deadlineAt` has passed, the remaining pages are skipped. That is
|
|
7
|
+
* not a timeout error.
|
|
8
|
+
*/
|
|
9
|
+
import { mkdirSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { resolveFlowStatus } from '../runner/flowStatus.js';
|
|
12
|
+
import { serializeTrace, serializeTraceStep } from '../trace/serialize.js';
|
|
13
|
+
import { isPageCheck, pageCheckSpec } from './plan.js';
|
|
14
|
+
import { consoleEvidence, judgeConsole } from './console.js';
|
|
15
|
+
import { BROKEN_LINK_CAP, isBrokenStatus, isReportableRequest, linkEvidence, requestEvidence, sameSiteLinks, } from './http.js';
|
|
16
|
+
import { readMissingLoginAutocomplete, runAxe } from './axe.js';
|
|
17
|
+
import { judgeMeta, readMetaInPage } from './meta.js';
|
|
18
|
+
import { judgeMobile, MOBILE_VIEWPORT, readMobileInPage } from './mobile.js';
|
|
19
|
+
const buckets = new WeakMap();
|
|
20
|
+
function bucket(page) {
|
|
21
|
+
let found = buckets.get(page);
|
|
22
|
+
if (!found) {
|
|
23
|
+
found = { hits: [], requests: [] };
|
|
24
|
+
buckets.set(page, found);
|
|
25
|
+
const target = found;
|
|
26
|
+
page.on('console', message => {
|
|
27
|
+
if (message.type() !== 'error')
|
|
28
|
+
return;
|
|
29
|
+
target.hits.push({
|
|
30
|
+
kind: 'console',
|
|
31
|
+
message: message.text(),
|
|
32
|
+
sourceUrl: message.location()?.url,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
page.on('pageerror', error => {
|
|
36
|
+
target.hits.push({ kind: 'pageerror', message: error.message });
|
|
37
|
+
});
|
|
38
|
+
page.on('response', response => {
|
|
39
|
+
const status = response.status();
|
|
40
|
+
if (status < 400)
|
|
41
|
+
return;
|
|
42
|
+
const request = response.request();
|
|
43
|
+
target.requests.push({
|
|
44
|
+
url: response.url(),
|
|
45
|
+
method: request.method(),
|
|
46
|
+
status,
|
|
47
|
+
resourceType: request.resourceType(),
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
page.on('requestfailed', request => {
|
|
51
|
+
target.requests.push({
|
|
52
|
+
url: request.url(),
|
|
53
|
+
method: request.method(),
|
|
54
|
+
failureText: request.failure()?.errorText,
|
|
55
|
+
resourceType: request.resourceType(),
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return found;
|
|
60
|
+
}
|
|
61
|
+
function resetCollected(collected) {
|
|
62
|
+
collected.hits.length = 0;
|
|
63
|
+
collected.requests.length = 0;
|
|
64
|
+
}
|
|
65
|
+
function clip(value, max = 500) {
|
|
66
|
+
const text = value.replace(/\s+/g, ' ').trim();
|
|
67
|
+
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
68
|
+
}
|
|
69
|
+
function withInfo(main, info) {
|
|
70
|
+
const extra = info.filter(Boolean);
|
|
71
|
+
const text = extra.length ? `${main} Info: ${extra.join(' ')}` : main;
|
|
72
|
+
return clip(text);
|
|
73
|
+
}
|
|
74
|
+
function skipped(observation) {
|
|
75
|
+
return { status: 'skipped', observation };
|
|
76
|
+
}
|
|
77
|
+
function passed(observation, info = []) {
|
|
78
|
+
return { status: 'passed', observation: withInfo(observation, info) };
|
|
79
|
+
}
|
|
80
|
+
function failed(observation, error, extra = {}, info = []) {
|
|
81
|
+
return {
|
|
82
|
+
status: 'failed',
|
|
83
|
+
observation: withInfo(observation, info),
|
|
84
|
+
error: clip(error, 240),
|
|
85
|
+
...extra,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export async function replayPageCheck(page, kind, url, timeoutMs) {
|
|
89
|
+
const collected = bucket(page);
|
|
90
|
+
resetCollected(collected);
|
|
91
|
+
if (kind === 'mobile') {
|
|
92
|
+
await page.setViewportSize(MOBILE_VIEWPORT).catch(() => { });
|
|
93
|
+
}
|
|
94
|
+
let response = null;
|
|
95
|
+
try {
|
|
96
|
+
response = await page.goto(url, { waitUntil: 'domcontentloaded', timeout: timeoutMs });
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
return loadFailure(kind, url, err);
|
|
100
|
+
}
|
|
101
|
+
await page.waitForTimeout(200).catch(() => { });
|
|
102
|
+
return assessLoadedPage(page, kind, url, collected, { remaining: BROKEN_LINK_CAP }, response?.status());
|
|
103
|
+
}
|
|
104
|
+
export async function executePageChecks(browser, flows, opts) {
|
|
105
|
+
if (flows.length === 0)
|
|
106
|
+
return [];
|
|
107
|
+
mkdirSync(opts.screenshotsDir, { recursive: true });
|
|
108
|
+
for (const flow of flows)
|
|
109
|
+
opts.onFlowStart?.(flow);
|
|
110
|
+
const desktop = await browser.newContext({ viewport: { width: 1280, height: 720 } });
|
|
111
|
+
const mobile = await browser.newContext({ viewport: MOBILE_VIEWPORT });
|
|
112
|
+
const desktopPage = await desktop.newPage();
|
|
113
|
+
const mobilePage = await mobile.newPage();
|
|
114
|
+
const linkBudget = { remaining: BROKEN_LINK_CAP };
|
|
115
|
+
const steps = new Map();
|
|
116
|
+
const traces = new Map();
|
|
117
|
+
for (const flow of flows) {
|
|
118
|
+
steps.set(flow.id, []);
|
|
119
|
+
traces.set(flow.id, []);
|
|
120
|
+
}
|
|
121
|
+
const urls = flowUrls(flows[0]);
|
|
122
|
+
let budgetUsed = false;
|
|
123
|
+
try {
|
|
124
|
+
for (const url of urls) {
|
|
125
|
+
if (budgetUsed || (opts.deadlineAt !== undefined && Date.now() > opts.deadlineAt)) {
|
|
126
|
+
budgetUsed = true;
|
|
127
|
+
for (const flow of flows) {
|
|
128
|
+
await record(flow, url, skipped('Skipped: the run finished its time budget before this check.'), opts, steps, traces);
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const collected = bucket(desktopPage);
|
|
133
|
+
resetCollected(collected);
|
|
134
|
+
let response = null;
|
|
135
|
+
let loadError;
|
|
136
|
+
try {
|
|
137
|
+
response = await desktopPage.goto(url, { waitUntil: 'domcontentloaded', timeout: opts.stepTimeoutMs });
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
loadError = err;
|
|
141
|
+
}
|
|
142
|
+
if (!loadError)
|
|
143
|
+
await desktopPage.waitForTimeout(200).catch(() => { });
|
|
144
|
+
const status = response?.status();
|
|
145
|
+
for (const flow of flows) {
|
|
146
|
+
const kind = kindOf(flow);
|
|
147
|
+
if (!kind || kind === 'mobile')
|
|
148
|
+
continue;
|
|
149
|
+
const outcome = loadError
|
|
150
|
+
? loadFailure(kind, url, loadError)
|
|
151
|
+
: status && status >= 400 && kind !== 'http'
|
|
152
|
+
? skipped(`Page responded HTTP ${status}, so this check was not run.`)
|
|
153
|
+
: await assessLoadedPage(desktopPage, kind, url, collected, linkBudget, status);
|
|
154
|
+
await record(flow, url, outcome, opts, steps, traces, desktopPage);
|
|
155
|
+
}
|
|
156
|
+
const mobileFlow = flows.find(flow => kindOf(flow) === 'mobile');
|
|
157
|
+
if (mobileFlow) {
|
|
158
|
+
if (loadError || (status && status >= 400)) {
|
|
159
|
+
await record(mobileFlow, url, skipped('Page did not load, so the mobile check was not run.'), opts, steps, traces);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
let mobileError;
|
|
163
|
+
try {
|
|
164
|
+
await mobilePage.goto(url, { waitUntil: 'domcontentloaded', timeout: opts.stepTimeoutMs });
|
|
165
|
+
await mobilePage.waitForTimeout(100).catch(() => { });
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
mobileError = err;
|
|
169
|
+
}
|
|
170
|
+
const outcome = mobileError
|
|
171
|
+
? skipped('Page did not load at 375px, so the mobile check was not run.')
|
|
172
|
+
: await assessLoadedPage(mobilePage, 'mobile', url, bucket(mobilePage), linkBudget);
|
|
173
|
+
await record(mobileFlow, url, outcome, opts, steps, traces, mobilePage);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
await desktop.close().catch(() => { });
|
|
180
|
+
await mobile.close().catch(() => { });
|
|
181
|
+
}
|
|
182
|
+
return flows.map(flow => {
|
|
183
|
+
const flowSteps = steps.get(flow.id) ?? [];
|
|
184
|
+
const traceSteps = traces.get(flow.id) ?? [];
|
|
185
|
+
const failed = flowSteps.some(step => step.status === 'failed');
|
|
186
|
+
const result = {
|
|
187
|
+
flowId: flow.id,
|
|
188
|
+
name: flow.name,
|
|
189
|
+
description: flow.description,
|
|
190
|
+
kind: flow.kind,
|
|
191
|
+
startUrl: flow.startUrl,
|
|
192
|
+
status: resolveFlowStatus(flowSteps, failed),
|
|
193
|
+
...(failed ? { failureReason: flowSteps.find(step => step.status === 'failed')?.error } : {}),
|
|
194
|
+
severityIfFails: flow.severityIfFails,
|
|
195
|
+
steps: flowSteps,
|
|
196
|
+
durationMs: flowSteps.reduce((sum, step) => sum + (step.durationMs ?? 0), 0),
|
|
197
|
+
bugIds: [],
|
|
198
|
+
trace: serializeTrace({
|
|
199
|
+
version: 1,
|
|
200
|
+
flowId: flow.id,
|
|
201
|
+
name: flow.name,
|
|
202
|
+
description: flow.description,
|
|
203
|
+
kind: flow.kind,
|
|
204
|
+
startUrl: flow.startUrl,
|
|
205
|
+
expectation: flow.expectation,
|
|
206
|
+
severityIfFails: flow.severityIfFails,
|
|
207
|
+
steps: traceSteps,
|
|
208
|
+
}),
|
|
209
|
+
};
|
|
210
|
+
opts.onFlowComplete?.(result);
|
|
211
|
+
return result;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
async function assessLoadedPage(page, kind, url, collected, linkBudget, status) {
|
|
215
|
+
if (kind === 'console')
|
|
216
|
+
return judgeConsoleStep(collected, url);
|
|
217
|
+
if (kind === 'http')
|
|
218
|
+
return judgeHttpStep(page, url, collected, linkBudget, status);
|
|
219
|
+
if (kind === 'axe')
|
|
220
|
+
return judgeAxeStep(page);
|
|
221
|
+
if (kind === 'mobile')
|
|
222
|
+
return judgeMobileStep(page);
|
|
223
|
+
return judgeMetaStep(page);
|
|
224
|
+
}
|
|
225
|
+
function judgeConsoleStep(collected, url) {
|
|
226
|
+
const judged = judgeConsole(collected.hits, url);
|
|
227
|
+
if (judged.bugs.length === 0) {
|
|
228
|
+
const note = judged.ignored ? [`Ignored ${judged.ignored} third-party or automation message${judged.ignored === 1 ? '' : 's'}.`] : [];
|
|
229
|
+
return passed('No first-party console error or uncaught exception on load.', note);
|
|
230
|
+
}
|
|
231
|
+
const lines = judged.bugs.slice(0, 4).map(hit => hit.kind === 'pageerror' ? `Uncaught page error: ${hit.message}` : `Console error: ${hit.message}`);
|
|
232
|
+
const first = judged.bugs[0];
|
|
233
|
+
const error = first.kind === 'pageerror'
|
|
234
|
+
? `pageerror: ${first.message}`
|
|
235
|
+
: `console-error: ${first.message}`;
|
|
236
|
+
return failed(lines.join(' '), error, { consoleErrors: consoleEvidence(judged.bugs) });
|
|
237
|
+
}
|
|
238
|
+
async function judgeHttpStep(page, url, collected, linkBudget, status) {
|
|
239
|
+
const requests = dedupeRequests([
|
|
240
|
+
...(status && status >= 400 && isBrokenStatus(status)
|
|
241
|
+
? [{ url, method: 'GET', status, resourceType: 'document' }]
|
|
242
|
+
: []),
|
|
243
|
+
...collected.requests.filter(item => isReportableRequest(item, url)),
|
|
244
|
+
]);
|
|
245
|
+
const broken = await probeLinks(page, url, linkBudget);
|
|
246
|
+
if (requests.length === 0 && broken.length === 0) {
|
|
247
|
+
return passed('Same-site requests and sampled links responded.');
|
|
248
|
+
}
|
|
249
|
+
const lines = [
|
|
250
|
+
...requests.slice(0, 4).map(item => item.status
|
|
251
|
+
? `${item.method || 'GET'} ${item.url} returned HTTP ${item.status}.`
|
|
252
|
+
: `${item.url} failed (${item.failureText || 'network'}).`),
|
|
253
|
+
...broken.slice(0, 4).map(link => link.status
|
|
254
|
+
? `Link ${link.url} returned HTTP ${link.status}.`
|
|
255
|
+
: `Link ${link.url} failed.`),
|
|
256
|
+
];
|
|
257
|
+
const lead = requests[0] ?? broken[0];
|
|
258
|
+
const code = lead?.status;
|
|
259
|
+
const error = code ? `http-${code}` : 'request-failed';
|
|
260
|
+
const network = [...requestEvidence(requests), ...linkEvidence(broken)];
|
|
261
|
+
return failed(lines.join(' '), error, { networkFailures: network });
|
|
262
|
+
}
|
|
263
|
+
async function probeLinks(page, pageUrl, budget) {
|
|
264
|
+
if (budget.remaining <= 0)
|
|
265
|
+
return [];
|
|
266
|
+
const hrefs = await page.$$eval('a[href]', anchors => anchors.map(anchor => anchor.getAttribute('href') || '')).catch(() => []);
|
|
267
|
+
const links = sameSiteLinks(hrefs, pageUrl, budget.remaining);
|
|
268
|
+
const broken = [];
|
|
269
|
+
for (const link of links) {
|
|
270
|
+
if (budget.remaining <= 0)
|
|
271
|
+
break;
|
|
272
|
+
budget.remaining -= 1;
|
|
273
|
+
try {
|
|
274
|
+
const response = await page.request.get(link, { timeout: 5_000, failOnStatusCode: false, maxRedirects: 2 });
|
|
275
|
+
if (isBrokenStatus(response.status()))
|
|
276
|
+
broken.push({ url: link, status: response.status() });
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
280
|
+
if (/ERR_ABORTED|ERR_BLOCKED_BY_CLIENT/i.test(message))
|
|
281
|
+
continue;
|
|
282
|
+
broken.push({ url: link, failureText: 'request failed' });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return broken;
|
|
286
|
+
}
|
|
287
|
+
async function judgeAxeStep(page) {
|
|
288
|
+
let judgement;
|
|
289
|
+
try {
|
|
290
|
+
judgement = await runAxe(page);
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
return passed('axe-core could not run on this page. Recorded as info, not a bug.', ['axe did not finish.']);
|
|
294
|
+
}
|
|
295
|
+
const missing = await page.evaluate(readMissingLoginAutocomplete).catch(() => []);
|
|
296
|
+
const autocomplete = [
|
|
297
|
+
...judgement.autocomplete,
|
|
298
|
+
...missing.slice(0, 4).map(name => `Login field "${name}" has no autocomplete attribute.`),
|
|
299
|
+
];
|
|
300
|
+
const info = judgement.info.slice(0, 4);
|
|
301
|
+
if (judgement.serious.length > 0) {
|
|
302
|
+
const lines = judgement.serious.slice(0, 4).map(item => `${item.impact} ${item.id}: ${item.help}`);
|
|
303
|
+
const first = judgement.serious[0];
|
|
304
|
+
return failed(lines.join(' '), `axe:${first.id}`, {}, [...info, ...autocomplete.map(line => `Minor: ${line}`)]);
|
|
305
|
+
}
|
|
306
|
+
if (autocomplete.length > 0) {
|
|
307
|
+
return failed(autocomplete.slice(0, 3).join(' '), 'autocomplete-missing', { severity: 'minor' }, info);
|
|
308
|
+
}
|
|
309
|
+
return passed(judgement.info.length ? 'No serious or critical WCAG A/AA violation.' : 'No WCAG A/AA violation.', info);
|
|
310
|
+
}
|
|
311
|
+
async function judgeMobileStep(page) {
|
|
312
|
+
const snapshot = await page.evaluate(readMobileInPage);
|
|
313
|
+
const judged = judgeMobile(snapshot);
|
|
314
|
+
if (judged.bugs.length === 0)
|
|
315
|
+
return passed('No horizontal overflow and no undersized tap target at 375px.', judged.info);
|
|
316
|
+
const error = judged.bugs[0].startsWith('The page is') ? 'overflow' : 'tap-target';
|
|
317
|
+
return failed(judged.bugs.join(' '), error, { severity: 'minor' }, judged.info);
|
|
318
|
+
}
|
|
319
|
+
async function judgeMetaStep(page) {
|
|
320
|
+
const snapshot = await page.evaluate(readMetaInPage);
|
|
321
|
+
const judged = judgeMeta(snapshot);
|
|
322
|
+
if (judged.bugs.length === 0)
|
|
323
|
+
return passed('Title and viewport are present.', judged.info);
|
|
324
|
+
const error = judged.bugs.some(line => /viewport/i.test(line)) && !snapshot.title.trim()
|
|
325
|
+
? 'missing-title'
|
|
326
|
+
: snapshot.title.trim() ? 'missing-viewport' : 'missing-title';
|
|
327
|
+
return failed(judged.bugs.join(' '), error, { severity: 'minor' }, judged.info);
|
|
328
|
+
}
|
|
329
|
+
function loadFailure(kind, url, err) {
|
|
330
|
+
if (kind !== 'http' && kind !== 'console') {
|
|
331
|
+
return skipped('Page did not finish loading, so this check was not run.');
|
|
332
|
+
}
|
|
333
|
+
const raw = err instanceof Error ? err.message : String(err);
|
|
334
|
+
if (/ERR_ABORTED|ERR_BLOCKED_BY_CLIENT/i.test(raw) || isOwnAutomationText(raw)) {
|
|
335
|
+
return passed('The load was interrupted by the browser. Recorded as info, not a bug.');
|
|
336
|
+
}
|
|
337
|
+
if (kind === 'console')
|
|
338
|
+
return passed('No first-party console error was captured before the load stopped.');
|
|
339
|
+
return failed(`Could not load ${url}.`, 'navigation-failed');
|
|
340
|
+
}
|
|
341
|
+
function isOwnAutomationText(text) {
|
|
342
|
+
return /waiting for locator|locator\.fill|strict mode violation|invalid selector/i.test(text);
|
|
343
|
+
}
|
|
344
|
+
function flowUrls(flow) {
|
|
345
|
+
if (!flow)
|
|
346
|
+
return [];
|
|
347
|
+
const urls = [];
|
|
348
|
+
for (const step of flow.steps) {
|
|
349
|
+
const url = step.url;
|
|
350
|
+
if (url && !urls.includes(url))
|
|
351
|
+
urls.push(url);
|
|
352
|
+
}
|
|
353
|
+
return urls;
|
|
354
|
+
}
|
|
355
|
+
function kindOf(flow) {
|
|
356
|
+
const kind = flow.steps.find(step => step.pageCheck)?.pageCheck;
|
|
357
|
+
return isPageCheck(kind) ? kind : undefined;
|
|
358
|
+
}
|
|
359
|
+
function dedupeRequests(items) {
|
|
360
|
+
const seen = new Set();
|
|
361
|
+
return items.filter(item => {
|
|
362
|
+
const key = `${item.method || 'GET'} ${item.status || 0} ${item.url}`;
|
|
363
|
+
if (seen.has(key))
|
|
364
|
+
return false;
|
|
365
|
+
seen.add(key);
|
|
366
|
+
return true;
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
async function record(flow, url, outcome, opts, steps, traces, page) {
|
|
370
|
+
const list = steps.get(flow.id);
|
|
371
|
+
if (!list)
|
|
372
|
+
return;
|
|
373
|
+
const index = list.length + 1;
|
|
374
|
+
const spec = isPageCheck(flow.steps[0]?.pageCheck) ? pageCheckSpec(flow.steps[0].pageCheck) : undefined;
|
|
375
|
+
const action = flow.steps[index - 1]?.action || `${spec?.action || 'Check'} on ${url}`;
|
|
376
|
+
const expectation = flow.steps[index - 1]?.expectation;
|
|
377
|
+
const result = {
|
|
378
|
+
index,
|
|
379
|
+
action,
|
|
380
|
+
expectation,
|
|
381
|
+
status: outcome.status,
|
|
382
|
+
observation: outcome.observation,
|
|
383
|
+
tool: 'check',
|
|
384
|
+
target: url,
|
|
385
|
+
resolution: 'recorded',
|
|
386
|
+
durationMs: 0,
|
|
387
|
+
...(outcome.error ? { error: outcome.error } : {}),
|
|
388
|
+
...(outcome.severity ? { severity: outcome.severity } : {}),
|
|
389
|
+
...(outcome.consoleErrors ? { consoleErrors: outcome.consoleErrors } : {}),
|
|
390
|
+
...(outcome.networkFailures ? { networkFailures: outcome.networkFailures } : {}),
|
|
391
|
+
};
|
|
392
|
+
if (outcome.status === 'failed' && page) {
|
|
393
|
+
const path = shotPath(opts.screenshotsDir, flow.id, index, outcome.status);
|
|
394
|
+
try {
|
|
395
|
+
await page.screenshot({ path, fullPage: false });
|
|
396
|
+
result.screenshotPath = path;
|
|
397
|
+
}
|
|
398
|
+
catch { /* a missed screenshot is not a bug */ }
|
|
399
|
+
}
|
|
400
|
+
list.push(result);
|
|
401
|
+
const trace = {
|
|
402
|
+
index,
|
|
403
|
+
action,
|
|
404
|
+
expectation,
|
|
405
|
+
tool: 'check',
|
|
406
|
+
locator: { strategy: 'css', target: url },
|
|
407
|
+
value: flow.steps[index - 1]?.pageCheck,
|
|
408
|
+
urlAfter: url,
|
|
409
|
+
status: outcome.status,
|
|
410
|
+
observation: outcome.observation,
|
|
411
|
+
...(outcome.error ? { error: outcome.error } : {}),
|
|
412
|
+
resolution: 'recorded',
|
|
413
|
+
...(outcome.consoleErrors ? { consoleErrors: outcome.consoleErrors } : {}),
|
|
414
|
+
...(outcome.networkFailures ? { networkFailures: outcome.networkFailures } : {}),
|
|
415
|
+
...(result.screenshotPath ? { screenshotPath: result.screenshotPath } : {}),
|
|
416
|
+
};
|
|
417
|
+
traces.get(flow.id)?.push(serializeTraceStep(trace));
|
|
418
|
+
opts.onStep?.(flow, result);
|
|
419
|
+
}
|
|
420
|
+
export function shotPath(dir, flowId, index, status) {
|
|
421
|
+
const slug = flowId.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60) || 'flow';
|
|
422
|
+
return join(dir, `flow-${slug}-step-${String(index).padStart(2, '0')}-${status}.png`);
|
|
423
|
+
}
|
|
424
|
+
//# sourceMappingURL=execute.js.map
|