@ashishjain15491/tapcheck 0.0.0-stage → 0.1.1
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 +87 -0
- package/LICENSE +21 -0
- package/README.md +190 -2
- package/dist/auth.d.ts +5 -0
- package/dist/auth.js +100 -0
- package/dist/browser.d.ts +143 -0
- package/dist/browser.js +237 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +321 -0
- package/dist/config.d.ts +169 -0
- package/dist/config.js +369 -0
- package/dist/coverage.d.ts +17 -0
- package/dist/coverage.js +56 -0
- package/dist/flow.d.ts +193 -0
- package/dist/flow.js +512 -0
- package/dist/jev.d.ts +48 -0
- package/dist/jev.js +89 -0
- package/dist/parts.d.ts +65 -0
- package/dist/parts.js +157 -0
- package/dist/questions.d.ts +66 -0
- package/dist/questions.js +203 -0
- package/dist/report.d.ts +29 -0
- package/dist/report.js +59 -0
- package/dist/routes.d.ts +18 -0
- package/dist/routes.js +54 -0
- package/dist/stub.d.ts +51 -0
- package/dist/stub.js +244 -0
- package/dist/suites/a11y.d.ts +3 -0
- package/dist/suites/a11y.js +73 -0
- package/dist/suites/audit.d.ts +2 -0
- package/dist/suites/audit.js +440 -0
- package/dist/suites/code.d.ts +10 -0
- package/dist/suites/code.js +48 -0
- package/dist/suites/contract.d.ts +5 -0
- package/dist/suites/contract.js +79 -0
- package/dist/suites/crawl.d.ts +2 -0
- package/dist/suites/crawl.js +135 -0
- package/dist/suites/interact.d.ts +2 -0
- package/dist/suites/interact.js +319 -0
- package/dist/suites/security.d.ts +12 -0
- package/dist/suites/security.js +134 -0
- package/dist/suites/usability.d.ts +3 -0
- package/dist/suites/usability.js +205 -0
- package/dist/suites/ux.d.ts +6 -0
- package/dist/suites/ux.js +183 -0
- package/package.json +61 -5
- package/schema/tapcheck.schema.json +368 -0
package/dist/flow.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { BrowserContext, Page } from 'playwright';
|
|
2
|
+
import { type Run } from './browser.ts';
|
|
3
|
+
import { type Config } from './config.ts';
|
|
4
|
+
import type { FailRule, Reply, Seen } from './stub.ts';
|
|
5
|
+
/** For a flow's own questions to t.jev(), t.ask() and t.mail.judge(), and tapcheck's own sets to start from. */
|
|
6
|
+
export { choice, noul, score } from '@typesafe-ai/sdk';
|
|
7
|
+
export { EMAIL, VISUAL } from './questions.ts';
|
|
8
|
+
/**
|
|
9
|
+
* timeout: seconds the whole flow may take (default 3600); past it the flow fails and the run goes on.
|
|
10
|
+
* serial: with `parallel` above 1, this flow runs alone, after the flows before it end and before the ones after it start
|
|
11
|
+
* (for a flow that changes data the others read, stub rules or the whole Mailpit inbox).
|
|
12
|
+
*/
|
|
13
|
+
export type Flow = {
|
|
14
|
+
name: string;
|
|
15
|
+
side?: string;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
serial?: boolean;
|
|
18
|
+
run: (t: T) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
/** A flow as loaded: its side settled and its part name. */
|
|
21
|
+
export type Loaded = Required<Flow> & {
|
|
22
|
+
part: string;
|
|
23
|
+
};
|
|
24
|
+
/** One message in Mailpit. headers: every header by name, as Mailpit spells it ("List-Unsubscribe"), each with its values. */
|
|
25
|
+
export type Mail = {
|
|
26
|
+
id: string;
|
|
27
|
+
subject: string;
|
|
28
|
+
from: string;
|
|
29
|
+
to: string[];
|
|
30
|
+
html: string;
|
|
31
|
+
text: string;
|
|
32
|
+
links: string[];
|
|
33
|
+
headers: Record<string, string[]>;
|
|
34
|
+
};
|
|
35
|
+
/** What a flow's run() is handed. */
|
|
36
|
+
export declare class T {
|
|
37
|
+
private r;
|
|
38
|
+
private flow;
|
|
39
|
+
private stubUrl?;
|
|
40
|
+
private pages;
|
|
41
|
+
private fresh;
|
|
42
|
+
private signedOut;
|
|
43
|
+
private errors;
|
|
44
|
+
private current?;
|
|
45
|
+
private cleanups;
|
|
46
|
+
private shots;
|
|
47
|
+
private dead;
|
|
48
|
+
private abort;
|
|
49
|
+
/** Aborted when the flow runs out of time: pass it to long waits of your own, or check `t.signal.aborted` in a loop. */
|
|
50
|
+
readonly signal: AbortSignal;
|
|
51
|
+
constructor(r: Run, flow: Loaded, stubUrl?: string);
|
|
52
|
+
/** The run's folder, for files of the flow's own (a payload log, a list it made). */
|
|
53
|
+
get dir(): string;
|
|
54
|
+
private record;
|
|
55
|
+
private live;
|
|
56
|
+
/** Stops the flow at its timeout: later findings are dropped and `t.signal` is aborted. */
|
|
57
|
+
kill(why: string): void;
|
|
58
|
+
/** Past the timeout every t.* call but a cleanup's throws, so the abandoned run() stops at its next one. */
|
|
59
|
+
private alive;
|
|
60
|
+
/** Runs `fn` when the flow ends, also when it fails or runs out of time (each one gets 60 s): put back what it changed. */
|
|
61
|
+
cleanup(fn: () => unknown): void;
|
|
62
|
+
/**
|
|
63
|
+
* Runs the cleanups, last added first; one that throws or hangs is a warning. Past the timeout the flow's pages are
|
|
64
|
+
* closed first, so the abandoned run() can't drive one while a cleanup works: a cleanup's t.page() opens new ones.
|
|
65
|
+
* Only what a cleanup awaits itself carries its t.* rights: a Playwright handler it adds (page.on) runs outside them
|
|
66
|
+
* unless wrapped with AsyncResource.bind (node:async_hooks).
|
|
67
|
+
*/
|
|
68
|
+
finish(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* A page on the flow's side, signed in with the side's session (`{ auth: false }`: signed out), at the first viewport
|
|
71
|
+
* or the one `viewport` names (`{ viewport: 'mobile' }`, a name from the config's viewports). One of each is kept, and
|
|
72
|
+
* the page handed out last is the current one: t.goto() and t.jev() act on it. `{ fresh: true }` gives a new page in
|
|
73
|
+
* a context of its own every time (cookies and storage its own too), for a second visitor or a sign-in of the flow's own;
|
|
74
|
+
* it is the current page too, until t.page() or t.use() hands out another.
|
|
75
|
+
*/
|
|
76
|
+
page(opts?: {
|
|
77
|
+
auth?: boolean;
|
|
78
|
+
viewport?: string;
|
|
79
|
+
fresh?: boolean;
|
|
80
|
+
}): Promise<Page>;
|
|
81
|
+
/**
|
|
82
|
+
* Makes `page` the current one: t.goto(), t.jev() and a failed step's screenshot act on it. For a page t.page() handed
|
|
83
|
+
* out earlier (back to the first visitor after a second one), or a tab the app opened itself (`context.waitForEvent('page')`).
|
|
84
|
+
*/
|
|
85
|
+
use(page: Page): Page;
|
|
86
|
+
/**
|
|
87
|
+
* Opens a path of the side (or a full URL) on the current page and waits for it to settle. On a signed-in page, being
|
|
88
|
+
* sent to sign in (`loginPaths`) when the path isn't a sign-in page throws: the side's session has ended. A flow that
|
|
89
|
+
* expects to be sent there (after signing out, or to check a page is refused) passes `{ guard: false }`.
|
|
90
|
+
*/
|
|
91
|
+
goto(path: string, opts?: {
|
|
92
|
+
guard?: boolean;
|
|
93
|
+
}): Promise<Page>;
|
|
94
|
+
/**
|
|
95
|
+
* Counts a request to the app the flow made itself (page.request, fetch) as reached, for hits.json and COVERAGE=1.
|
|
96
|
+
* Pass its answer's status, and one the app refused (401, 403, 405) or didn't find (404) isn't counted, as in the browser.
|
|
97
|
+
*/
|
|
98
|
+
reach(method: string, url: string, status?: number): void;
|
|
99
|
+
/** Throws `msg` unless `cond` holds. (Not an `asserts` signature: TypeScript refuses those on the untyped `t` of `run: async (t) => …`.) */
|
|
100
|
+
expect(cond: unknown, msg: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* One finding: passes when `fn` returns (a string it returns is the detail), fails when it throws; returning
|
|
103
|
+
* `{ warn }` makes it a warning with that detail (it worked, with something to look at). Returns whether it didn't fail.
|
|
104
|
+
*/
|
|
105
|
+
step(name: string, fn: () => Promise<void | string | {
|
|
106
|
+
warn: string;
|
|
107
|
+
}>): Promise<boolean>;
|
|
108
|
+
/** A finding the flow decides itself: a warning (default), a failure, or info such as a check it skipped and why. */
|
|
109
|
+
note(name: string, detail: string, status?: 'warn' | 'info' | 'fail'): void;
|
|
110
|
+
/** Records that Jev's look at `label` was skipped, and why. */
|
|
111
|
+
private skipped;
|
|
112
|
+
/**
|
|
113
|
+
* Asks Jev about `state`; one finding per answer. Null, and one finding, when its budget is spent (info) or Jev can't
|
|
114
|
+
* be reached (a warning): a look never stops the flow.
|
|
115
|
+
*/
|
|
116
|
+
private look;
|
|
117
|
+
/**
|
|
118
|
+
* Jev's look at the current page: screenshots of it (up to three screens, top to bottom) and the visual questions
|
|
119
|
+
* (loaded, no error, overlap, clipping, raw keys, alignment), or your own `questions` about `screenshots` (built with
|
|
120
|
+
* the TypeSafe SDK's noul, score and choice). Each answer is a finding of the flow, and an unsure one a warning. A
|
|
121
|
+
* yes-or-no question of your own passes on yes; a score passes from 7 of 10 and is a warning below; any other answer is
|
|
122
|
+
* recorded as info. The page is looked at once it has settled. The answers are returned for the flow's own checks; null when Jev is off or over its budget.
|
|
123
|
+
*/
|
|
124
|
+
jev(label: string, questions?: Record<string, any>): Promise<Record<string, any> | null>;
|
|
125
|
+
/**
|
|
126
|
+
* Jev's answers to `questions` about `state` you describe yourself (text, data; images built with the SDK's image()
|
|
127
|
+
* whose files are `images`): no screenshot is taken. Findings, budget and null as for t.jev().
|
|
128
|
+
*/
|
|
129
|
+
ask(label: string, state: Record<string, unknown>, questions: Record<string, any>, images?: string[]): Promise<Record<string, any> | null>;
|
|
130
|
+
/** Mailpit and the stub: 30 s at most a call, and none past the flow's timeout (but a cleanup's). */
|
|
131
|
+
private api;
|
|
132
|
+
private need;
|
|
133
|
+
/** The stub server (src/stub.ts): the outside requests it saw, and how it answers the next ones. */
|
|
134
|
+
get stub(): {
|
|
135
|
+
/** Requests seen, oldest first: by host (or parent domain), a part of the path, and from a time (ms) on. */
|
|
136
|
+
requests: (f?: {
|
|
137
|
+
host?: string;
|
|
138
|
+
path?: string;
|
|
139
|
+
since?: number;
|
|
140
|
+
}) => Promise<Seen[]>;
|
|
141
|
+
/** Fails the next `times` matching requests (default 1; 0: until clear()). */
|
|
142
|
+
fail: (rule: FailRule) => Promise<void>;
|
|
143
|
+
/** Answers the next matching request with this, once. */
|
|
144
|
+
reply: (rule: Reply) => Promise<void>;
|
|
145
|
+
/** Answers that DNS question with these values from now on (stub.dns); null puts the config's answer back. */
|
|
146
|
+
dns: (name: string, type: string, values: string[] | null) => Promise<void>;
|
|
147
|
+
/** Forgets the requests seen, the failures, the queued replies and the DNS answers set here. */
|
|
148
|
+
clear: () => Promise<void>;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Sends a browser context's requests for hosts that aren't local through the stub, so nothing in the browser reaches a
|
|
152
|
+
* real outside service. Redirects are followed here hop by hop (a browser doesn't hand them back), so the app sending
|
|
153
|
+
* the browser to an outside page (a provider's sign-in or checkout) lands on the stub too.
|
|
154
|
+
*/
|
|
155
|
+
routeOutside(ctx: BrowserContext): Promise<void>;
|
|
156
|
+
/** The mail the app sent, read from Mailpit (config `mail.mailpit`). */
|
|
157
|
+
get mail(): {
|
|
158
|
+
/** The newest message to that address and/or with that subject (a part of it), waiting up to timeoutMs (default 30 s) for it. */
|
|
159
|
+
waitFor: (f?: {
|
|
160
|
+
to?: string;
|
|
161
|
+
subject?: string;
|
|
162
|
+
} & {
|
|
163
|
+
timeoutMs?: number;
|
|
164
|
+
}) => Promise<Mail>;
|
|
165
|
+
/** How many messages are to that address and/or have that subject (a part of either); all of them without a filter. */
|
|
166
|
+
count: (f?: {
|
|
167
|
+
to?: string;
|
|
168
|
+
subject?: string;
|
|
169
|
+
}) => Promise<number>;
|
|
170
|
+
/** Every such message, newest first, each read in full: at most `limit` (1 to 500, default 500); `limit: 1` is the newest or none. */
|
|
171
|
+
all: (f?: {
|
|
172
|
+
to?: string;
|
|
173
|
+
subject?: string;
|
|
174
|
+
} & {
|
|
175
|
+
limit?: number;
|
|
176
|
+
}) => Promise<Mail[]>;
|
|
177
|
+
/**
|
|
178
|
+
* Jev's look at an email: its HTML drawn in a page (scripts off) at a computer's and at a phone's width, then asked
|
|
179
|
+
* whether it is laid out properly, has no unfilled placeholder, shows its links and buttons, and reads on a phone
|
|
180
|
+
* (or your own `questions` about `screenshot` and `screenshot_mobile`). Findings and null as for t.jev().
|
|
181
|
+
* ponytail: only the first 1500 px of the email are looked at; slice it if long emails matter.
|
|
182
|
+
*/
|
|
183
|
+
judge: (m: Pick<Mail, 'subject' | 'html'>, questions?: Record<string, any>) => Promise<Record<string, any> | null>;
|
|
184
|
+
/** Deletes every message in Mailpit. */
|
|
185
|
+
clear: () => Promise<void>;
|
|
186
|
+
};
|
|
187
|
+
/** Closes the flow's pages. */
|
|
188
|
+
close(): Promise<void>;
|
|
189
|
+
}
|
|
190
|
+
/** Imports every file the `flows` globs match (relative to the config file) and checks each default export. */
|
|
191
|
+
export declare function loadFlows(cfg: Config): Promise<Loaded[]>;
|
|
192
|
+
/** Runs one flow on its side; whatever it throws outside a step is the caller's to record. */
|
|
193
|
+
export declare function runFlow(flow: Loaded, r: Run, stubUrl?: string): Promise<void>;
|