@orkestrel/test 0.0.5 → 0.0.7

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/README.md CHANGED
@@ -5,10 +5,12 @@ real callback rather than a spy. A real host delay. A throw-to-value converter a
5
5
  narrower, so `!` and `as` stay banned in tests. Two async collectors and a JSON copier. A frozen
6
6
  hostile-value corpus for proving guards are total. A cleanup list that gives every owned resource
7
7
  back, newest first. A scratch directory the test owns and destroys, a loopback port for a server the
8
- test built, and a symlink-refusing source-file walker. A helper ships here only when enough packages
9
- had already written their own; the guide's
10
- [Limits](guides/test.md#limits) section states that rule and what it excluded. Add it as a
11
- devDependency; nothing here runs in production code. Part of the `@orkestrel` line.
8
+ test built, and a symlink-refusing source-file walker. And the browser journey layer, which drives
9
+ a real interface by role and accessible name through the installed Vitest provider. A helper ships
10
+ here only when enough packages had already written their own; the guide's
11
+ [Limits](guides/test.md#limits) section states that rule, what it excluded, and the one door the
12
+ journey layer came through instead. Add it as a devDependency; nothing here runs in production
13
+ code. Part of the `@orkestrel` line.
12
14
 
13
15
  It has **zero runtime dependencies**, and no exported signature names an `@orkestrel/*` type. Both
14
16
  rules exist for one reason: a test helper hands its types straight into the consumer's assertions,
@@ -27,8 +29,10 @@ npm install -D @orkestrel/test
27
29
 
28
30
  ## Usage
29
31
 
30
- `@orkestrel/test` is the host-independent core. `@orkestrel/test/server` is the Node face. Core
31
- touches neither `node:*` nor the DOM, so a browser test project imports it unchanged.
32
+ `@orkestrel/test` is the host-independent core. `@orkestrel/test/server` is the Node face.
33
+ `@orkestrel/test/browser` is the journey layer, which drives a real browser through the installed
34
+ Vitest provider. Core touches neither `node:*` nor the DOM, so a browser test project imports it
35
+ unchanged.
32
36
 
33
37
  ```ts
34
38
  import {
@@ -141,6 +145,14 @@ leaves the root through a link in the middle, and skips a symlink met while walk
141
145
  sandbox against hostile filesystem content: those refusals stop accidental escape, not an adversary
142
146
  who can create hard links where the test process already writes.
143
147
 
148
+ The browser face is the journey layer: an accessible-name resolver with exact failure voices,
149
+ region and disclosure targeting, input and traversal verbs, perception readers, a WCAG contrast
150
+ instrument that composites translucent layers, and the capture portfolio. Every acting verb
151
+ resolves its own target from a role and an accessible name — none takes an element, a component
152
+ instance, or a selector — and the whole environment imports `vitest/browser` and DOM globals and
153
+ nothing else, with `vitest` declared as a peer dependency. The guide's
154
+ [Browser](guides/test.md#browser) section carries every export and every voice.
155
+
144
156
  `createLoopback` binds a server the test built. The caller constructs it and keeps every route,
145
157
  header, and status on it; this package supplies the bind and the release and nothing else.
146
158
 
@@ -179,9 +191,10 @@ rule deciding what ships and what stays in the package that owns it — see
179
191
 
180
192
  ## Package
181
193
 
182
- Published as two typed entry points per the `exports` field in `package.json`: `@orkestrel/test` for
183
- the host-independent core, `@orkestrel/test/server` for the Node helpers. Both ship ESM and
184
- CommonJS.
194
+ Published as three typed entry points per the `exports` field in `package.json`: `@orkestrel/test`
195
+ for the host-independent core, `@orkestrel/test/browser` for the journey layer, and
196
+ `@orkestrel/test/server` for the Node helpers. Core and server ship ESM and CommonJS; the browser
197
+ face ships ESM only, because `vitest/browser` is an ES-only module.
185
198
 
186
199
  ## License
187
200
 
@@ -0,0 +1,478 @@
1
+ /**
2
+ * The interactive ARIA roles a bare accessible name is searched across.
3
+ *
4
+ * @remarks
5
+ * A person names a control, not a role, so the one-argument resolver searches every role a control
6
+ * can compute. The two-argument form searches exactly the role it is given, which is how a name
7
+ * shared by a tab and its panel is disambiguated.
8
+ */
9
+ export declare const ACCESSIBLE_ROLES: readonly string[];
10
+
11
+ /** One theme-and-viewport pair a capture run renders. */
12
+ export declare interface CaptureVariant {
13
+ /** The variant's name, which is the second half of every filename the run writes. */
14
+ readonly name: string;
15
+ /** The viewport width in pixels. */
16
+ readonly width: number;
17
+ /** The viewport height in pixels. */
18
+ readonly height: number;
19
+ /**
20
+ * The document change this variant needs before the viewport is resized — a theme attribute, a
21
+ * density class, a language direction. Omit it when the variant is a viewport alone.
22
+ */
23
+ readonly apply?: () => void;
24
+ }
25
+
26
+ /**
27
+ * Clicks one visible, focus-reachable control by its accessible name through the browser provider.
28
+ *
29
+ * @param name - The target's exact accessible name.
30
+ * @returns A promise resolving after trusted activation completes.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * await clickAccessible('Apply')
35
+ * ```
36
+ */
37
+ export declare function clickAccessible(name: string): Promise<void>;
38
+
39
+ /**
40
+ * Clicks one visible, focus-reachable control by its exact ARIA role and accessible name,
41
+ * disambiguating a bare name that answers for more than one rendered element.
42
+ *
43
+ * @param role - The control's exact ARIA role.
44
+ * @param name - The target's exact accessible name.
45
+ * @returns A promise resolving after trusted activation completes.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * await clickAccessible('tab', 'Drafts')
50
+ * ```
51
+ */
52
+ export declare function clickAccessible(role: string, name: string): Promise<void>;
53
+
54
+ /**
55
+ * Clicks one human-reachable control by role and accessible-name text inside a named region.
56
+ *
57
+ * @param region - The containing region's exact accessible name.
58
+ * @param role - The control's exact ARIA role.
59
+ * @param name - The rendered accessible-name text that identifies the control in that region.
60
+ * @returns A promise resolving after trusted activation completes.
61
+ * @throws When the named control is absent, unreachable, or ambiguous inside the region.
62
+ *
63
+ * @remarks
64
+ * Use this form when repeated short verbs such as `Add`, or a line whose status completes its
65
+ * accessible name, need the same region context a person uses to disambiguate them.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * await clickAccessibleWithin('Ledger', 'button', 'Monthly income')
70
+ * ```
71
+ */
72
+ export declare function clickAccessibleWithin(region: string, role: string, name: string): Promise<void>;
73
+
74
+ /**
75
+ * Opens or closes one native details disclosure by its rendered summary.
76
+ *
77
+ * @param name - The summary text a person reads.
78
+ * @returns A promise resolving after trusted activation completes.
79
+ * @throws When no visible, focus-reachable native summary has that rendered name, or several do.
80
+ *
81
+ * @remarks
82
+ * Chromium exposes `<summary>` as a native disclosure rather than through an ARIA role accepted by
83
+ * `getByRole`, so this resolver names the platform element and its rendered text directly.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * await clickDisclosure('Advanced')
88
+ * ```
89
+ */
90
+ export declare function clickDisclosure(name: string): Promise<void>;
91
+
92
+ /**
93
+ * Measures the WCAG 2.x contrast ratio between an element's computed text and background colors.
94
+ *
95
+ * @param element - The element whose rendered text contrast to measure.
96
+ * @returns The relative-luminance contrast ratio.
97
+ * @throws When the browser does not expose parseable computed colors.
98
+ *
99
+ * @remarks
100
+ * A transparent or translucent background resolves through the element's ancestors: every painted
101
+ * layer from the element up to the first opaque one composites top-over-bottom onto that opaque
102
+ * base, so a 3% surface tint reads as a tint over what shows through it rather than as a
103
+ * full-strength paint. A translucent foreground then resolves against that effective background
104
+ * before luminance is measured.
105
+ *
106
+ * Every element from the target upwards must be reachable, and at least one of them must paint:
107
+ * the measurement throws rather than assuming a white canvas when nothing in the chain declares a
108
+ * background color. The element itself must expose a computed foreground color — a detached
109
+ * element exposes none, and the measurement throws rather than guessing one.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * const container = render('<p style="background: #000; color: #fff">Ready</p>')
114
+ * contrast(requireValue(container.firstElementChild)) // 21
115
+ * ```
116
+ */
117
+ export declare function contrast(element: Element): number;
118
+
119
+ /**
120
+ * Creates the capture portfolio one run places its screenshots through.
121
+ *
122
+ * @param options - The state registry, the variant matrix, the variant this run renders, the
123
+ * directory it writes into, and whether it writes at all.
124
+ * @returns The portfolio: its registry expansion, what it has placed, and `place`.
125
+ * @throws When no registered variant carries the name `variant` names.
126
+ *
127
+ * @remarks
128
+ * A disabled portfolio is the ordinary run. `place` then resizes nothing, writes nothing, and
129
+ * records nothing, so a journey calls it unconditionally and a suite with the flag unset pays for
130
+ * none of it. The portfolio refuses an unregistered variant at creation. An enabled run refuses an
131
+ * unregistered state name and a second placement of one state.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * const portfolio = createPortfolio({
136
+ * states: ['start-empty'],
137
+ * variants: [{ name: 'dark-390', width: 390, height: 844 }],
138
+ * variant: 'dark-390',
139
+ * directory: '../../tmp/capture/states',
140
+ * })
141
+ * await portfolio.place('start-empty')
142
+ * ```
143
+ */
144
+ export declare function createPortfolio(options: PortfolioOptions): PortfolioInterface;
145
+
146
+ /**
147
+ * Expands a capture registry across every variant into the filenames a complete portfolio holds.
148
+ *
149
+ * @param states - The registered state names.
150
+ * @param variants - The variants the portfolio is rendered in.
151
+ * @returns One `<state>--<variant>.png` name per pair, each state's variants together, in registry
152
+ * order.
153
+ *
154
+ * @remarks
155
+ * The expansion is the portfolio's own definition of complete, so a duplicate in it is a registry
156
+ * defect a proof reads directly rather than a collision discovered on disk.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * expandCaptures(['start'], [{ name: 'dark-390', width: 390, height: 844 }])
161
+ * // ['start--dark-390.png']
162
+ * ```
163
+ */
164
+ export declare function expandCaptures(states: readonly string[], variants: readonly CaptureVariant[]): readonly string[];
165
+
166
+ /**
167
+ * Replaces a named field's value in one operation, for text too long to type key by key.
168
+ *
169
+ * @param name - The field's exact accessible name.
170
+ * @param text - The text to place in the field.
171
+ * @returns A promise resolving after the browser commits the value.
172
+ *
173
+ * @remarks
174
+ * The provider drives the real element, so the field publishes the same input event a person's
175
+ * typing publishes. Use {@link typeAccessible} wherever the keystrokes themselves are the subject.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * await fillAccessible('Payload', '{"status":"ready"}')
180
+ * ```
181
+ */
182
+ export declare function fillAccessible(name: string, text: string): Promise<void>;
183
+
184
+ /**
185
+ * Determines whether a rectangle lies wholly outside the browser viewport.
186
+ *
187
+ * @param rectangle - The measured client rectangle to inspect.
188
+ * @returns `true` when no part of the rectangle intersects the viewport.
189
+ *
190
+ * @example
191
+ * ```ts
192
+ * isOutsideViewport(element.getBoundingClientRect())
193
+ * ```
194
+ */
195
+ export declare function isOutsideViewport(rectangle: DOMRectReadOnly): boolean;
196
+
197
+ /** The registry of capture states one run places, and the files it wrote placing them. */
198
+ export declare interface PortfolioInterface {
199
+ /** The name of the variant this run renders. */
200
+ readonly variant: string;
201
+ /** Every state placed so far, in placement order. */
202
+ readonly states: readonly string[];
203
+ /** Every path written so far, in write order. */
204
+ readonly paths: readonly string[];
205
+ /** The registry expanded across every variant: the filenames a complete portfolio holds. */
206
+ readonly files: readonly string[];
207
+ /**
208
+ * Places one registered state: applies the variant, resizes the viewport, and writes the
209
+ * screenshot.
210
+ *
211
+ * @param state - The state name from the registry.
212
+ * @returns The written path, or `undefined` when the portfolio is not enabled.
213
+ * @throws When the state is not registered or has already been placed.
214
+ */
215
+ place(state: string): Promise<string | undefined>;
216
+ }
217
+
218
+ /** Options for a capture portfolio. */
219
+ export declare interface PortfolioOptions {
220
+ /**
221
+ * Every state name the journeys place, declared once. `place` refuses a name absent from this
222
+ * list, so the registry and the disk cannot drift apart.
223
+ */
224
+ readonly states: readonly string[];
225
+ /** Every variant the portfolio can be rendered in. One run renders exactly one of them. */
226
+ readonly variants: readonly CaptureVariant[];
227
+ /** The name of the variant this run renders. Creation throws when no variant carries it. */
228
+ readonly variant: string;
229
+ /** The directory each written file is placed in, relative to the calling test file. */
230
+ readonly directory: string;
231
+ /**
232
+ * Whether this run writes files. An ordinary run leaves it unset, so `place` resizes nothing,
233
+ * writes nothing, and records nothing.
234
+ */
235
+ readonly enabled?: boolean;
236
+ }
237
+
238
+ /**
239
+ * Presses a browser-keyboard sequence using Vitest's installed user-event syntax.
240
+ *
241
+ * @param keys - The keys or key descriptors to press.
242
+ * @returns A promise resolving after the sequence completes.
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * await pressKeys('{ArrowRight}{Enter}')
247
+ * ```
248
+ */
249
+ export declare function pressKeys(keys: string): Promise<void>;
250
+
251
+ /**
252
+ * Collects every class token the stylesheets loaded into this document actually define.
253
+ *
254
+ * @returns The set of class names reachable in the shipped cascade.
255
+ *
256
+ * @remarks
257
+ * The set is what an authored-class conformance check measures against, so a class no loaded
258
+ * stylesheet defines — an invented utility, a misspelled framework name — is absent from it.
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * readCascade().has('card')
263
+ * ```
264
+ */
265
+ export declare function readCascade(): ReadonlySet<string>;
266
+
267
+ /**
268
+ * Reads the rendered text of the element that currently holds focus.
269
+ *
270
+ * @returns The focused HTML element's trimmed rendered text, including an empty string, or
271
+ * `undefined` when focus rests on a non-HTML element. When nothing holds focus, the browser
272
+ * reports the document body as active, so the whole page's rendered text returns.
273
+ *
274
+ * @example
275
+ * ```ts
276
+ * await traverseAccessible('Evaluate')
277
+ * readFocus() // 'Evaluate'
278
+ * ```
279
+ */
280
+ export declare function readFocus(): string | undefined;
281
+
282
+ /**
283
+ * Reads the normalized visible text of the whole page.
284
+ *
285
+ * @returns Every rendered word in the document body, its whitespace runs collapsed and trimmed.
286
+ *
287
+ * @remarks
288
+ * This is the reader for a sentence that spans two regions and for a vocabulary sweep over the
289
+ * words an interface uses. Reach for {@link readPerception} wherever one named region is the
290
+ * subject, because that one throws when the region is missing and this one returns whatever is
291
+ * there.
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * readPage().includes('No cases yet')
296
+ * ```
297
+ */
298
+ export declare function readPage(): string;
299
+
300
+ /**
301
+ * Reads the normalized visible text of one named region, dialog, table, tab panel, or alert.
302
+ *
303
+ * @param name - The region's exact accessible name.
304
+ * @returns The text a screen reader can perceive in the visible region, including descendant
305
+ * visually-hidden content.
306
+ * @throws When the named region is absent, hidden, or ambiguous.
307
+ *
308
+ * @example
309
+ * ```ts
310
+ * readPerception('Run')
311
+ * ```
312
+ */
313
+ export declare function readPerception(name: string): string;
314
+
315
+ /**
316
+ * Reads the normalized visible text of every element a selector matches, in document order.
317
+ *
318
+ * @param root - The subtree to search.
319
+ * @param selector - The CSS selector naming the rows.
320
+ * @returns One line per matched element, its text runs collapsed and single-space joined.
321
+ *
322
+ * @remarks
323
+ * The line is built from the row's text nodes rather than from `textContent`, because adjacent
324
+ * inline elements carry no whitespace between them in compiled template output and would otherwise
325
+ * read as one run-together word.
326
+ *
327
+ * @example
328
+ * ```ts
329
+ * readRows(container, 'li')
330
+ * ```
331
+ */
332
+ export declare function readRows(root: ParentNode, selector: string): readonly string[];
333
+
334
+ /**
335
+ * Reads the value a resolved control renders.
336
+ *
337
+ * @param role - The control's exact ARIA role.
338
+ * @param name - The control's exact accessible name.
339
+ * @returns The control's current value.
340
+ * @throws When the target does not resolve, or resolves to an element that carries no value.
341
+ *
342
+ * @remarks
343
+ * A control's value is a rendered fact a person can read, not internal state, so it is read from
344
+ * the resolved element rather than from the component that produced it.
345
+ *
346
+ * @example
347
+ * ```ts
348
+ * readValue('spinbutton', 'Runs') // '3'
349
+ * ```
350
+ */
351
+ export declare function readValue(role: string, name: string): string;
352
+
353
+ /**
354
+ * Renders trusted fixture markup into a container attached to the document.
355
+ *
356
+ * @param markup - The fixture markup to render.
357
+ * @returns The attached container.
358
+ *
359
+ * @example
360
+ * ```ts
361
+ * const container = render('<button type="button">Save</button>')
362
+ * container.remove()
363
+ * ```
364
+ */
365
+ export declare function render(markup: string): HTMLDivElement;
366
+
367
+ /**
368
+ * Resolves one visible, focus-reachable interactive element by its exact accessible name. A
369
+ * wholly-off-viewport target is scrolled into view before reachability is measured.
370
+ *
371
+ * @param name - The accessible name rendered for the target.
372
+ * @returns The one reachable element carrying that name.
373
+ * @throws When no matching element exists; every match is disconnected, hidden, zero-sized, still
374
+ * outside the viewport after being scrolled into view, removed from sequential focus, disabled, or
375
+ * inside an inert subtree; or several reachable matches make the name ambiguous.
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * resolveAccessible('Save changes')
380
+ * ```
381
+ */
382
+ export declare function resolveAccessible(name: string): HTMLElement;
383
+
384
+ /**
385
+ * Resolves one visible, focus-reachable interactive element by its exact ARIA role and accessible
386
+ * name, disambiguating a bare name that answers for more than one rendered element. A
387
+ * wholly-off-viewport target is scrolled into view before reachability is measured.
388
+ *
389
+ * @param role - The element's exact ARIA role.
390
+ * @param name - The accessible name rendered for the target.
391
+ * @returns The one reachable element carrying that role and name.
392
+ * @throws When no matching element exists; every match is disconnected, hidden, zero-sized, still
393
+ * outside the viewport after being scrolled into view, removed from sequential focus, disabled, or
394
+ * inside an inert subtree; or several reachable matches make the role/name pair ambiguous.
395
+ *
396
+ * @example
397
+ * ```ts
398
+ * resolveAccessible('tab', 'Drafts')
399
+ * ```
400
+ */
401
+ export declare function resolveAccessible(role: string, name: string): HTMLElement;
402
+
403
+ /**
404
+ * Resolves one rendered, focus-reachable interactive element without requiring it to intersect the
405
+ * viewport yet.
406
+ *
407
+ * @param first - The accessible name, or the exact ARIA role when `second` is present.
408
+ * @param second - The accessible name when `first` supplies the role.
409
+ * @returns The one rendered element carrying that name and optional role.
410
+ * @throws When no matching element exists, every match is hidden or unreachable, or several
411
+ * rendered matches make the name ambiguous.
412
+ *
413
+ * @remarks
414
+ * This is the resolver the acting verbs use, so a click does not fail on a target the act itself
415
+ * scrolls into view. Use {@link resolveAccessible} wherever the target must already be on screen.
416
+ *
417
+ * @example
418
+ * ```ts
419
+ * resolveRendered('tab', 'Drafts')
420
+ * ```
421
+ */
422
+ export declare function resolveRendered(first: string, second?: string): HTMLElement;
423
+
424
+ /**
425
+ * Reads one resolved CSS property from a real browser element.
426
+ *
427
+ * @param element - The element whose resolved style to inspect.
428
+ * @param property - The CSS property name.
429
+ * @returns The browser's resolved property value.
430
+ *
431
+ * @example
432
+ * ```ts
433
+ * style(button, 'padding-left')
434
+ * ```
435
+ */
436
+ export declare function style(element: Element, property: string): string;
437
+
438
+ /**
439
+ * Reaches a named control only through natural forward Tab traversal from the current focus.
440
+ *
441
+ * @param name - The target's exact accessible name.
442
+ * @returns The target after the browser moves focus to it.
443
+ * @throws When one complete traversal cannot reach the target.
444
+ *
445
+ * @example
446
+ * ```ts
447
+ * await traverseAccessible('Evaluate')
448
+ * ```
449
+ */
450
+ export declare function traverseAccessible(name: string): Promise<HTMLElement>;
451
+
452
+ /**
453
+ * Replaces a named field's value through focus, select-all, deletion, and real keystrokes.
454
+ *
455
+ * @param name - The field's exact accessible name.
456
+ * @param text - The text to type.
457
+ * @returns A promise resolving after every keystroke completes.
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * await typeAccessible('Runs', '3')
462
+ * ```
463
+ */
464
+ export declare function typeAccessible(name: string, text: string): Promise<void>;
465
+
466
+ /**
467
+ * Waits for one animation frame to settle pending browser paint work.
468
+ *
469
+ * @returns A promise resolving after one `requestAnimationFrame`.
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * await waitForFrame()
474
+ * ```
475
+ */
476
+ export declare function waitForFrame(): Promise<void>;
477
+
478
+ export { }