@ashishjain15491/tapcheck 0.1.1 → 0.1.3

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.
@@ -8,7 +8,7 @@
8
8
  * missed-routes.json.
9
9
  */
10
10
  import { writeFileSync } from 'node:fs';
11
- import { abs, context, facts, guard, host, watch } from '../browser.js';
11
+ import { abs, context, facts, here, host, load, marked, signedIn, watch } from '../browser.js';
12
12
  import { coverage, hasParams, routes } from '../routes.js';
13
13
  const SLOW_MS = 3000;
14
14
  function listen(r, page, current) {
@@ -71,35 +71,38 @@ export async function run(r) {
71
71
  errors.length = 0;
72
72
  const t0 = Date.now();
73
73
  let download = false; // a link to a file (a PDF invoice): Playwright downloads it and goto throws
74
- const res = await page.goto(abs(r, path), { waitUntil: 'domcontentloaded' }).catch((e) => { download = /Download is starting/.test(e.message); return null; });
74
+ const res = await load(page, abs(r, path)).catch((e) => { download = /Download is starting/.test(e.message); return null; });
75
75
  if (download)
76
76
  continue; // not a page; "in-app links answer" still checks that it answers
77
77
  await page.waitForLoadState('networkidle', { timeout: 15_000 }).catch(() => { });
78
78
  const ms = Date.now() - t0;
79
- const finalPath = new URL(page.url()).pathname;
79
+ const finalPath = here(page.url(), path);
80
80
  const st = res?.status() ?? 0;
81
81
  // A route from the list that isn't this side's (refused, sent to sign in) or isn't a page (a download): not a finding.
82
82
  if (route && (st === 0 || [401, 403, 404, 405].includes(st) || (r.cfg.loginPaths.test(finalPath) && !r.cfg.loginPaths.test(path))))
83
83
  continue;
84
- guard(r, path, page.url());
84
+ await signedIn(r, page, path);
85
85
  const f = await facts(page).catch(() => null);
86
86
  const links = [...new Set((f?.controls ?? []).map((c) => c.href).filter((h) => !!h && host(h) === own)
87
- .map((h) => { const u = new URL(h); return u.pathname + u.search; }))];
87
+ .map((h) => { const u = new URL(h); return u.pathname + u.search + (/^#!?\//.test(u.hash) ? u.hash : ''); }))]; // #/orders is a route, #section a place on the page
88
88
  r.crawl.pages.push({ path, status: st, finalPath, ms, errors: [...errors], links });
89
89
  visits++;
90
90
  const where = path;
91
- r.record({ suite: S, where, check: 'page answers', status: st >= 200 && st < 400 ? 'pass' : 'fail', detail: `${st}${finalPath !== path.split('?')[0] ? ` → ${finalPath}` : ''}` });
91
+ r.record({ suite: S, where, check: 'page answers', status: st >= 200 && st < 400 ? 'pass' : 'fail', detail: `${st}${finalPath !== path.split('?')[0].replace(/#$/, '') ? ` → ${finalPath}` : ''}` });
92
92
  r.record({ suite: S, where, check: `loads under ${SLOW_MS} ms`, status: ms < SLOW_MS ? 'pass' : 'warn', detail: `${ms} ms` });
93
93
  r.record({ suite: S, where, check: 'no console or page errors', status: errors.length ? 'fail' : 'pass', detail: errors.slice(0, 3).join(' | ') || undefined });
94
+ // MARK=1: the elements a failing check tagged while it measured, boxed on the page as it is now.
95
+ const shot = async (check, detail, tag) => { const m = r.cfg.marks ? await marked(r, page, `crawl ${where} ${check}`, { status: 'fail', title: check, detail: `${where} · ${detail}` }, [{ target: `[data-tapcheck-mark-${tag}]` }]) : undefined; return m ? [m] : undefined; };
94
96
  if (f?.brokenImages.length)
95
- r.record({ suite: S, where, check: 'images load', status: 'fail', detail: f.brokenImages.slice(0, 5).join(', ') });
97
+ r.record({ suite: S, where, check: 'images load', status: 'fail', detail: f.brokenImages.slice(0, 5).join(', '), evidence: await shot('images load', f.brokenImages.slice(0, 5).join(', '), 'broken') });
96
98
  const unlabelled = await page.$$eval('input:not([type=hidden]):not([type=submit]):not([type=button]), select, textarea', (els) => els.filter((el) => {
97
99
  const e = el;
98
100
  if (e.offsetParent === null || el.closest('[aria-hidden=true]'))
99
101
  return false;
100
102
  return !(e.labels?.length || e.getAttribute('aria-label') || e.getAttribute('aria-labelledby') || e.title);
101
- }).map((el) => el.name || el.id || el.tagName.toLowerCase())).catch(() => []);
102
- r.record({ suite: S, where, check: 'form fields labelled', status: unlabelled.length ? 'fail' : 'pass', detail: unlabelled.slice(0, 6).join(', ') || undefined });
103
+ }).map((el) => { el.setAttribute('data-tapcheck-mark-unlabelled', 'no label'); return el.name || el.id || el.tagName.toLowerCase(); })).catch(() => []);
104
+ r.record({ suite: S, where, check: 'form fields labelled', status: unlabelled.length ? 'fail' : 'pass', detail: unlabelled.slice(0, 6).join(', ') || undefined,
105
+ evidence: unlabelled.length ? await shot('form fields labelled', unlabelled.slice(0, 6).join(', '), 'unlabelled') : undefined });
103
106
  for (const l of links) {
104
107
  if (skip.test(l.split('?')[0]))
105
108
  continue;
@@ -22,7 +22,7 @@
22
22
  */
23
23
  import { writeFileSync } from 'node:fs';
24
24
  import { isLocal } from '../config.js';
25
- import { context, host, open, reach, SessionExpired, watch } from '../browser.js';
25
+ import { context, hashRoute, host, marked, open, reach, SessionExpired, watch } from '../browser.js';
26
26
  import { UNSAFE } from './usability.js';
27
27
  const S = 'interact';
28
28
  const MAX_CLICKS = 30; // per screen
@@ -179,18 +179,26 @@ export async function run(r) {
179
179
  });
180
180
  const wait = async () => { await page.waitForTimeout(WAIT); if (seen.requests)
181
181
  await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => { }); };
182
- const still = (u) => u.split('#')[0];
183
182
  try {
184
183
  for (const path of paths) {
184
+ // On a hash-routed screen a new hash is another screen; elsewhere a hash is a place on the same page.
185
+ const still = (u) => (hashRoute(path) ? u : u.split('#')[0]);
185
186
  const broke = [], failed = [], native = [], dead = [], clicked = [];
187
+ const who = { broke: [], failed: [], native: [] }; // the labels behind those lists, for a marked screenshot
186
188
  const clear = () => { seen.errors.length = seen.bad.length = seen.natives.length = seen.requests = seen.popups = 0; };
187
189
  const drain = (label) => {
188
- if (seen.errors.length)
190
+ if (seen.errors.length) {
189
191
  broke.push(`"${label}": ${seen.errors[0].slice(0, 120)}`);
190
- if (seen.bad.length)
192
+ who.broke.push(label);
193
+ }
194
+ if (seen.bad.length) {
191
195
  failed.push(`"${label}" → ${seen.bad[0]}`);
192
- if (seen.natives.length)
196
+ who.failed.push(label);
197
+ }
198
+ if (seen.natives.length) {
193
199
  native.push(`"${label}": ${seen.natives[0]}`);
200
+ who.native.push(label);
201
+ }
194
202
  clear();
195
203
  };
196
204
  try {
@@ -297,10 +305,17 @@ export async function run(r) {
297
305
  await attempt('menu', 'row menu opens', t.menu, (l) => l.click({ timeout: 3000 }), () => page.evaluate((DIALOG) => [...document.querySelectorAll(`[role=menu], [role=listbox], details[open], ${DIALOG}`)].some((el) => el.getClientRects().length > 0), DIALOG));
298
306
  log.tables.push(entry);
299
307
  }
300
- r.record({ suite: S, where: path, check: 'clicks raise no page or console errors', status: broke.length ? 'fail' : 'pass', detail: broke.slice(0, 4).join(' | ') || `${clicked.length} control(s) clicked` });
301
- r.record({ suite: S, where: path, check: 'clicks set off no 5xx', status: failed.length ? 'fail' : 'pass', detail: failed.slice(0, 4).join('; ') || undefined });
302
- r.record({ suite: S, where: path, check: 'no native alert, confirm or prompt', status: native.length ? 'fail' : 'pass', detail: native.slice(0, 4).join('; ') || undefined });
303
- r.record({ suite: S, where: path, check: 'every control does something', status: dead.length ? 'warn' : 'pass', detail: dead.length ? `nothing changed after: ${dead.slice(0, 6).map((l) => `"${l}"`).join(', ')}` : undefined });
308
+ // MARK=1: the screen once more, and each failing check's controls boxed, those that are still there under the same label.
309
+ const now = r.cfg.marks && (broke.length || failed.length || native.length || dead.length) ? await open(r, page, path).then(() => tag(page, own, r.cfg.crawl.skip)).catch(() => []) : [];
310
+ const rec = async (check, status, detail, labels, note) => {
311
+ const marks = status === 'pass' ? [] : now.filter((c) => labels.includes(c.label)).map((c) => ({ target: `[data-tapcheck="${c.i}"]`, note }));
312
+ const shot = marks.length ? await marked(r, page, `interact ${path} ${check}`, { status, title: check, detail: `${path} · ${detail}` }, marks) : undefined;
313
+ r.record({ suite: S, where: path, check, status, detail, evidence: shot ? [shot] : undefined });
314
+ };
315
+ await rec('clicks raise no page or console errors', broke.length ? 'fail' : 'pass', broke.slice(0, 4).join(' | ') || `${clicked.length} control(s) clicked`, who.broke, 'raised an error');
316
+ await rec('clicks set off no 5xx', failed.length ? 'fail' : 'pass', failed.slice(0, 4).join('; ') || undefined, who.failed, 'set off a 5xx');
317
+ await rec('no native alert, confirm or prompt', native.length ? 'fail' : 'pass', native.slice(0, 4).join('; ') || undefined, who.native, 'opened a native dialog');
318
+ await rec('every control does something', dead.length ? 'warn' : 'pass', dead.length ? `nothing changed after: ${dead.slice(0, 6).map((l) => `"${l}"`).join(', ')}` : undefined, dead, 'nothing changed');
304
319
  }
305
320
  catch (e) {
306
321
  if (e instanceof SessionExpired)
@@ -14,7 +14,7 @@ import { context, open, SessionExpired, settle, slug } from '../browser.js';
14
14
  import { ask, bad, BudgetReached, good, img, NO } from '../jev.js';
15
15
  import { MAX_STEPS, SCROLL, TASK_Q } from '../questions.js';
16
16
  const S = 'usability';
17
- export const UNSAFE = /\b(delete|remove|destroy|log ?out|sign out|send|publish|unpublish|pay|upgrade|downgrade|cancel|archive|disconnect|revoke|unsubscribe|reset|discard|take down|impersonat)/i;
17
+ export const UNSAFE = /\b(delete|remove|destroy|log ?out|sign out|send|publish|unpublish|pay|upgrade|downgrade|cancel|archive|disconnect|revoke|unsubscribe|reset|discard|take down|impersonat|dark mode|light mode|theme)/i;
18
18
  // ponytail: fixed bands, enough to tell two same-labelled controls apart; read the page's landmarks if this misnames them.
19
19
  const place = (c) => (c.y < 72 ? 'at the top of the screen' : c.x < 260 ? 'on the left side' : 'in the main area');
20
20
  /**
package/dist/suites/ux.js CHANGED
@@ -125,7 +125,7 @@ export async function run(r) {
125
125
  r.record({ suite: S, where, check: 'no raw translation keys (measured)', status: raw.length ? 'fail' : 'pass', detail: raw.slice(0, 6).join(', ') || undefined, evidence: raw.length ? [shots[0]] : undefined });
126
126
  // One request for every judgment over the same screenshots.
127
127
  const a = await ask(key, { screen: s.name, viewport: `${vp.name}, ${vp.width} × ${vp.height} px`, screenshots: shots.map(img),
128
- note: shots.length > 1 ? 'The screenshots are consecutive slices of one screen, top to bottom.' : undefined }, { ...VISUAL, ...DESIGN, ...HEURISTICS(r.cfg.audience) }, shots);
128
+ note: shots.length > 1 ? 'The screenshots are consecutive slices of one screen, top to bottom.' : undefined }, { ...VISUAL, ...DESIGN, ...HEURISTICS(r.cfg.audience, r.cfg.context) }, shots);
129
129
  visual(r, S, where, a, shots);
130
130
  for (const k of ['cta', 'cta_label', 'negative_space', 'hierarchy', 'legibility', 'spacing'])
131
131
  scored(r, where, `design: ${k.replace('_', ' ')}`, a[k], shots);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ashishjain15491/tapcheck",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "End-to-end and UI audit harness for any web app, whatever its stack: crawl, API contract, security, accessibility, and Jev judgments of what people see.",
5
5
  "license": "MIT",
6
6
  "author": "ashishjain15491 (https://github.com/ashishjain15491)",
@@ -28,6 +28,18 @@
28
28
  }
29
29
  },
30
30
  "audience": { "$ref": "#/definitions/text", "description": "Who the app is for, in the words Jev is asked with (\"a shop owner\", \"a nurse on a ward\").", "default": "a first-time visitor" },
31
+ "context": { "$ref": "#/definitions/text", "description": "What kind of product it is and the conventions its users expect (\"a dense, real-time trading tool; market terms and packed tables are intended\"). Sent to Jev with every question." },
32
+ "expect": {
33
+ "description": "Findings that are right for this product: a fail or warn whose \"<suite>: <check> @ <where>\" matches `match` is recorded as info, saying `why`.",
34
+ "type": "array",
35
+ "items": {
36
+ "type": "object",
37
+ "additionalProperties": false,
38
+ "required": ["match", "why"],
39
+ "properties": { "match": { "$ref": "#/definitions/text", "description": "A regular expression (case-insensitive) on \"<suite>: <check> @ <where>\"." }, "why": { "$ref": "#/definitions/text" } }
40
+ },
41
+ "default": []
42
+ },
31
43
  "sides": {
32
44
  "description": "Each kind of person who sees a different app, by name. Names are lowercase letters, digits and dashes, and can't be a suite or tag name.",
33
45
  "type": "object",
@@ -35,7 +47,7 @@
35
47
  "default": { "public": {} },
36
48
  "propertyNames": {
37
49
  "pattern": "^[a-z][a-z0-9-]*$",
38
- "not": { "enum": ["crawl", "contract", "security", "a11y", "interact", "audit", "ux", "usability", "code", "flow", "jev", "measured"] }
50
+ "not": { "enum": ["crawl", "contract", "security", "a11y", "interact", "audit", "ux", "usability", "code", "flow", "jev", "measured", "verify"] }
39
51
  },
40
52
  "additionalProperties": {
41
53
  "type": ["object", "null"],
@@ -43,7 +55,8 @@
43
55
  "properties": {
44
56
  "baseUrl": { "description": "This side's own address, when it differs from the top-level baseUrl.", "type": "string", "pattern": "^(https?://[^/]+|.*\\$\\{?[A-Z_])" },
45
57
  "login": { "$ref": "#/definitions/login" },
46
- "csrf": { "$ref": "#/definitions/csrf", "description": "This side's own CSRF probe, in place of security.csrf (another host often has other routes)." }
58
+ "csrf": { "$ref": "#/definitions/csrf", "description": "This side's own CSRF probe, in place of security.csrf (another host often has other routes)." },
59
+ "signedIn": { "description": "A CSS selector on every signed-in page and not on the sign-in form (the account menu). A page without it means the session has ended, for apps that show their sign-in form at the same address.", "type": "string" }
47
60
  }
48
61
  }
49
62
  },
@@ -259,6 +272,10 @@
259
272
  "oneOf": [{ "$ref": "#/definitions/text" }, { "type": "array", "items": { "$ref": "#/definitions/text" } }],
260
273
  "default": []
261
274
  },
275
+ "marks": {
276
+ "description": "Marked screenshots (MARK=1 or MARK=0 overrides it for one run): a failing or warning finding's evidence opens with the screen as it was measured, a banner saying the check, and a box, a number and a note on each element the check knows (audit, a11y, crawl, interact, and t.mark in flows). What Jev judged gets the banner alone.",
277
+ "type": "boolean", "default": false
278
+ },
262
279
  "mail": {
263
280
  "type": "object",
264
281
  "additionalProperties": false,