@ultimat3/testing 31.25.0 → 31.27.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/CLAUDE.md +4 -0
- package/README.md +48 -1
- package/package.json +22 -22
- package/src/cdp-e2e-page.ts +112 -2
- package/src/declaration-boundary.ts +226 -0
- package/src/define-exercise-routes.ts +97 -0
- package/src/define-exercise.ts +24 -2
- package/src/drill-services.ts +6 -6
- package/src/e2e-driver.ts +8 -12
- package/src/e2e-page.ts +6 -6
- package/src/exercise-judge.ts +13 -2
- package/src/exercise-observed.ts +3 -0
- package/src/exercise-queued.ts +43 -0
- package/src/exercise-report.ts +17 -1
- package/src/exercise-route-loads.ts +55 -16
- package/src/exercise-route-override.ts +105 -0
- package/src/exercise-shard.ts +13 -0
- package/src/exercise.ts +23 -50
- package/src/factory-persist.ts +3 -0
- package/src/fixture-island-coverage.ts +26 -0
- package/src/fixture-island.ts +27 -2
- package/src/framework-fixtures.ts +7 -1
- package/src/index.ts +5 -2
- package/src/registry-leak-guard.ts +12 -0
- package/src/scrape-driver-conformance-frame-checks.ts +1 -7
- package/src/scrape-driver-conformance-page-checks.ts +2 -6
- package/src/test-types-services.ts +36 -0
- package/src/test-types.ts +20 -0
package/src/exercise.ts
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|
import type { Actor, ExerciseAttempt, ExerciseVerdict } from '@ultimat3/core';
|
|
14
14
|
import { runExercise, subscribe } from '@ultimat3/core';
|
|
15
|
-
import { LIVE_STATES, registeredJobs } from '@ultimat3/jobs';
|
|
16
15
|
import type { ExerciseOverride, ExerciseOverrides } from './define-exercise';
|
|
17
16
|
import { assertOverridesKnown, overrideFor, unknownDeclaration } from './define-exercise';
|
|
17
|
+
import { assertRoutesKnown } from './define-exercise-routes';
|
|
18
18
|
import type { RoleGrants } from './exercise-actor';
|
|
19
19
|
import { chooseActor } from './exercise-actor';
|
|
20
20
|
import { seatActorUsers } from './exercise-actor-user';
|
|
@@ -22,20 +22,13 @@ import { proveCrash } from './exercise-crash';
|
|
|
22
22
|
import { defectDetail } from './exercise-defect';
|
|
23
23
|
import type { IdLookup, Sampler } from './exercise-input';
|
|
24
24
|
import { bindIds, drawInput, loadSampler, namesActorEntity, seededIds } from './exercise-input';
|
|
25
|
-
import {
|
|
26
|
-
import { judged, labelFor } from './exercise-judge';
|
|
25
|
+
import { judged, labelFor, withEmptyWhy } from './exercise-judge';
|
|
27
26
|
import { mergeObserved } from './exercise-observed';
|
|
28
27
|
import type { OverrideInput } from './exercise-override-input';
|
|
29
28
|
import { inputThrew, overrideInput } from './exercise-override-input';
|
|
30
29
|
import { actorHintOf, type OverrideHint, seededIn } from './exercise-override-line';
|
|
31
|
-
import
|
|
32
|
-
|
|
33
|
-
ExerciseEffect,
|
|
34
|
-
ExercisePhaseMs,
|
|
35
|
-
ExerciseRecord,
|
|
36
|
-
ExerciseRoom,
|
|
37
|
-
Observed,
|
|
38
|
-
} from './exercise-report';
|
|
30
|
+
import { enqueued, queuedIds, queuedPayloads } from './exercise-queued';
|
|
31
|
+
import type { ExercisePhaseMs, ExerciseRecord, ExerciseRoom, Observed } from './exercise-report';
|
|
39
32
|
import { openExerciseRoom } from './exercise-report';
|
|
40
33
|
import type { RouteLoadRecord } from './exercise-route-loads';
|
|
41
34
|
import {
|
|
@@ -47,6 +40,8 @@ import {
|
|
|
47
40
|
} from './exercise-route-loads';
|
|
48
41
|
import type { RouteLoadSubject } from './exercise-route-subjects';
|
|
49
42
|
import { withExerciseSetup } from './exercise-setup';
|
|
43
|
+
import type { ExerciseShard } from './exercise-shard';
|
|
44
|
+
import { inShard } from './exercise-shard';
|
|
50
45
|
import type { ExerciseStatementCeiling } from './exercise-statement-ceiling';
|
|
51
46
|
import { judgeStatementCeiling } from './exercise-statement-ceiling';
|
|
52
47
|
import type { Subject } from './exercise-subjects';
|
|
@@ -88,6 +83,8 @@ export interface ExercisePassOptions {
|
|
|
88
83
|
readonly routes?: readonly RouteLoadSubject[];
|
|
89
84
|
/** Told once, as the pass returns: each route load's record, the sweeps' proofs on it. */
|
|
90
85
|
readonly onRoutes?: (records: readonly RouteLoadRecord[]) => void;
|
|
86
|
+
/** One of n slices of the whole pass (`exercise-shard.ts`); ignored beside `only`. */
|
|
87
|
+
readonly shard?: ExerciseShard;
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
const isOff = (overrides: ExerciseOverrides | undefined, subject: Subject): boolean => {
|
|
@@ -95,42 +92,6 @@ const isOff = (overrides: ExerciseOverrides | undefined, subject: Subject): bool
|
|
|
95
92
|
return override !== undefined && 'off' in override;
|
|
96
93
|
};
|
|
97
94
|
|
|
98
|
-
/** The ids of every row the call's queue holds now: what an attempt adds is the call's. */
|
|
99
|
-
const queuedIds = async (): Promise<ReadonlySet<string>> =>
|
|
100
|
-
new Set((await ambientJobRows()).map((record) => record.id));
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Jobs the primitive queued — rows an ATTEMPT added (`mine`), still live — its own job excepted.
|
|
104
|
-
* Never run: a job's children are left queued as an action's are (`exercise-job-run.ts`). A row
|
|
105
|
-
* the override's input added between calls is on the same queue, so the call can find it, and is
|
|
106
|
-
* not in `mine`: the input's enqueue is never the primitive's.
|
|
107
|
-
*/
|
|
108
|
-
async function enqueued(subject: Subject, mine: ReadonlySet<string>) {
|
|
109
|
-
const counts = new Map<string, number>();
|
|
110
|
-
for (const record of await ambientJobRows()) {
|
|
111
|
-
if (!mine.has(record.id) || !LIVE_STATES.has(record.state)) continue;
|
|
112
|
-
if (subject.kind === 'job' && record.name === subject.name) continue;
|
|
113
|
-
counts.set(record.name, (counts.get(record.name) ?? 0) + 1);
|
|
114
|
-
}
|
|
115
|
-
const order = registeredJobs().map((handle) => handle.name);
|
|
116
|
-
return [...counts]
|
|
117
|
-
.sort(([a], [b]) => order.indexOf(a) - order.indexOf(b))
|
|
118
|
-
.map(([job, count]): ExerciseEffect => ({ kind: 'enqueue', job, count }));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Every job a B leg's queue holds or ran, with its input — the subject's own job excepted, whose
|
|
123
|
-
* input is what B was handed. Read off the leg's own queue, page by page.
|
|
124
|
-
*/
|
|
125
|
-
async function queuedPayloads(subject: Subject): Promise<readonly EffectPayload[]> {
|
|
126
|
-
return (await ambientJobRows())
|
|
127
|
-
.filter((record) => !(subject.kind === 'job' && record.name === subject.name))
|
|
128
|
-
.map((record, i) => ({
|
|
129
|
-
path: `effect.enqueue[${i}]`,
|
|
130
|
-
value: { job: record.name, input: record.input },
|
|
131
|
-
}));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
95
|
/** Everything one primitive's calls share: who acts in each tenant, and how ids are bound. */
|
|
135
96
|
interface Prepared {
|
|
136
97
|
readonly subject: Subject;
|
|
@@ -403,18 +364,30 @@ export async function runExercisePass(
|
|
|
403
364
|
});
|
|
404
365
|
const known = new Set(subjects.map((subject) => subject.name));
|
|
405
366
|
assertOverridesKnown(options.overrides, subjects);
|
|
367
|
+
// Judged only where the route table was handed over: an `only` run never reads one.
|
|
368
|
+
if (options.routes !== undefined && options.only === undefined) {
|
|
369
|
+
assertRoutesKnown(
|
|
370
|
+
options.overrides,
|
|
371
|
+
options.routes.map((route) => route.path),
|
|
372
|
+
);
|
|
373
|
+
}
|
|
406
374
|
const label = labelFor(subjects);
|
|
407
375
|
if (options.only !== undefined && !known.has(options.only)) {
|
|
408
376
|
throw unknownDeclaration([options.only], known, 'x exercise');
|
|
409
377
|
}
|
|
410
|
-
const
|
|
378
|
+
const shard = options.only === undefined ? options.shard : undefined;
|
|
379
|
+
const chosen = subjects.filter((s, i) =>
|
|
380
|
+
options.only === undefined ? inShard(i, shard) : s.name === options.only,
|
|
381
|
+
);
|
|
411
382
|
const sampler = await loadSampler();
|
|
412
383
|
// Not `Math.random`: the frozen RNG answers the same sequence in every process.
|
|
413
384
|
const passSeed = options.seed ?? (crypto.getRandomValues(new Uint32Array(1))[0] as number);
|
|
414
385
|
// The app's setup runs inside the seal, before the first row: its routes answer every call.
|
|
415
386
|
const room = await withExerciseSetup(await openExerciseRoom(), options.overrides?.setup);
|
|
416
387
|
const live = chosen.filter((subject) => !isOff(options.overrides, subject));
|
|
417
|
-
const routes = options.only === undefined ? (options.routes ?? []) : []
|
|
388
|
+
const routes = (options.only === undefined ? (options.routes ?? []) : []).filter((_, i) =>
|
|
389
|
+
inShard(subjects.length + i, shard),
|
|
390
|
+
);
|
|
418
391
|
const records: ExerciseRecord[] = [];
|
|
419
392
|
let routeRecords: readonly RouteLoadRecord[] = [];
|
|
420
393
|
let graph: SeedGraph;
|
|
@@ -481,5 +454,5 @@ export async function runExercisePass(
|
|
|
481
454
|
options.onPhases?.({ seed, primitives, ...swept.ms });
|
|
482
455
|
const split = splitRouteRecords(swept.records);
|
|
483
456
|
options.onRoutes?.(split.routes);
|
|
484
|
-
return split.primitives;
|
|
457
|
+
return split.primitives.map((record) => withEmptyWhy(record, options.overrides));
|
|
485
458
|
}
|
package/src/factory-persist.ts
CHANGED
|
@@ -34,6 +34,9 @@ export function clearPersister(): void {
|
|
|
34
34
|
|
|
35
35
|
export const persisterInstalled = (): boolean => current !== undefined;
|
|
36
36
|
|
|
37
|
+
/** The installed persister itself: what the registry guard's file boundary hands back. */
|
|
38
|
+
export const installedPersister = (): Persister | undefined => current;
|
|
39
|
+
|
|
37
40
|
/** Install for one run and hand back what was there: the factory lint's own throwaway writer. */
|
|
38
41
|
export function swapPersister(next: Persister | undefined): Persister | undefined {
|
|
39
42
|
const previous = current;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// What `mountIsland` leaves behind for coverage: each chunk's source map, written where the
|
|
2
|
+
// coverage run asked, under the file name the chunk was imported by. The run (`@ultimat3/cli`'s
|
|
3
|
+
// `coverage-island.ts`) reads them and credits the chunk's lines to the island's own source.
|
|
4
|
+
|
|
5
|
+
// why: Bun ships no path-join primitive.
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
/** Set by `x verify`'s coverage run (`@ultimat3/cli`'s `runCovered`) to a directory per process. */
|
|
9
|
+
export const ISLAND_COVERAGE_ENV = 'ULTIMATE_ISLAND_COVERAGE_DIR';
|
|
10
|
+
|
|
11
|
+
/** The directory to record into, or nothing outside a coverage run. */
|
|
12
|
+
export const islandCoverageDir = (
|
|
13
|
+
env: Readonly<Record<string, string | undefined>> = Bun.env,
|
|
14
|
+
): string | undefined => {
|
|
15
|
+
const dir = env[ISLAND_COVERAGE_ENV];
|
|
16
|
+
return dir === undefined || dir === '' ? undefined : dir;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* One chunk's map, as `{ module, cwd, map }`. The map is kept as the builder's text: its `sources`
|
|
21
|
+
* are relative to THIS process's cwd (Bun's convention), which is why the cwd rides beside it.
|
|
22
|
+
* Named by the module, so a second mount of the same bytes rewrites the same file.
|
|
23
|
+
*/
|
|
24
|
+
export async function recordChunkMap(dir: string, module: string, map: string): Promise<void> {
|
|
25
|
+
await Bun.write(join(dir, `${module}.json`), JSON.stringify({ module, cwd: process.cwd(), map }));
|
|
26
|
+
}
|
package/src/fixture-island.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { basename, join } from 'node:path';
|
|
7
7
|
import { onFileBoundary } from './file-boundary';
|
|
8
|
+
import { islandCoverageDir, recordChunkMap } from './fixture-island-coverage';
|
|
8
9
|
import { createIslandDocument, FakeElement, handlerFor, parseHtml } from './island-dom';
|
|
9
10
|
import { islandMountMissing, islandNotBuilt } from './island-errors';
|
|
10
11
|
import { installGlobals } from './island-globals';
|
|
@@ -22,12 +23,19 @@ export interface IslandChunkLike {
|
|
|
22
23
|
* is why `shared` below is written beside it before it is imported.
|
|
23
24
|
*/
|
|
24
25
|
readonly code: string;
|
|
26
|
+
/**
|
|
27
|
+
* The chunk's external source map, as text. Optional: under a coverage run the fixture records
|
|
28
|
+
* it (`fixture-island-coverage.ts`) so the chunk's lines count for the island's own source.
|
|
29
|
+
*/
|
|
30
|
+
readonly map?: string;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
/** A module two or more islands import, served beside them under its own name. */
|
|
28
34
|
export interface SharedChunkLike {
|
|
29
35
|
readonly url: string;
|
|
30
36
|
readonly code: string;
|
|
37
|
+
/** Its source map, recorded the same way as an entry's. */
|
|
38
|
+
readonly map?: string;
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
export interface IslandBundleLike {
|
|
@@ -46,7 +54,14 @@ export interface IslandBundleLike {
|
|
|
46
54
|
*/
|
|
47
55
|
export type IslandBuilder = (
|
|
48
56
|
root: string,
|
|
49
|
-
options?: {
|
|
57
|
+
options?: {
|
|
58
|
+
readonly only?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Asked only under a coverage run: a build whose lines a map can name — whitespace kept, a
|
|
61
|
+
* map on every chunk. A builder that ignores it still mounts; its chunk just credits nothing.
|
|
62
|
+
*/
|
|
63
|
+
readonly coverage?: boolean;
|
|
64
|
+
},
|
|
50
65
|
) => Promise<IslandBundleLike>;
|
|
51
66
|
|
|
52
67
|
export interface MountIslandOptions {
|
|
@@ -201,7 +216,11 @@ export async function mountIsland(options: MountIslandOptions): Promise<MountedI
|
|
|
201
216
|
// `bun test`, fixed in 1.4.0, and asking for the island we actually want walks around it while
|
|
202
217
|
// being the faster and more honest call regardless. A builder that ignores the argument still
|
|
203
218
|
// works: the `find` below is unchanged.
|
|
204
|
-
const
|
|
219
|
+
const coverage = islandCoverageDir();
|
|
220
|
+
const bundle = await options.build(options.root, {
|
|
221
|
+
only: options.file,
|
|
222
|
+
...(coverage === undefined ? {} : { coverage: true }),
|
|
223
|
+
});
|
|
205
224
|
const chunk = bundle.chunks.find((each) => each.file === options.file);
|
|
206
225
|
if (chunk === undefined) {
|
|
207
226
|
throw islandNotBuilt(
|
|
@@ -240,9 +259,15 @@ export async function mountIsland(options: MountIslandOptions): Promise<MountedI
|
|
|
240
259
|
// bytes at the same name.
|
|
241
260
|
for (const shared of bundle.shared ?? []) {
|
|
242
261
|
await Bun.write(join(scratch, basename(shared.url)), shared.code);
|
|
262
|
+
if (coverage !== undefined && shared.map !== undefined) {
|
|
263
|
+
await recordChunkMap(coverage, basename(shared.url), shared.map);
|
|
264
|
+
}
|
|
243
265
|
}
|
|
244
266
|
const path = modulePathFor(scratch, chunk.code);
|
|
245
267
|
await Bun.write(path, chunk.code);
|
|
268
|
+
if (coverage !== undefined && chunk.map !== undefined) {
|
|
269
|
+
await recordChunkMap(coverage, basename(path), chunk.map);
|
|
270
|
+
}
|
|
246
271
|
// By `file:` URL, never the bare path: Bun on macOS caches a directory's entries on its first
|
|
247
272
|
// resolution, and a bare-path import of a file written there afterwards is "Cannot find module"
|
|
248
273
|
// (#704, Bun 1.4.0 arm64). The per-mount directory already avoids it; the URL form holds even
|
|
@@ -60,6 +60,12 @@ export function registerFrameworkFixtures(): void {
|
|
|
60
60
|
// After the spread, so it REPLACES the `unavailableFixture('subscribe')` declaration above it —
|
|
61
61
|
// `defineFixtures` merges and the last registration wins, which is the same seam an app's own
|
|
62
62
|
// driver uses.
|
|
63
|
-
|
|
63
|
+
// The function, carrying the driver's `stop` as its disposer: handing back `.subscribe` alone
|
|
64
|
+
// dropped it, so the replicator's `entity.row` subscription outlived the test into every later
|
|
65
|
+
// file — where each `countedIn` write read its parents back as one more statement.
|
|
66
|
+
subscribe: async () => {
|
|
67
|
+
const driver = await subscribeDriver();
|
|
68
|
+
return Object.assign(driver.subscribe, { [Symbol.asyncDispose]: driver.stop });
|
|
69
|
+
},
|
|
64
70
|
});
|
|
65
71
|
}
|
package/src/index.ts
CHANGED
|
@@ -45,8 +45,8 @@ export {
|
|
|
45
45
|
} from './cdp-browser';
|
|
46
46
|
export type { E2eBrowserLease, RunEndHook } from './cdp-browser-lease';
|
|
47
47
|
export { closeE2eBrowsersAtRunEnd, leaseE2eBrowser } from './cdp-browser-lease';
|
|
48
|
-
export type { CdpE2eTabOptions, E2eTab } from './cdp-e2e-page';
|
|
49
|
-
export { cdpE2eTab } from './cdp-e2e-page';
|
|
48
|
+
export type { CdpE2eTabOptions, E2eTab, TouchPoint } from './cdp-e2e-page';
|
|
49
|
+
export { cdpE2eTab, PRESS_KEYS } from './cdp-e2e-page';
|
|
50
50
|
export type { CdpE2eSessionOptions, E2eSession } from './cdp-e2e-session';
|
|
51
51
|
export { cdpE2eSession } from './cdp-e2e-session';
|
|
52
52
|
// The exercise pass (plan 101 / 40, phase 2): an app's per-primitive overrides — 39's
|
|
@@ -248,6 +248,7 @@ export type {
|
|
|
248
248
|
SharedChunkLike,
|
|
249
249
|
} from './fixture-island';
|
|
250
250
|
export { mountIsland } from './fixture-island';
|
|
251
|
+
export { ISLAND_COVERAGE_ENV } from './fixture-island-coverage';
|
|
251
252
|
export type {
|
|
252
253
|
JobDrainAs,
|
|
253
254
|
JobEnqueueAs,
|
|
@@ -487,3 +488,5 @@ export {
|
|
|
487
488
|
unitTest,
|
|
488
489
|
useE2eDriver,
|
|
489
490
|
} from './test-types';
|
|
491
|
+
export type { TestService } from './test-types-services';
|
|
492
|
+
export { TEST_SERVICE_ENV, TEST_SERVICES_START } from './test-types-services';
|
|
@@ -8,8 +8,10 @@ import { knownTags, registeredTiers } from '@ultimat3/cache';
|
|
|
8
8
|
import { configureLocales } from '@ultimat3/i18n';
|
|
9
9
|
import { captureAdminMounts, restoreAdminMounts } from './admin-mount-boundary';
|
|
10
10
|
import { isAppRoot } from './app-root';
|
|
11
|
+
import { captureDeclarationTables, restoreDeclarationTables } from './declaration-boundary';
|
|
11
12
|
import { captureDriverStores, restoreDriverStores } from './driver-store-boundary';
|
|
12
13
|
import { RegistryLeakError } from './errors';
|
|
14
|
+
import { installedPersister, swapPersister } from './factory-persist';
|
|
13
15
|
import { runBoundaryHooks, runFileBoundary } from './file-boundary';
|
|
14
16
|
import { type ImportGraph, importGraphReader } from './import-graph';
|
|
15
17
|
import { ownEnvironment } from './registry-environment';
|
|
@@ -167,6 +169,8 @@ export function installRegistryLeakGuard(): void {
|
|
|
167
169
|
before: RegistrySample | undefined;
|
|
168
170
|
readonly snapshot: ProcessRegistrySnapshot;
|
|
169
171
|
readonly admins: ReturnType<typeof captureAdminMounts>;
|
|
172
|
+
readonly tables: ReturnType<typeof captureDeclarationTables>;
|
|
173
|
+
readonly persister: ReturnType<typeof installedPersister>;
|
|
170
174
|
}
|
|
171
175
|
| undefined;
|
|
172
176
|
const leaks: RegistryLeak[] = [];
|
|
@@ -232,6 +236,12 @@ export function installRegistryLeakGuard(): void {
|
|
|
232
236
|
// whose drift step then read its fixture app as "a store that owns its own schema".
|
|
233
237
|
restoreDriverStores(preloadStores);
|
|
234
238
|
restoreAdminMounts(current.admins);
|
|
239
|
+
// The framework repository's own suites only: in an app these tables hold what `loadApp()`
|
|
240
|
+
// registered once for the worker's life (routes, the authenticator, storage, channels), and a
|
|
241
|
+
// module the cache will not evaluate again cannot put them back for the next file.
|
|
242
|
+
if (!inApp) restoreDeclarationTables(current.tables);
|
|
243
|
+
// A preload's `usePersister` is in every body's start; a file's own `factoryWorld()` is not.
|
|
244
|
+
swapPersister(current.persister);
|
|
235
245
|
accumulated = mergeSnapshots(accumulated, restored);
|
|
236
246
|
lastBoundary = restored;
|
|
237
247
|
current = undefined;
|
|
@@ -281,6 +291,8 @@ export function installRegistryLeakGuard(): void {
|
|
|
281
291
|
before: undefined,
|
|
282
292
|
snapshot: narrowed(live, accumulated),
|
|
283
293
|
admins: captureAdminMounts(),
|
|
294
|
+
tables: captureDeclarationTables(),
|
|
295
|
+
persister: installedPersister(),
|
|
284
296
|
};
|
|
285
297
|
pending = undefined;
|
|
286
298
|
};
|
|
@@ -75,7 +75,7 @@ export const SCRAPE_FRAME_CHECKS: readonly ScrapeDriverCheck[] = [
|
|
|
75
75
|
},
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
|
-
name: 'accessibility() answers the computed role and name,
|
|
78
|
+
name: 'accessibility() answers the computed role and name, on every driver',
|
|
79
79
|
async run({ page }) {
|
|
80
80
|
await page.goto(SCRAPE_CONFORMANCE_URLS.search);
|
|
81
81
|
// Screened before any driver is asked, whichever kind this is.
|
|
@@ -83,12 +83,6 @@ export const SCRAPE_FRAME_CHECKS: readonly ScrapeDriverCheck[] = [
|
|
|
83
83
|
'X_INVARIANT',
|
|
84
84
|
);
|
|
85
85
|
expect(await codeOf(() => page.accessibility('#go', { max: 0 }))).toBe('X_INVARIANT');
|
|
86
|
-
const refused = await codeOf(() => page.accessibility('#go'));
|
|
87
|
-
if (refused !== undefined) {
|
|
88
|
-
// An offline driver refuses rather than reading `role=` off the markup and inventing one.
|
|
89
|
-
expect(refused).toBe('X_NOT_IMPLEMENTED');
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
86
|
expect(await page.accessibility('#go')).toMatchObject([
|
|
93
87
|
{ role: 'button', name: 'Run search' },
|
|
94
88
|
]);
|
|
@@ -98,14 +98,10 @@ export const SCRAPE_PAGE_CHECKS: readonly ScrapeDriverCheck[] = [
|
|
|
98
98
|
},
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
|
-
name: 'offline(true) cuts the browser off
|
|
101
|
+
name: 'offline(true) cuts the browser off — answered by every driver, never a no-op',
|
|
102
102
|
async run({ page }) {
|
|
103
103
|
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
104
|
-
|
|
105
|
-
if (refused !== undefined) {
|
|
106
|
-
expect(refused).toBe('X_NOT_IMPLEMENTED');
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
104
|
+
expect(await codeOf(() => page.offline(true))).toBeUndefined();
|
|
109
105
|
// Set: then the browser must actually fail a navigation, or a test proved nothing offline.
|
|
110
106
|
expect(await codeOf(() => page.goto(SCRAPE_CONFORMANCE_URLS.second))).not.toBeUndefined();
|
|
111
107
|
await page.offline(false);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// What a typed test may declare it needs from a real server, and how that need is answered: the
|
|
2
|
+
// `TEST_*_URL` variable `docker/test-services.env` writes for each service. Set, the test runs;
|
|
3
|
+
// unset, it is skipped with the service and the command that starts it in its own reported name.
|
|
4
|
+
|
|
5
|
+
/** The services a test may declare, each under the variable the test services publish it as. */
|
|
6
|
+
export const TEST_SERVICE_ENV = {
|
|
7
|
+
postgres: 'TEST_DATABASE_URL',
|
|
8
|
+
redis: 'TEST_REDIS_URL',
|
|
9
|
+
nats: 'TEST_NATS_URL',
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
export type TestService = keyof typeof TEST_SERVICE_ENV;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The lines that start every service and point this shell at them — the same two the generated
|
|
16
|
+
* `docker/docker-compose.test.yml` header names, so a skipped test's reason is a paste, not a hunt.
|
|
17
|
+
*/
|
|
18
|
+
export const TEST_SERVICES_START =
|
|
19
|
+
'docker compose -f docker/docker-compose.test.yml up -d --wait && set -a && . docker/test-services.env && set +a';
|
|
20
|
+
|
|
21
|
+
type Env = Readonly<Record<string, string | undefined>>;
|
|
22
|
+
|
|
23
|
+
/** The declared services whose variable is unset or blank in `env`, in declared order. */
|
|
24
|
+
export const missingServices = (needs: readonly TestService[], env: Env): readonly TestService[] =>
|
|
25
|
+
needs.filter((service) => (env[TEST_SERVICE_ENV[service]]?.trim() ?? '') === '');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The suffix a skipped test's name carries: each missing service, the variable it is read from,
|
|
29
|
+
* and the command that starts them. `undefined` when nothing is missing — the test runs.
|
|
30
|
+
*/
|
|
31
|
+
export function serviceSkipReason(needs: readonly TestService[], env: Env): string | undefined {
|
|
32
|
+
const missing = missingServices(needs, env);
|
|
33
|
+
if (missing.length === 0) return undefined;
|
|
34
|
+
const named = missing.map((service) => `${service} (${TEST_SERVICE_ENV[service]})`).join(', ');
|
|
35
|
+
return `needs ${named} unset: ${TEST_SERVICES_START}`;
|
|
36
|
+
}
|
package/src/test-types.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { TestEvalThresholdError } from './errors';
|
|
|
8
8
|
import type { FixtureBody } from './fixtures';
|
|
9
9
|
import { runWithFixtures } from './fixtures';
|
|
10
10
|
import { paced } from './test-pace';
|
|
11
|
+
import type { TestService } from './test-types-services';
|
|
12
|
+
import { serviceSkipReason } from './test-types-services';
|
|
11
13
|
|
|
12
14
|
export const TEST_TYPES = ['unit', 'contract', 'live', 'job', 'e2e', 'eval'] as const;
|
|
13
15
|
|
|
@@ -28,8 +30,23 @@ export interface TestOptions {
|
|
|
28
30
|
* (`paced`). Absent is the run's default, which `x verify` paces the same way.
|
|
29
31
|
*/
|
|
30
32
|
readonly timeoutMs?: number;
|
|
33
|
+
/**
|
|
34
|
+
* The real servers this test needs, by name (`TEST_SERVICE_ENV`: `postgres` is
|
|
35
|
+
* `TEST_DATABASE_URL`). Every one set, the test runs; one unset, it is SKIPPED with the service,
|
|
36
|
+
* its variable and the command that starts it in its reported name — the declaration a live
|
|
37
|
+
* suite's `describe.skipIf(!Bun.env.TEST_DATABASE_URL)` spelled by hand, on every registrar.
|
|
38
|
+
*/
|
|
39
|
+
readonly needs?: readonly TestService[];
|
|
31
40
|
}
|
|
32
41
|
|
|
42
|
+
/** The skip a test whose declared services are unset becomes, or `false` when it may run. */
|
|
43
|
+
const skippedFor = (type: TestType, name: string, options: TestOptions | undefined): boolean => {
|
|
44
|
+
const reason = serviceSkipReason(options?.needs ?? [], Bun.env);
|
|
45
|
+
if (reason === undefined) return false;
|
|
46
|
+
test.skip(testName(type, `${name} (${reason})`), () => undefined);
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
|
|
33
50
|
/**
|
|
34
51
|
* One typed registrar. The body is `test`'s own (`FixtureBody`): it is handed the fixture bag and
|
|
35
52
|
* only what it destructures is built, so `unitTest('…', async ({ runJobs }) => …)` is a job body
|
|
@@ -39,6 +56,7 @@ export interface TestOptions {
|
|
|
39
56
|
const typed =
|
|
40
57
|
(type: TestType) =>
|
|
41
58
|
(name: string, body: FixtureBody, options?: TestOptions): void => {
|
|
59
|
+
if (skippedFor(type, name, options)) return;
|
|
42
60
|
test(
|
|
43
61
|
testName(type, name),
|
|
44
62
|
() => runWithFixtures(body),
|
|
@@ -162,6 +180,7 @@ export const resetE2eDriver = (): void => {
|
|
|
162
180
|
};
|
|
163
181
|
|
|
164
182
|
export const e2eTest = (name: string, body: E2eBody, options?: E2eTestOptions): void => {
|
|
183
|
+
if (skippedFor('e2e', name, options)) return;
|
|
165
184
|
if (e2eDriver === undefined) {
|
|
166
185
|
test.skip(
|
|
167
186
|
testName('e2e', `${name} (no browser driver: x build --target static && x e2e)`),
|
|
@@ -193,6 +212,7 @@ export function evalTest<TInput, TOutput>(
|
|
|
193
212
|
name: string,
|
|
194
213
|
options: EvalOptions<TInput, TOutput>,
|
|
195
214
|
): void {
|
|
215
|
+
if (skippedFor('eval', name, options)) return;
|
|
196
216
|
test(
|
|
197
217
|
testName('eval', name),
|
|
198
218
|
async () => {
|