trykeyline-browser 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +14 -2
- package/audit/probe.mjs +390 -0
- package/audit.mjs +231 -0
- package/bin/trykeyline-browser.mjs +79 -0
- package/browse/args.mjs +44 -0
- package/browse/capture.mjs +181 -0
- package/browse/compare.mjs +263 -0
- package/browse/findings.mjs +129 -0
- package/browse/playwright.mjs +78 -0
- package/browse/report.mjs +301 -0
- package/browse/routes.mjs +252 -0
- package/browse/score.mjs +46 -0
- package/browse/serve.mjs +61 -0
- package/browse/walk.mjs +117 -0
- package/browse.mjs +175 -0
- package/package.json +53 -4
- package/probe.mjs +26 -0
- package/smoke/clicks.mjs +320 -0
- package/smoke/config.mjs +184 -0
- package/smoke/forms.mjs +329 -0
- package/smoke/keyboard.mjs +100 -0
- package/smoke/links.mjs +120 -0
- package/smoke/page.mjs +575 -0
- package/smoke/phone.mjs +126 -0
- package/smoke/shift.mjs +103 -0
- package/smoke/util.mjs +113 -0
- package/smoke.mjs +412 -0
package/smoke.mjs
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyline's smoke test: walk a running product like a tester and report the
|
|
3
|
+
* flows that break. Built on the shared walk (browse/walk.mjs) — which finds
|
|
4
|
+
* the pages, screenshots them and records load failures, exceptions and failed
|
|
5
|
+
* requests — plus passes that use the product:
|
|
6
|
+
*
|
|
7
|
+
* links every same-origin link's status, redirect chains and loops
|
|
8
|
+
* clicks every control clicked from a fresh page: dead clicks, Escape on
|
|
9
|
+
* menus and dialogs, Back after moving, and state lost on reload
|
|
10
|
+
* stuck spinners, skeletons and aria-busy still there after 8 s
|
|
11
|
+
* back (part of clicks) Back restores the previous URL and content
|
|
12
|
+
* forms submit empty, invalid and valid: errors by the field, success shown
|
|
13
|
+
* keyboard Tab through: traps, focus you can't see, focus on hidden things
|
|
14
|
+
* phone at 390px: sideways scroll, navigation that can't be reached
|
|
15
|
+
* shift layout shift while loading on a slow connection
|
|
16
|
+
*
|
|
17
|
+
* keyline smoke (--base URL | --serve DIR) [options]
|
|
18
|
+
* keyline smoke probe <name> a page function, for an agent's own browser
|
|
19
|
+
* keyline smoke report [DIR] re-render DIR/index.html
|
|
20
|
+
*
|
|
21
|
+
* Exit codes: 0 nothing broken, 1 errors found, 2 a usage error.
|
|
22
|
+
*/
|
|
23
|
+
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
24
|
+
import { join, resolve } from "node:path";
|
|
25
|
+
import { parseOrExplain } from "./browse/args.mjs";
|
|
26
|
+
import { target } from "./browse.mjs";
|
|
27
|
+
import { add, counts, dedupe, writeRun } from "./browse/findings.mjs";
|
|
28
|
+
import { openContext, shotKey, withHelpers } from "./browse/capture.mjs";
|
|
29
|
+
import { launch } from "./browse/playwright.mjs";
|
|
30
|
+
import { renderDir } from "./browse/report.mjs";
|
|
31
|
+
import { discover } from "./browse/routes.mjs";
|
|
32
|
+
import { walk } from "./browse/walk.mjs";
|
|
33
|
+
import { checkClicks } from "./smoke/clicks.mjs";
|
|
34
|
+
import { CHECKS, isDestructivePath, loadConfig, policy as makePolicy, settings as makeSettings } from "./smoke/config.mjs";
|
|
35
|
+
import { checkForms } from "./smoke/forms.mjs";
|
|
36
|
+
import { checkKeyboard } from "./smoke/keyboard.mjs";
|
|
37
|
+
import { checkLinks } from "./smoke/links.mjs";
|
|
38
|
+
import { PAGE } from "./smoke/page.mjs";
|
|
39
|
+
import { probeExpression } from "./probe.mjs";
|
|
40
|
+
import { checkPhone } from "./smoke/phone.mjs";
|
|
41
|
+
import { checkShift } from "./smoke/shift.mjs";
|
|
42
|
+
import { openStep, pool, sourceFinder } from "./smoke/util.mjs";
|
|
43
|
+
|
|
44
|
+
const USAGE = `keyline smoke — walk a running product like a tester and report broken flows.
|
|
45
|
+
|
|
46
|
+
keyline smoke (--base URL | --serve DIR) [options]
|
|
47
|
+
keyline smoke probe <name> [--arg JSON]
|
|
48
|
+
print a page function to run in your own browser:
|
|
49
|
+
${Object.keys(PAGE).join(", ")}
|
|
50
|
+
keyline smoke report [DIR] re-render DIR/index.html (default smoke-report)
|
|
51
|
+
|
|
52
|
+
Checks: ${CHECKS.join(", ")} (all by default).
|
|
53
|
+
|
|
54
|
+
Options:
|
|
55
|
+
--base <url> the running product, e.g. http://localhost:3000
|
|
56
|
+
--serve <dir> serve a static folder on a free port instead
|
|
57
|
+
--root <dir> the project's code, for routes and sources (default: .)
|
|
58
|
+
--config <file> settings (default: <root>/keyline.smoke.json)
|
|
59
|
+
--out <dir> where the report goes (default: smoke-report)
|
|
60
|
+
--routes <a,b> only these paths
|
|
61
|
+
--limit <n> at most this many pages (default 20)
|
|
62
|
+
--only <checks> only these checks, e.g. links,clicks
|
|
63
|
+
--skip <checks> every check but these
|
|
64
|
+
--max-clicks <n> controls clicked per page (default 30)
|
|
65
|
+
--quiet-ms <n> how long a click may take to do something (default 1500)
|
|
66
|
+
--stuck-ms <n> when a loading indicator counts as stuck (default 8000)
|
|
67
|
+
--test-host <host> treat this host as a test host too (writes may run)
|
|
68
|
+
--allow-writes on a test host, include destructive actions too
|
|
69
|
+
--concurrency <n> pages worked on at once (default 3)
|
|
70
|
+
--headed show the browser
|
|
71
|
+
-h, --help this
|
|
72
|
+
|
|
73
|
+
Writes (form submits; anything that says delete, remove, pay, buy, purchase,
|
|
74
|
+
unsubscribe, sign out or log out) run only on localhost, 127.0.0.1, *.localhost,
|
|
75
|
+
*.test or a host the config lists in testHosts; destructive ones only with
|
|
76
|
+
--allow-writes. Elsewhere every request that isn't GET, HEAD or OPTIONS is blocked.`;
|
|
77
|
+
|
|
78
|
+
export const SMOKE_OPTIONS = {
|
|
79
|
+
values: ["base", "serve", "root", "config", "out", "routes", "limit", "only", "skip", "max-clicks", "quiet-ms", "stuck-ms", "test-host", "concurrency", "arg"],
|
|
80
|
+
switches: ["headed", "allow-writes"],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Sign in once and return a storage state every context starts from. */
|
|
84
|
+
async function signIn(browser, { base, auth, root, log }) {
|
|
85
|
+
if (!auth) return undefined;
|
|
86
|
+
if (auth.storageState) {
|
|
87
|
+
const path = resolve(root, auth.storageState);
|
|
88
|
+
if (!existsSync(path)) throw new Error(`auth.storageState: no file at ${path}`);
|
|
89
|
+
return path;
|
|
90
|
+
}
|
|
91
|
+
const login = auth.login;
|
|
92
|
+
if (!login) return undefined;
|
|
93
|
+
log(`Signing in at ${login.url ?? "/"} …`);
|
|
94
|
+
const context = await browser.newContext();
|
|
95
|
+
const page = await context.newPage();
|
|
96
|
+
try {
|
|
97
|
+
await page.goto(new URL(login.url ?? "/", base).href, { waitUntil: "load", timeout: 30000 });
|
|
98
|
+
for (const step of login.steps) {
|
|
99
|
+
if (step.fill) {
|
|
100
|
+
const value = process.env[step.env];
|
|
101
|
+
if (value == null) throw new Error(`login: the environment variable ${step.env} isn't set`);
|
|
102
|
+
await page.locator(step.fill).first().fill(value, { timeout: 10000 });
|
|
103
|
+
} else if (step.click) {
|
|
104
|
+
await page.locator(step.click).first().click({ timeout: 10000 });
|
|
105
|
+
} else if (step.press) {
|
|
106
|
+
await page.keyboard.press(step.press);
|
|
107
|
+
} else if (step.waitFor) {
|
|
108
|
+
const w = String(step.waitFor);
|
|
109
|
+
if (w.startsWith("/")) await page.waitForURL((u) => new URL(u).pathname.startsWith(w), { timeout: 20000 });
|
|
110
|
+
else await page.locator(w).first().waitFor({ timeout: 20000 });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
await page.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => {});
|
|
114
|
+
return await context.storageState();
|
|
115
|
+
} finally {
|
|
116
|
+
await context.close();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Every context gets the same guard: forbidden URLs never load, and writes stop where they aren't allowed. */
|
|
121
|
+
function guard({ policy, settings, blocked }) {
|
|
122
|
+
return async (context) => {
|
|
123
|
+
await context.route("**/*", (route) => {
|
|
124
|
+
const req = route.request();
|
|
125
|
+
const url = req.url();
|
|
126
|
+
const method = req.method();
|
|
127
|
+
if (settings.forbidUrl(url)) {
|
|
128
|
+
blocked.push(`${method} ${url} (forbidden by the config)`);
|
|
129
|
+
return route.abort("blockedbyclient");
|
|
130
|
+
}
|
|
131
|
+
const write = !["GET", "HEAD", "OPTIONS"].includes(method);
|
|
132
|
+
if (write && !policy.testHost) {
|
|
133
|
+
blocked.push(`${method} ${url} (not a test host)`);
|
|
134
|
+
return route.abort("blockedbyclient");
|
|
135
|
+
}
|
|
136
|
+
if (method === "DELETE" && !policy.allowWrites) {
|
|
137
|
+
blocked.push(`${method} ${url} (destructive; --allow-writes runs it)`);
|
|
138
|
+
return route.abort("blockedbyclient");
|
|
139
|
+
}
|
|
140
|
+
return route.fallback();
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const NOUNS = {
|
|
146
|
+
"flow/dead-click": ["dead click", "dead clicks"],
|
|
147
|
+
"flow/broken-link": ["broken link", "broken links"],
|
|
148
|
+
"flow/redirect-loop": ["redirect loop", "redirect loops"],
|
|
149
|
+
"flow/redirect-chain": ["redirect chain", "redirect chains"],
|
|
150
|
+
"flow/stuck-loading": ["stuck loading state", "stuck loading states"],
|
|
151
|
+
"flow/state-lost": ["view lost on reload", "views lost on reload"],
|
|
152
|
+
"flow/back-broken": ["broken Back", "broken Backs"],
|
|
153
|
+
"flow/silent-validation": ["form that refuses input in silence", "forms that refuse input in silence"],
|
|
154
|
+
"flow/validation-far": ["error shown away from its field", "errors shown away from their fields"],
|
|
155
|
+
"flow/accepts-invalid": ["form that sends bad input", "forms that send bad input"],
|
|
156
|
+
"flow/silent-success": ["submit with no confirmation", "submits with no confirmation"],
|
|
157
|
+
"flow/dead-submit": ["submit that does nothing", "submits that do nothing"],
|
|
158
|
+
"flow/submit-failed": ["form that fails", "forms that fail"],
|
|
159
|
+
"flow/focus-trap": ["focus trap", "focus traps"],
|
|
160
|
+
"flow/focus-invisible": ["page with invisible focus", "pages with invisible focus"],
|
|
161
|
+
"flow/focus-hidden": ["page where focus goes off screen", "pages where focus goes off screen"],
|
|
162
|
+
"flow/escape-ignored": ["menu Escape won't close", "menus Escape won't close"],
|
|
163
|
+
"flow/focus-not-returned": ["menu that drops focus", "menus that drop focus"],
|
|
164
|
+
"flow/phone-overflow": ["page wider than a phone", "pages wider than a phone"],
|
|
165
|
+
"flow/phone-nav-missing": ["page whose navigation is lost on a phone", "pages whose navigation is lost on a phone"],
|
|
166
|
+
"flow/phone-menu-dead": ["phone menu that doesn't open", "phone menus that don't open"],
|
|
167
|
+
"flow/layout-shift": ["page that jumps while loading", "pages that jump while loading"],
|
|
168
|
+
"flow/click-blocked": ["covered control", "covered controls"],
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
function summarise(run, { policy, checks }) {
|
|
172
|
+
const s = run.stats;
|
|
173
|
+
const did = [];
|
|
174
|
+
if (checks.has("clicks")) did.push(`clicked ${s.clicks} ${s.clicks === 1 ? "control" : "controls"}`);
|
|
175
|
+
if (checks.has("links")) did.push(`followed ${s.links} ${s.links === 1 ? "link" : "links"}`);
|
|
176
|
+
const formsSkipped = run.skipped.filter((x) => /form/.test(x.what) && !/proper submit/.test(x.what)).length;
|
|
177
|
+
if (checks.has("forms")) did.push(s.forms ? `submitted ${s.forms} ${s.forms === 1 ? "form" : "forms"} empty, wrong and right` : formsSkipped ? "submitted no forms" : "found no forms to submit");
|
|
178
|
+
if (checks.has("keyboard")) did.push(`tabbed through ${s.tabbed} ${s.tabbed === 1 ? "page" : "pages"}`);
|
|
179
|
+
if (checks.has("shift")) did.push("loaded each on a slow connection");
|
|
180
|
+
const byRule = new Map();
|
|
181
|
+
for (const f of run.findings) byRule.set(f.rule, (byRule.get(f.rule) ?? 0) + 1);
|
|
182
|
+
const found = [...byRule]
|
|
183
|
+
.filter(([rule]) => NOUNS[rule])
|
|
184
|
+
.sort((a, b) => b[1] - a[1])
|
|
185
|
+
.map(([rule, n]) => `${n} ${NOUNS[rule][n === 1 ? 0 : 1]}`);
|
|
186
|
+
const runtime = run.findings.filter((f) => f.domain === "runtime" && f.severity === "error").length;
|
|
187
|
+
if (runtime) found.push(`${runtime} runtime ${runtime === 1 ? "error" : "errors"}`);
|
|
188
|
+
const pages = `${run.pages.length} ${run.pages.length === 1 ? "page" : "pages"}`;
|
|
189
|
+
let text = `Walked ${pages} at desktop${checks.has("phone") ? " and phone" : ""} width; ${did.join(", ")}. `;
|
|
190
|
+
text += found.length ? `Found ${found.join(", ")}.` : "Every flow tried worked.";
|
|
191
|
+
if (!policy.testHost) text += " This isn't a test host, so nothing was submitted and every write request was blocked.";
|
|
192
|
+
if (run.skipped.length) text += ` ${run.skipped.length} ${run.skipped.length === 1 ? "action was" : "actions were"} skipped for safety or by the config (listed in findings.json).`;
|
|
193
|
+
return text;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function projectTitle(root, fallback) {
|
|
197
|
+
try {
|
|
198
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
199
|
+
if (pkg.name) return pkg.name;
|
|
200
|
+
} catch {
|
|
201
|
+
// No package.json: use the page title.
|
|
202
|
+
}
|
|
203
|
+
return fallback;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The whole smoke test. Returns the run (also written to `out`).
|
|
208
|
+
* `browser` may be given (tests launch their own); otherwise one is launched and closed.
|
|
209
|
+
*/
|
|
210
|
+
export async function smoke({ base, root, out, config = {}, opts = {}, browser: given = null, headless = true, log = (m) => process.stderr.write(m + "\n") }) {
|
|
211
|
+
const settings = makeSettings(opts, config);
|
|
212
|
+
const policy = makePolicy({ base, testHosts: settings.testHosts, allowWrites: settings.allowWrites });
|
|
213
|
+
const checks = settings.checks;
|
|
214
|
+
const skipped = [];
|
|
215
|
+
const blocked = [];
|
|
216
|
+
const find = sourceFinder(root);
|
|
217
|
+
const prepare = guard({ policy, settings, blocked });
|
|
218
|
+
log(`Smoke test of ${base}${policy.testHost ? " (a test host: forms will be submitted)" : " (not a test host: no writes)"}`);
|
|
219
|
+
|
|
220
|
+
// Pages: given, configured, or discovered — with an example for each dynamic route.
|
|
221
|
+
const reachable = (path) => {
|
|
222
|
+
const href = new URL(path, base).href;
|
|
223
|
+
if (settings.forbidUrl(href)) return false;
|
|
224
|
+
return settings.allowWrites || !isDestructivePath(href);
|
|
225
|
+
};
|
|
226
|
+
let routes;
|
|
227
|
+
let dynamic = [];
|
|
228
|
+
const list = (v) => String(v).split(",").map((s) => s.trim()).filter(Boolean);
|
|
229
|
+
if (opts.routes) routes = list(opts.routes);
|
|
230
|
+
else if (config.routes?.length) routes = config.routes;
|
|
231
|
+
else {
|
|
232
|
+
const found = await discover({ root, base, limit: settings.limit });
|
|
233
|
+
routes = found.routes.map((r) => r.path);
|
|
234
|
+
for (const d of found.dynamic) {
|
|
235
|
+
const example = settings.examples[d.path] ?? d.sample;
|
|
236
|
+
if (example) routes.push(example);
|
|
237
|
+
dynamic.push({ path: d.path, sample: example ?? null, file: d.file ?? null });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
for (const [pattern, example] of Object.entries(settings.examples)) {
|
|
241
|
+
if (!routes.includes(example) && !dynamic.some((d) => d.path === pattern)) routes.push(example);
|
|
242
|
+
}
|
|
243
|
+
routes = [...new Set(routes)].filter(reachable).slice(0, settings.limit);
|
|
244
|
+
if (!routes.length) routes = ["/"];
|
|
245
|
+
|
|
246
|
+
const browser = given ?? (await launch({ root, headless, log }));
|
|
247
|
+
try {
|
|
248
|
+
const storageState = await signIn(browser, { base, auth: config.auth, root, log });
|
|
249
|
+
const fresh = async (viewport = "desktop") => {
|
|
250
|
+
const context = await withHelpers(await openContext(browser, { viewport, theme: "light", storageState }));
|
|
251
|
+
await prepare(context);
|
|
252
|
+
context.setDefaultTimeout(15000);
|
|
253
|
+
return context;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// 1. The walk: every page at desktop and phone, an inventory of each, and loaders that never stop.
|
|
257
|
+
const inventories = { desktop: new Map(), phone: new Map() };
|
|
258
|
+
const probes = [{ name: "inventory", fn: PAGE.inventory }];
|
|
259
|
+
if (checks.has("stuck")) probes.push({ name: "stuck", fn: PAGE.stuck, arg: { after: settings.stuckMs } });
|
|
260
|
+
const run = await walk({
|
|
261
|
+
kind: "smoke",
|
|
262
|
+
title: config.title ?? null,
|
|
263
|
+
base,
|
|
264
|
+
root,
|
|
265
|
+
out,
|
|
266
|
+
routes,
|
|
267
|
+
limit: settings.limit,
|
|
268
|
+
viewports: checks.has("phone") ? ["desktop", "phone"] : ["desktop"],
|
|
269
|
+
themes: ["light"],
|
|
270
|
+
probes,
|
|
271
|
+
browser,
|
|
272
|
+
storageState,
|
|
273
|
+
prepare,
|
|
274
|
+
follow: reachable,
|
|
275
|
+
log,
|
|
276
|
+
judge: (run, v) => {
|
|
277
|
+
const inv = v.results?.inventory;
|
|
278
|
+
if (inv && !inv.error) inventories[v.viewport].set(v.route, inv);
|
|
279
|
+
if (v.viewport !== "desktop") return;
|
|
280
|
+
for (const s of Array.isArray(v.results?.stuck) ? v.results.stuck : []) {
|
|
281
|
+
add(run, {
|
|
282
|
+
page: v.route,
|
|
283
|
+
viewport: "desktop",
|
|
284
|
+
theme: "light",
|
|
285
|
+
shot: shotKey("desktop", "light"),
|
|
286
|
+
box: s.box,
|
|
287
|
+
selector: s.sel,
|
|
288
|
+
...(find(s) ?? {}),
|
|
289
|
+
rule: "flow/stuck-loading",
|
|
290
|
+
severity: "error",
|
|
291
|
+
title: `A loading state never finishes${s.text ? `: “${s.text}”` : ""}`,
|
|
292
|
+
evidence: `${s.why} still showing ${s.seconds} s after the page started loading`,
|
|
293
|
+
detail: "Whatever this waits for never arrives, or never says so. Show the content, an empty state, or an error with a way to retry.",
|
|
294
|
+
fix: "/keyline patterns",
|
|
295
|
+
steps: [openStep(v.route), `Wait ${settings.stuckMs / 1000} s`, `${s.text ? `“${s.text}”` : s.sel} is still loading`],
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
run.dynamic = dynamic;
|
|
301
|
+
run.title ??= projectTitle(root, run.pages.find((p) => p.route === "/")?.title ?? run.pages[0]?.title ?? null);
|
|
302
|
+
run.stats = { clicks: 0, links: 0, forms: 0, tabbed: 0, shiftChecked: 0 };
|
|
303
|
+
run.checks = [...checks];
|
|
304
|
+
run.skipped = skipped;
|
|
305
|
+
run.blocked = blocked;
|
|
306
|
+
run.testHost = policy.testHost;
|
|
307
|
+
const visited = run.pages.filter((p) => inventories.desktop.has(p.route)).map((p) => p.route);
|
|
308
|
+
|
|
309
|
+
// 2. Links.
|
|
310
|
+
let broken = new Set();
|
|
311
|
+
if (checks.has("links")) {
|
|
312
|
+
const context = await fresh();
|
|
313
|
+
try {
|
|
314
|
+
broken = await checkLinks({ run, request: context.request, base, inventories: inventories.desktop, settings, skipped, log });
|
|
315
|
+
} finally {
|
|
316
|
+
await context.close();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// 3–7. The passes that use each page, a few pages at a time, each in its own context.
|
|
321
|
+
const perPage = async (name, viewport, fn) => {
|
|
322
|
+
if (!checks.has(name)) return;
|
|
323
|
+
await pool(visited, settings.concurrency, async (route) => {
|
|
324
|
+
const context = await fresh(viewport);
|
|
325
|
+
try {
|
|
326
|
+
await fn({ context, route });
|
|
327
|
+
} catch (err) {
|
|
328
|
+
log(` ${name} ${route}: ${String(err?.message ?? err).split("\n")[0]}`);
|
|
329
|
+
} finally {
|
|
330
|
+
await context.close().catch(() => {});
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
};
|
|
334
|
+
const common = { run, base, settings, policy, skipped, log, find };
|
|
335
|
+
if (!checks.has("clicks") && (checks.has("back"))) checks.add("clicks"); // Back is checked on the clicks that move
|
|
336
|
+
await perPage("clicks", "desktop", ({ context, route }) => checkClicks({ ...common, context, route, inventory: inventories.desktop.get(route) }));
|
|
337
|
+
await perPage("forms", "desktop", ({ context, route }) => checkForms({ ...common, context, route, inventory: inventories.desktop.get(route) }));
|
|
338
|
+
await perPage("keyboard", "desktop", ({ context, route }) => checkKeyboard({ ...common, context, route }));
|
|
339
|
+
await perPage("phone", "phone", ({ context, route }) => checkPhone({ ...common, context, route, desktop: inventories.desktop.get(route), phone: inventories.phone.get(route) }));
|
|
340
|
+
await perPage("shift", "desktop", ({ context, route }) => checkShift({ ...common, context, route }));
|
|
341
|
+
|
|
342
|
+
// A 404 the walk found by following a link is already reported, better, as that link.
|
|
343
|
+
const ownUrl = (f) => {
|
|
344
|
+
try {
|
|
345
|
+
return (new URL(f.evidence.split(" ")[1]).pathname.replace(/\/+$/, "") || "/") === f.page;
|
|
346
|
+
} catch {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
run.findings = dedupe(run.findings.filter((f) => !(broken.has(f.page) && (f.rule === "runtime/http-status" || (f.rule === "runtime/request-failed" && ownUrl(f))))));
|
|
351
|
+
run.summary = summarise(run, { policy, checks });
|
|
352
|
+
return run;
|
|
353
|
+
} finally {
|
|
354
|
+
if (!given) await browser.close();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export async function run(argv) {
|
|
359
|
+
const opts = parseOrExplain("smoke", argv, SMOKE_OPTIONS);
|
|
360
|
+
if (!opts) return 2;
|
|
361
|
+
const [cmd, arg] = opts._;
|
|
362
|
+
if (opts.help) {
|
|
363
|
+
console.log(USAGE);
|
|
364
|
+
return 0;
|
|
365
|
+
}
|
|
366
|
+
if (cmd === "probe") {
|
|
367
|
+
try {
|
|
368
|
+
const given = opts.arg ? JSON.parse(opts.arg) : arg === "stuck" ? { after: Number(opts["stuck-ms"] ?? 8000) } : {};
|
|
369
|
+
console.log(probeExpression(arg ?? "inventory", given));
|
|
370
|
+
return 0;
|
|
371
|
+
} catch (err) {
|
|
372
|
+
console.error(err.message);
|
|
373
|
+
return 2;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (cmd === "report") {
|
|
377
|
+
console.log(renderDir(resolve(arg ?? opts.out ?? "smoke-report")));
|
|
378
|
+
return 0;
|
|
379
|
+
}
|
|
380
|
+
if (cmd) {
|
|
381
|
+
console.error(`no command '${cmd}'\n\n${USAGE}`);
|
|
382
|
+
return 2;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const root = resolve(opts.root ?? opts.serve ?? ".");
|
|
386
|
+
let config;
|
|
387
|
+
try {
|
|
388
|
+
config = loadConfig({ root, file: opts.config ?? null });
|
|
389
|
+
} catch (err) {
|
|
390
|
+
console.error(err.message);
|
|
391
|
+
return 2;
|
|
392
|
+
}
|
|
393
|
+
if (!opts.base && !opts.serve && config.base) opts.base = config.base;
|
|
394
|
+
const t = await target({ ...opts, root });
|
|
395
|
+
if (!t) {
|
|
396
|
+
console.error("smoke needs --base <url>, --serve <dir>, or a base in keyline.smoke.json\n");
|
|
397
|
+
console.error(USAGE);
|
|
398
|
+
return 2;
|
|
399
|
+
}
|
|
400
|
+
const out = resolve(opts.out ?? "smoke-report");
|
|
401
|
+
if (existsSync(join(out, "shots"))) rmSync(join(out, "shots"), { recursive: true });
|
|
402
|
+
try {
|
|
403
|
+
const result = await smoke({ base: t.base, root: t.root, out, config, opts, headless: !opts.headed });
|
|
404
|
+
writeRun(out, result);
|
|
405
|
+
const file = renderDir(out);
|
|
406
|
+
const c = counts(result.findings);
|
|
407
|
+
console.log(`\n${result.summary}\n\n${result.pages.length} pages · ${c.error} errors · ${c.warning} warnings · ${c.info} notes\n${file}`);
|
|
408
|
+
return c.error ? 1 : 0;
|
|
409
|
+
} finally {
|
|
410
|
+
await t.stop();
|
|
411
|
+
}
|
|
412
|
+
}
|