@ultimat3/testing 31.48.0 → 31.50.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/README.md +9 -4
- package/package.json +22 -22
- package/src/app-assets.ts +20 -0
- package/src/auth-adapter-conformance-passkeys.ts +24 -1
- package/src/auth-server-store-conformance-records.ts +13 -0
- package/src/auth-server-store-conformance.ts +118 -0
- package/src/cdp-console-capture.ts +112 -0
- package/src/cdp-e2e-context.ts +33 -0
- package/src/cdp-e2e-page.ts +18 -60
- package/src/cdp-e2e-session.ts +49 -33
- package/src/cdp-e2e-webauthn.ts +91 -0
- package/src/cdp-key-press.ts +108 -0
- package/src/cdp-ports.ts +55 -0
- package/src/drill-errors.ts +37 -2
- package/src/drill-fleet.ts +41 -25
- package/src/drill-scratch-db.ts +125 -0
- package/src/e2e-console.ts +16 -0
- package/src/e2e-driver.ts +8 -1
- package/src/e2e-error-codes.ts +4 -2
- package/src/e2e-errors.ts +15 -0
- package/src/e2e-page-input.ts +80 -0
- package/src/e2e-page.ts +18 -1
- package/src/entity-conformance-aggregates.ts +44 -2
- package/src/entity-conformance-update-many.ts +25 -0
- package/src/errors.ts +2 -0
- package/src/html-entities.ts +134 -0
- package/src/index.ts +16 -1
- package/src/isolated-plugins.ts +20 -8
- package/src/matcher-receiver-errors.ts +20 -9
- package/src/matchers.ts +4 -0
- package/src/meter-store-conformance.ts +163 -3
- package/src/per-test-reset.ts +13 -6
- package/src/plan-sweep-fix.ts +13 -5
- package/src/plan-sweep.ts +2 -2
- package/src/preload.ts +8 -1
- package/src/render-view.ts +70 -18
package/src/e2e-driver.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { A11yOptions, A11yRun } from './e2e-a11y-run';
|
|
|
7
7
|
import { checkAllow, startA11yRun } from './e2e-a11y-run';
|
|
8
8
|
import type { E2eBrowserPage, E2ePageOptions } from './e2e-page';
|
|
9
9
|
import { e2ePage } from './e2e-page';
|
|
10
|
+
import { markConsoleStart } from './e2e-page-input';
|
|
10
11
|
import { FixtureUnavailableError } from './errors';
|
|
11
12
|
import { withFailureContext } from './failure-context';
|
|
12
13
|
import { unavailableFixture } from './fixture-drivers';
|
|
@@ -99,6 +100,8 @@ export function e2eRunner(options: E2eDriverOptions): E2eRunner {
|
|
|
99
100
|
try {
|
|
100
101
|
const current = startA11yRun(options.page, checkAllow(a11y), reported);
|
|
101
102
|
audit = current;
|
|
103
|
+
// The console a test reads begins with the test: a tab shared by the suite carries the last one's.
|
|
104
|
+
await markConsoleStart(page);
|
|
102
105
|
await body(e2eFixtures(page, options.page, options.newBuild));
|
|
103
106
|
await current.check();
|
|
104
107
|
current.verdict();
|
|
@@ -132,7 +135,11 @@ export function installE2eDriver(options: E2eDriverOptions): () => void {
|
|
|
132
135
|
const { page, run } = e2eRunner(options);
|
|
133
136
|
const newBuild = options.newBuild;
|
|
134
137
|
defineFixtures({
|
|
135
|
-
|
|
138
|
+
// Built once per test: the plain `{ page }` fixture's console begins with its test too.
|
|
139
|
+
page: async () => {
|
|
140
|
+
await markConsoleStart(page);
|
|
141
|
+
return page;
|
|
142
|
+
},
|
|
136
143
|
...(newBuild === undefined ? {} : { deploy: () => ({ newBuild }) }),
|
|
137
144
|
});
|
|
138
145
|
useE2eDriver((name, body: E2eBody, test) => {
|
package/src/e2e-error-codes.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The registry for the browser-backed e2e driver's codes: the
|
|
1
|
+
// The registry for the browser-backed e2e driver's codes: the eight `X_E2E_*` a page refuses with,
|
|
2
2
|
// registered here (not in `errors.ts`, which sits at its ceiling). The four `X_CDP_*` its raw-CDP
|
|
3
3
|
// browser refuses with are `@ultimat3/scraping/cdp`'s since 31.0.0 — listed here, registered there.
|
|
4
4
|
import { registerErrorCodes } from '@ultimat3/core';
|
|
@@ -12,11 +12,12 @@ const OWN_E2E_CODES = [
|
|
|
12
12
|
'X_E2E_LOCATOR_AMBIGUOUS',
|
|
13
13
|
'X_E2E_SERVICE_WORKER_ABSENT',
|
|
14
14
|
'X_E2E_APP_FAILED',
|
|
15
|
+
'X_E2E_CONSOLE_ERRORS',
|
|
15
16
|
] as const;
|
|
16
17
|
|
|
17
18
|
type OwnE2eCode = (typeof OWN_E2E_CODES)[number];
|
|
18
19
|
|
|
19
|
-
/** Every code an e2e run can refuse with: this package's
|
|
20
|
+
/** Every code an e2e run can refuse with: this package's eight, then the browser's four. */
|
|
20
21
|
export const E2E_ERROR_CODES = [...OWN_E2E_CODES, ...CDP_ERROR_CODES] as const;
|
|
21
22
|
|
|
22
23
|
export type E2eErrorCode = (typeof E2E_ERROR_CODES)[number];
|
|
@@ -29,6 +30,7 @@ const OWN_E2E_TITLES = Object.freeze<Record<OwnE2eCode, string>>({
|
|
|
29
30
|
X_E2E_LOCATOR_AMBIGUOUS: 'an e2e locator matched more than one element and was asked to click',
|
|
30
31
|
X_E2E_SERVICE_WORKER_ABSENT: 'no service worker took control of the page within the budget',
|
|
31
32
|
X_E2E_APP_FAILED: 'the app an e2e run spawned did not come up',
|
|
33
|
+
X_E2E_CONSOLE_ERRORS: 'the page printed a console error or threw an uncaught exception',
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
export const E2E_ERROR_TITLES = Object.freeze<Record<E2eErrorCode, string>>({
|
package/src/e2e-errors.ts
CHANGED
|
@@ -164,3 +164,18 @@ export class E2eAppFailedError extends UltimateError {
|
|
|
164
164
|
this.inner = inner;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The page printed an error, or threw one nothing caught, while the test ran. Every such line is
|
|
170
|
+
* quoted back at once, so one run shows them all rather than one per fix.
|
|
171
|
+
*/
|
|
172
|
+
export class E2eConsoleErrorsError extends UltimateError {
|
|
173
|
+
constructor(input: { readonly errors: readonly string[]; readonly url: string }) {
|
|
174
|
+
const listed = input.errors.map((text) => renderCauseValue(text)).join('; ');
|
|
175
|
+
super({
|
|
176
|
+
code: 'X_E2E_CONSOLE_ERRORS',
|
|
177
|
+
cause: `the page printed ${String(input.errors.length)} console error(s) during this test: ${listed}`,
|
|
178
|
+
fix: `x dev # then open ${renderFixLiteral(input.url, URL_PLACEHOLDER)} with the browser console open; each error is the page's to fix`,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Key presses and the console, for the page an e2e test holds. Free functions over `PageLike`
|
|
2
|
+
// rather than members of it, so no implementation of that interface has to grow: each reaches the
|
|
3
|
+
// browser port `e2ePage()` was built over, and refuses by name when that port cannot.
|
|
4
|
+
|
|
5
|
+
import type { E2eConsoleMessage } from './e2e-console';
|
|
6
|
+
import { E2eConsoleErrorsError } from './e2e-errors';
|
|
7
|
+
import type { E2eBrowserPage } from './e2e-page';
|
|
8
|
+
import { FixtureUnavailableError } from './errors';
|
|
9
|
+
import type { PageLike } from './test-types';
|
|
10
|
+
|
|
11
|
+
/** A WeakMap, so a page nobody holds any more is not kept alive by having been bound. */
|
|
12
|
+
const bindings = new WeakMap<PageLike, E2eBrowserPage>();
|
|
13
|
+
|
|
14
|
+
const DRIVER_PAGE = "the page e2eTest or a test's `{ page }` fixture hands you";
|
|
15
|
+
|
|
16
|
+
/** Called by `e2ePage()`: the page it answers, and the port behind it. */
|
|
17
|
+
export function bindPagePort(page: PageLike, port: E2eBrowserPage): void {
|
|
18
|
+
bindings.set(page, port);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const portOf = (page: PageLike, call: string, member: string): E2eBrowserPage => {
|
|
22
|
+
const port = bindings.get(page);
|
|
23
|
+
if (port === undefined) throw new FixtureUnavailableError({ name: call, needs: DRIVER_PAGE });
|
|
24
|
+
if (port[member as keyof E2eBrowserPage] === undefined) {
|
|
25
|
+
throw new FixtureUnavailableError({
|
|
26
|
+
name: call,
|
|
27
|
+
needs: `a page whose driver implements ${member}() — cdpE2eTab does; a hand-rolled E2eBrowserPage may not`,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return port;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A REAL key press at whatever has focus, so its default action runs (Tab moves focus, Enter
|
|
35
|
+
* submits): a key name (`Tab`, `Enter`, `Escape`, the arrows …), one letter or digit, or a chord
|
|
36
|
+
* with modifiers held (`Shift+Tab`, `Control+k`, `Meta+Shift+Enter`).
|
|
37
|
+
*/
|
|
38
|
+
export async function pressKey(page: PageLike, key: string): Promise<void> {
|
|
39
|
+
const port = portOf(page, 'pressKey', 'press');
|
|
40
|
+
await port.press?.(key);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Starts the running test's console: the e2e driver calls it as each test starts, on `e2eTest` and
|
|
45
|
+
* on the `{ page }` fixture alike. One round trip first, so a line the previous test printed that
|
|
46
|
+
* is still in flight lands before the clear, never in this test.
|
|
47
|
+
*/
|
|
48
|
+
export async function markConsoleStart(page: PageLike): Promise<void> {
|
|
49
|
+
const port = bindings.get(page);
|
|
50
|
+
if (port?.clearConsole === undefined) return;
|
|
51
|
+
await port.evaluate('0');
|
|
52
|
+
port.clearConsole();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Every console line and uncaught exception since the running test began. One round trip to the
|
|
57
|
+
* page first: the browser sends each console event before the reply to a later call, so a line
|
|
58
|
+
* printed just before this call is in the answer.
|
|
59
|
+
*/
|
|
60
|
+
export async function consoleMessages(page: PageLike): Promise<readonly E2eConsoleMessage[]> {
|
|
61
|
+
const port = portOf(page, 'consoleMessages', 'consoleMessages');
|
|
62
|
+
// Without a reset the log is the whole tab's, and a previous test's error would fail this one.
|
|
63
|
+
portOf(page, 'consoleMessages', 'clearConsole');
|
|
64
|
+
await port.evaluate('0');
|
|
65
|
+
return port.consoleMessages?.() ?? [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Refuses with `X_E2E_CONSOLE_ERRORS`, quoting each, when the page printed `console.error` (or a
|
|
70
|
+
* failed `console.assert`) or threw an uncaught exception since the running test began. Warnings
|
|
71
|
+
* and logs pass; filter `consoleMessages(page)` for a stricter or looser rule.
|
|
72
|
+
*/
|
|
73
|
+
export async function expectNoConsoleErrors(page: PageLike): Promise<void> {
|
|
74
|
+
const errors = (await consoleMessages(page)).filter((message) => message.level === 'error');
|
|
75
|
+
if (errors.length === 0) return;
|
|
76
|
+
throw new E2eConsoleErrorsError({
|
|
77
|
+
errors: errors.map((message) => message.text),
|
|
78
|
+
url: page.url(),
|
|
79
|
+
});
|
|
80
|
+
}
|
package/src/e2e-page.ts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { finiteCount } from '@ultimat3/core';
|
|
6
6
|
import type { AxTreeNode } from './ax-node';
|
|
7
|
+
import type { E2eConsoleMessage } from './e2e-console';
|
|
7
8
|
import { evaluateClosure } from './e2e-evaluate';
|
|
8
9
|
import { e2eLocator } from './e2e-locator';
|
|
10
|
+
import { bindPagePort } from './e2e-page-input';
|
|
9
11
|
import type { E2eSelection } from './e2e-selection';
|
|
10
12
|
import { callBudget, waitForServiceWorker } from './e2e-service-worker';
|
|
11
13
|
import type { LocatorLike, PageLike } from './test-types';
|
|
@@ -40,6 +42,19 @@ export interface E2eBrowserPage {
|
|
|
40
42
|
* (`e2e-a11y-run.ts`) rather than passing a page nothing audited.
|
|
41
43
|
*/
|
|
42
44
|
accessibilityTree?(request: AxTreeRequest): Promise<readonly AxTreeNode[]>;
|
|
45
|
+
/**
|
|
46
|
+
* A real key press at the focused element, or a chord (`Shift+Tab`, `Control+k`): what
|
|
47
|
+
* `pressKey(page, key)` forwards to. OPTIONAL as `offline` is; absent, `pressKey` refuses by name.
|
|
48
|
+
*/
|
|
49
|
+
press?(key: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Every console line and uncaught exception the page has printed since `clearConsole()` (or since
|
|
52
|
+
* this port was built), in order: what `consoleMessages(page)` reads. OPTIONAL as `offline` is;
|
|
53
|
+
* absent, it refuses by name.
|
|
54
|
+
*/
|
|
55
|
+
consoleMessages?(): readonly E2eConsoleMessage[];
|
|
56
|
+
/** Forget the console held so far: the e2e driver calls it as each test starts. */
|
|
57
|
+
clearConsole?(): void;
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
/** What the audit asks of one tree read: which nodes to describe, and the selectors to test. */
|
|
@@ -163,7 +178,7 @@ export function e2ePage(options: E2ePageOptions): PageLike {
|
|
|
163
178
|
return answer;
|
|
164
179
|
};
|
|
165
180
|
|
|
166
|
-
|
|
181
|
+
const adapted: PageLike = {
|
|
167
182
|
url: () => page.url(),
|
|
168
183
|
goto: (url) => settled(page.goto(absolute(url), { timeout })),
|
|
169
184
|
// The page's OWN url, re-read at call time: a reload of the url the adapter was built with
|
|
@@ -198,4 +213,6 @@ export function e2ePage(options: E2ePageOptions): PageLike {
|
|
|
198
213
|
}),
|
|
199
214
|
getByText: (text) => locate({ kind: 'text', text, first: false }),
|
|
200
215
|
};
|
|
216
|
+
bindPagePort(adapted, page);
|
|
217
|
+
return adapted;
|
|
201
218
|
}
|
|
@@ -4,7 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
import { expect } from 'bun:test';
|
|
6
6
|
import { isUltimateError } from '@ultimat3/core';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
bigint,
|
|
9
|
+
decimal,
|
|
10
|
+
entity,
|
|
11
|
+
integer,
|
|
12
|
+
json,
|
|
13
|
+
money,
|
|
14
|
+
t,
|
|
15
|
+
text,
|
|
16
|
+
timestamp,
|
|
17
|
+
uuid,
|
|
18
|
+
} from '@ultimat3/entity';
|
|
8
19
|
import { remember } from './entity-conformance-entities';
|
|
9
20
|
import { checkOver, idAt } from './entity-conformance-support';
|
|
10
21
|
import type { EntityDriverCheck } from './entity-driver-conformance';
|
|
@@ -49,6 +60,10 @@ const rates = remember(
|
|
|
49
60
|
}),
|
|
50
61
|
);
|
|
51
62
|
|
|
63
|
+
const totals = remember(
|
|
64
|
+
entity('ec_a_totals', { columns: { id: uuid().primaryKey(), n: bigint() } }),
|
|
65
|
+
);
|
|
66
|
+
|
|
52
67
|
const ORG = idAt('a1');
|
|
53
68
|
const OTHER_ORG = idAt('a2');
|
|
54
69
|
const [POST_A, POST_B, POST_C] = [idAt('aaa'), idAt('bbb'), idAt('ccc')];
|
|
@@ -207,4 +222,31 @@ const extremes: readonly EntityDriverCheck[] = [
|
|
|
207
222
|
),
|
|
208
223
|
];
|
|
209
224
|
|
|
210
|
-
|
|
225
|
+
/** Nineteen digits: past it Postgres' own `avg(bigint)` has no fraction digits left to answer in. */
|
|
226
|
+
const NINETEEN = 9_000_000_000_000_000_000n;
|
|
227
|
+
|
|
228
|
+
const means: readonly EntityDriverCheck[] = [
|
|
229
|
+
checkOver(
|
|
230
|
+
{ totals },
|
|
231
|
+
'avg over 19-digit bigints keeps six decimals',
|
|
232
|
+
async (db) => {
|
|
233
|
+
// Ten rows of N and one of N + 5: the mean is N + 5/11 = N.454545(45…), which rounds DOWN
|
|
234
|
+
// at six places — and up, wrongly, in a division that rounded once at seven first.
|
|
235
|
+
for (let index = 0; index < 11; index += 1) {
|
|
236
|
+
const n = (index === 10 ? NINETEEN + 5n : NINETEEN).toString();
|
|
237
|
+
await db.totals.insert({ id: idAt(index + 1), n });
|
|
238
|
+
}
|
|
239
|
+
expect(await db.totals.avg('n')).toBe('9000000000000000000.454545');
|
|
240
|
+
expect(await db.totals.aggregate({ mean: { fn: 'avg', column: 'n' } })).toEqual({
|
|
241
|
+
mean: '9000000000000000000.454545',
|
|
242
|
+
});
|
|
243
|
+
// Two rows one apart: the half the server's own scale dropped.
|
|
244
|
+
const pair = db.totals.andWhere('id', 'in', [idAt(10), idAt(11)]);
|
|
245
|
+
expect(await pair.avg('n')).toBe('9000000000000000002.500000');
|
|
246
|
+
expect(await db.totals.andWhere('n', 'lt', 0).avg('n')).toBeNull();
|
|
247
|
+
},
|
|
248
|
+
['aggregate:avg'],
|
|
249
|
+
),
|
|
250
|
+
];
|
|
251
|
+
|
|
252
|
+
export const AGGREGATE_CHECKS: readonly EntityDriverCheck[] = [...countBy, ...extremes, ...means];
|
|
@@ -188,6 +188,31 @@ const writes: readonly EntityDriverCheck[] = [
|
|
|
188
188
|
]);
|
|
189
189
|
},
|
|
190
190
|
),
|
|
191
|
+
checkOver(
|
|
192
|
+
{ uniques },
|
|
193
|
+
'a batch whose end state is unique but whose order meets a stored value moves no row',
|
|
194
|
+
async (db) => {
|
|
195
|
+
await db.uniques.insertAll([
|
|
196
|
+
{ id: 'a', slug: 'x' },
|
|
197
|
+
{ id: 'b', slug: 'y' },
|
|
198
|
+
{ id: 'c', slug: 'q' },
|
|
199
|
+
]);
|
|
200
|
+
// `c` takes `b`'s value before `b` lets it go: Postgres checks a plain unique per row, so the
|
|
201
|
+
// one statement is refused and rolled back whole — `a`'s new value included.
|
|
202
|
+
const shift = () =>
|
|
203
|
+
db.uniques.updateMany([
|
|
204
|
+
{ id: 'a', patch: { slug: 'w' } },
|
|
205
|
+
{ id: 'c', patch: { slug: 'y' } },
|
|
206
|
+
{ id: 'b', patch: { slug: 'z' } },
|
|
207
|
+
]);
|
|
208
|
+
expect(await codeOf(shift)).toBe('X_DB_UNIQUE_VIOLATION');
|
|
209
|
+
expect((await db.uniques.orderBy('id').all()).map((row) => row.slug)).toEqual([
|
|
210
|
+
'x',
|
|
211
|
+
'y',
|
|
212
|
+
'q',
|
|
213
|
+
]);
|
|
214
|
+
},
|
|
215
|
+
),
|
|
191
216
|
checkOver(
|
|
192
217
|
{ broad },
|
|
193
218
|
'a 200-row, 600-column updateMany past the bind ceiling lands every patch, or none of them',
|
package/src/errors.ts
CHANGED
|
@@ -83,6 +83,7 @@ export const TESTING_ERROR_CODES = [
|
|
|
83
83
|
'X_TEST_SOAK_HEAP_GROWTH',
|
|
84
84
|
'X_TEST_TEMP_TREE_LEFT',
|
|
85
85
|
'X_TEST_ISLAND_BUILD_REUSED',
|
|
86
|
+
'X_DRILL_TEARDOWN_FAILED',
|
|
86
87
|
] as const;
|
|
87
88
|
|
|
88
89
|
export type TestingErrorCode = (typeof TESTING_ERROR_CODES)[number];
|
|
@@ -169,6 +170,7 @@ export const TESTING_ERROR_TITLES: Readonly<Record<TestingErrorCode, string>> =
|
|
|
169
170
|
X_TEST_SOAK_HEAP_GROWTH: 'a soak() run grew the live heap past its stated bound',
|
|
170
171
|
X_TEST_TEMP_TREE_LEFT: 'a temp tree survived its own remove',
|
|
171
172
|
X_TEST_ISLAND_BUILD_REUSED: 'an island builder answered the shipped build with the coverage one',
|
|
173
|
+
X_DRILL_TEARDOWN_FAILED: 'a fault drill could not drop its scratch database',
|
|
172
174
|
};
|
|
173
175
|
|
|
174
176
|
// Titles must be registered for `format()` to render the contract's first line. Every code above is
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Character references back to characters, for the visible text a render test compares with a
|
|
2
|
+
// catalog string: every numeric reference, and the named ones copy commonly carries.
|
|
3
|
+
|
|
4
|
+
/** A `Map`, so a lookup never reaches `Object.prototype` (`bun run proto-index`). */
|
|
5
|
+
const NAMED: ReadonlyMap<string, string> = new Map([
|
|
6
|
+
['amp', '&'],
|
|
7
|
+
['lt', '<'],
|
|
8
|
+
['gt', '>'],
|
|
9
|
+
['quot', '"'],
|
|
10
|
+
['apos', "'"],
|
|
11
|
+
['nbsp', ' '],
|
|
12
|
+
['copy', '©'],
|
|
13
|
+
['reg', '®'],
|
|
14
|
+
['trade', '™'],
|
|
15
|
+
['hellip', '…'],
|
|
16
|
+
['ndash', '–'],
|
|
17
|
+
['mdash', '—'],
|
|
18
|
+
['lsquo', '‘'],
|
|
19
|
+
['rsquo', '’'],
|
|
20
|
+
['ldquo', '“'],
|
|
21
|
+
['rdquo', '”'],
|
|
22
|
+
['laquo', '«'],
|
|
23
|
+
['raquo', '»'],
|
|
24
|
+
['middot', '·'],
|
|
25
|
+
['bull', '•'],
|
|
26
|
+
['deg', '°'],
|
|
27
|
+
['times', '×'],
|
|
28
|
+
['euro', '€'],
|
|
29
|
+
['pound', '£'],
|
|
30
|
+
['yen', '¥'],
|
|
31
|
+
['cent', '¢'],
|
|
32
|
+
['sect', '§'],
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The names the HTML standard also reads WITHOUT a semicolon in text (its legacy list), among
|
|
37
|
+
* those the table holds: `&` renders `&`, `©2026` renders `©2026`.
|
|
38
|
+
*/
|
|
39
|
+
const LEGACY = [
|
|
40
|
+
'amp',
|
|
41
|
+
'lt',
|
|
42
|
+
'gt',
|
|
43
|
+
'quot',
|
|
44
|
+
'nbsp',
|
|
45
|
+
'copy',
|
|
46
|
+
'reg',
|
|
47
|
+
'laquo',
|
|
48
|
+
'raquo',
|
|
49
|
+
'middot',
|
|
50
|
+
'deg',
|
|
51
|
+
'times',
|
|
52
|
+
'pound',
|
|
53
|
+
'yen',
|
|
54
|
+
'cent',
|
|
55
|
+
'sect',
|
|
56
|
+
] as const;
|
|
57
|
+
|
|
58
|
+
/** A numeric reference's semicolon is optional, as a browser reads it; a named one's is not. */
|
|
59
|
+
const REFERENCE = /&(?:#(\d+);?|#[xX]([0-9a-fA-F]+);?|([a-zA-Z][a-zA-Z0-9]*)(;?))/g;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* `€`–`Ÿ` name the windows-1252 characters there, not C1 controls: the HTML standard's
|
|
63
|
+
* numeric reference table, which is what a browser renders (`€` is `€`).
|
|
64
|
+
*/
|
|
65
|
+
const WINDOWS_1252: ReadonlyMap<number, number> = new Map([
|
|
66
|
+
[0x80, 0x20ac],
|
|
67
|
+
[0x82, 0x201a],
|
|
68
|
+
[0x83, 0x0192],
|
|
69
|
+
[0x84, 0x201e],
|
|
70
|
+
[0x85, 0x2026],
|
|
71
|
+
[0x86, 0x2020],
|
|
72
|
+
[0x87, 0x2021],
|
|
73
|
+
[0x88, 0x02c6],
|
|
74
|
+
[0x89, 0x2030],
|
|
75
|
+
[0x8a, 0x0160],
|
|
76
|
+
[0x8b, 0x2039],
|
|
77
|
+
[0x8c, 0x0152],
|
|
78
|
+
[0x8e, 0x017d],
|
|
79
|
+
[0x91, 0x2018],
|
|
80
|
+
[0x92, 0x2019],
|
|
81
|
+
[0x93, 0x201c],
|
|
82
|
+
[0x94, 0x201d],
|
|
83
|
+
[0x95, 0x2022],
|
|
84
|
+
[0x96, 0x2013],
|
|
85
|
+
[0x97, 0x2014],
|
|
86
|
+
[0x98, 0x02dc],
|
|
87
|
+
[0x99, 0x2122],
|
|
88
|
+
[0x9a, 0x0161],
|
|
89
|
+
[0x9b, 0x203a],
|
|
90
|
+
[0x9c, 0x0153],
|
|
91
|
+
[0x9e, 0x017e],
|
|
92
|
+
[0x9f, 0x0178],
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
/** What the HTML standard reads in place of a null, a surrogate or a code point past Unicode. */
|
|
96
|
+
const REPLACEMENT = '�';
|
|
97
|
+
|
|
98
|
+
const fromCodePoint = (point: number): string =>
|
|
99
|
+
point === 0 || point > 0x10ffff || (point >= 0xd800 && point <= 0xdfff)
|
|
100
|
+
? REPLACEMENT
|
|
101
|
+
: String.fromCodePoint(WINDOWS_1252.get(point) ?? point);
|
|
102
|
+
|
|
103
|
+
/** `&name` with no semicolon: the longest legacy name it starts with, the rest kept as text. */
|
|
104
|
+
function legacyPrefix(whole: string, name: string): string {
|
|
105
|
+
let longest = '';
|
|
106
|
+
for (const legacy of LEGACY) {
|
|
107
|
+
if (name.startsWith(legacy) && legacy.length > longest.length) longest = legacy;
|
|
108
|
+
}
|
|
109
|
+
if (longest === '') return whole;
|
|
110
|
+
return (NAMED.get(longest) ?? '') + name.slice(longest.length);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* One pass, so a decoded `&` never starts another reference: the text `&lt;` — an author's
|
|
115
|
+
* literal `<` — reads `<`, never `<`. A name outside the table stays as written, and so does
|
|
116
|
+
* a semicolon-less name outside the legacy list.
|
|
117
|
+
*/
|
|
118
|
+
export function decodeHtmlEntities(text: string): string {
|
|
119
|
+
return text.replace(
|
|
120
|
+
REFERENCE,
|
|
121
|
+
(
|
|
122
|
+
whole,
|
|
123
|
+
decimal: string | undefined,
|
|
124
|
+
hex: string | undefined,
|
|
125
|
+
name: string | undefined,
|
|
126
|
+
semicolon: string | undefined,
|
|
127
|
+
) => {
|
|
128
|
+
if (decimal !== undefined) return fromCodePoint(Number.parseInt(decimal, 10));
|
|
129
|
+
if (hex !== undefined) return fromCodePoint(Number.parseInt(hex, 16));
|
|
130
|
+
if (semicolon === '') return legacyPrefix(whole, name ?? '');
|
|
131
|
+
return NAMED.get(name ?? '') ?? whole;
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -37,10 +37,18 @@ export {
|
|
|
37
37
|
} from './cdp-browser';
|
|
38
38
|
export type { E2eBrowserLease, RunEndHook } from './cdp-browser-lease';
|
|
39
39
|
export { closeE2eBrowsersAtRunEnd, leaseE2eBrowser } from './cdp-browser-lease';
|
|
40
|
+
export type { E2eContext } from './cdp-e2e-context';
|
|
41
|
+
export { newBrowserContext } from './cdp-e2e-context';
|
|
40
42
|
export type { CdpE2eTabOptions, E2eTab, TouchPoint } from './cdp-e2e-page';
|
|
41
43
|
export { cdpE2eTab, PRESS_KEYS } from './cdp-e2e-page';
|
|
42
44
|
export type { CdpE2eSessionOptions, E2eSession } from './cdp-e2e-session';
|
|
43
45
|
export { cdpE2eSession } from './cdp-e2e-session';
|
|
46
|
+
export type {
|
|
47
|
+
VirtualAuthenticator,
|
|
48
|
+
VirtualAuthenticatorOptions,
|
|
49
|
+
VirtualCredential,
|
|
50
|
+
} from './cdp-e2e-webauthn';
|
|
51
|
+
export { addVirtualAuthenticator } from './cdp-e2e-webauthn';
|
|
44
52
|
// The exercise pass (plan 101 / 40, phase 2): an app's per-primitive overrides — 39's
|
|
45
53
|
// `.contract({ exercise })` option, one shape — and the pass over every action, query and job.
|
|
46
54
|
export type { ExerciseAppOptions, ExerciseOverride, ExerciseOverrides } from './define-exercise';
|
|
@@ -71,7 +79,11 @@ export {
|
|
|
71
79
|
// `x drill` (plan 101 / 40): the nine fault drills, the fleet they run on, the verdict over evidence.
|
|
72
80
|
export type { DrillConfig, DrillTiming } from './drill-budgets';
|
|
73
81
|
export { drillBudgets } from './drill-budgets';
|
|
74
|
-
export {
|
|
82
|
+
export {
|
|
83
|
+
DrillFailedError,
|
|
84
|
+
DrillServiceMissingError,
|
|
85
|
+
DrillTeardownFailedError,
|
|
86
|
+
} from './drill-errors';
|
|
75
87
|
export type { DrillFleet, DrillRoleProcess, DrillRollout, DrillServiceUrls } from './drill-fleet';
|
|
76
88
|
export { startDrillFleet } from './drill-fleet';
|
|
77
89
|
export { bunDrillSql } from './drill-jobs';
|
|
@@ -110,11 +122,13 @@ export { allowA11y } from './e2e-a11y-tabs';
|
|
|
110
122
|
export type { E2eApp, E2eAppMode, StartE2eAppOptions } from './e2e-app';
|
|
111
123
|
export { E2E_APP_START_MS, E2E_APP_STOP_MS, startE2eApp } from './e2e-app';
|
|
112
124
|
export { E2E_ROOT_ENV, e2eApp, e2eBaseUrl, e2eBrowser } from './e2e-browser-handle';
|
|
125
|
+
export type { E2eConsoleLevel, E2eConsoleMessage } from './e2e-console';
|
|
113
126
|
export type { E2eDriverOptions } from './e2e-driver';
|
|
114
127
|
export { e2eFixtures, installE2eDriver } from './e2e-driver';
|
|
115
128
|
export { E2E_ERROR_CODES } from './e2e-error-codes';
|
|
116
129
|
export {
|
|
117
130
|
E2eAppFailedError,
|
|
131
|
+
E2eConsoleErrorsError,
|
|
118
132
|
E2eEvaluateCapturedError,
|
|
119
133
|
E2eEvaluateThrewError,
|
|
120
134
|
E2eEvaluateUnsupportedError,
|
|
@@ -126,6 +140,7 @@ export type { LocatablePage } from './e2e-locator';
|
|
|
126
140
|
export { e2eLocator } from './e2e-locator';
|
|
127
141
|
export type { AxTreeRequest, E2eBrowserPage, E2ePageOptions } from './e2e-page';
|
|
128
142
|
export { DEFAULT_E2E_TIMEOUT_MS, DEFAULT_SERVICE_WORKER_TIMEOUT_MS, e2ePage } from './e2e-page';
|
|
143
|
+
export { consoleMessages, expectNoConsoleErrors, pressKey } from './e2e-page-input';
|
|
129
144
|
export type { E2eSelection } from './e2e-selection';
|
|
130
145
|
export type { TestingErrorCode } from './errors';
|
|
131
146
|
export {
|
package/src/isolated-plugins.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Frees each finished test file in an ISOLATED run. Bun 1.4.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Frees each finished test file in an ISOLATED run. Through Bun 1.4.5 a plugin keeps every
|
|
2
|
+
// finished file's global alive; Bun 1.4.6 clears it at the swap, so the workaround is skipped there.
|
|
3
|
+
// The framework registers two plugins in every file; `isolated-plugins.test.ts` measures both
|
|
4
|
+
// behaviours with real `bun test` runs.
|
|
5
5
|
|
|
6
6
|
import { afterAll } from 'bun:test';
|
|
7
7
|
|
|
@@ -13,13 +13,24 @@ import { afterAll } from 'bun:test';
|
|
|
13
13
|
export const ISOLATED_ENV = 'ULTIMATE_TEST_ISOLATED';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Bun 1.4.6 landed the runtime-side fix: the `--isolate` swap now clears the outgoing global's
|
|
17
|
+
* plugin lists and module registry, and `Bun.plugin.clearAll()` shares that clear/reset path. The
|
|
18
|
+
* framework's own `afterAll` clear then retains one global per file instead of freeing it. Canary
|
|
19
|
+
* builds carry a `-canary` suffix, which semver orders BEFORE the 1.4.6 release, so compare the
|
|
20
|
+
* numeric part only: the runtime fix is in every 1.4.6 build, prerelease or final. The hook below
|
|
21
|
+
* is installed only while this returns true.
|
|
22
|
+
*/
|
|
23
|
+
export const needsPluginRelease = (version: string = Bun.version): boolean =>
|
|
24
|
+
Bun.semver.order(version.split('-')[0] ?? version, '1.4.6') < 0;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `Bun.plugin.clearAll()` after each file, isolated runs on Bun below 1.4.6 only. Measured on one
|
|
28
|
+
* adopter's unit suite (652 files, 18 workers): per-worker peak 2.1–2.3 GB → 1.0–1.5 GB, total
|
|
29
|
+
* ~30 GB → 18 GB. The next file's preload registers the plugins again, so every file still gets them.
|
|
19
30
|
*
|
|
20
31
|
* NEVER in a shared process: render's loader keeps an `installed` flag, so a cleared plugin is
|
|
21
32
|
* never re-registered and the next `.tsx` compiles with Bun's classic factory — `__xh is not
|
|
22
|
-
* defined`.
|
|
33
|
+
* defined`. On 1.4.6+ the runtime clears at the swap, so this installs no hook at all.
|
|
23
34
|
*/
|
|
24
35
|
export function releasePluginsAfterIsolatedFile(
|
|
25
36
|
env: Readonly<Record<string, string | undefined>> = Bun.env,
|
|
@@ -27,6 +38,7 @@ export function releasePluginsAfterIsolatedFile(
|
|
|
27
38
|
plugin: { clearAll(): void } = Bun.plugin,
|
|
28
39
|
): boolean {
|
|
29
40
|
if (env[ISOLATED_ENV] !== '1') return false;
|
|
41
|
+
if (!needsPluginRelease()) return false;
|
|
30
42
|
after(() => clearPlugins(plugin));
|
|
31
43
|
return true;
|
|
32
44
|
}
|
|
@@ -11,7 +11,7 @@ export class TestPolicyExpectedError extends UltimateError {
|
|
|
11
11
|
super({
|
|
12
12
|
code: 'X_TEST_POLICY_EXPECTED',
|
|
13
13
|
cause: `toDenyPolicy expects a policy — an object with run() (@ultimat3/policy) or evaluate() — and received ${describeValue(received)}`,
|
|
14
|
-
fix: "expect(post.policy).toDenyPolicy(ctx)
|
|
14
|
+
fix: "expect(post.policy).toDenyPolicy(ctx) // pass the policy object (@ultimat3/policy's, with run() or evaluate()), never the action or its result",
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -22,18 +22,29 @@ export class TestOpenApiExpectedError extends UltimateError {
|
|
|
22
22
|
super({
|
|
23
23
|
code: 'X_TEST_OPENAPI_EXPECTED',
|
|
24
24
|
cause: `toMatchOpenApi expects an OpenAPI document — an object with operations: [{ operationId, required? }] — and received ${describeValue(received)}`,
|
|
25
|
-
fix: 'expect(await app.openapi()).toMatchOpenApi(committed)
|
|
25
|
+
fix: 'expect(await app.openapi()).toMatchOpenApi(committed) // the receiver is the generated document: an object with operations: [{ operationId, required? }]',
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* `toBeWithinBudget` handed something that is not a finite number — as the measurement, or as the
|
|
32
|
+
* LIMIT: `budgets['renamedKey']` is `undefined`, and `x <= undefined` is false, so `.not` held.
|
|
33
|
+
*/
|
|
31
34
|
export class TestNumberExpectedError extends UltimateError {
|
|
32
|
-
constructor(received: unknown) {
|
|
33
|
-
super(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
constructor(received: unknown, side: 'measurement' | 'limit' = 'measurement') {
|
|
36
|
+
super(
|
|
37
|
+
side === 'limit'
|
|
38
|
+
? {
|
|
39
|
+
code: 'X_TEST_NUMBER_EXPECTED',
|
|
40
|
+
cause: `toBeWithinBudget expects a finite number as the budget's limit, and was given ${describeValue(received)}`,
|
|
41
|
+
fix: "expect(bytes).toBeWithinBudget(budgets['<a key the table has>']) // the limit read undefined or NaN: name a key your budgets table declares",
|
|
42
|
+
}
|
|
43
|
+
: {
|
|
44
|
+
code: 'X_TEST_NUMBER_EXPECTED',
|
|
45
|
+
cause: `toBeWithinBudget expects a finite number to compare against the budget, and received ${describeValue(received)}`,
|
|
46
|
+
fix: 'expect(bytes).toBeWithinBudget(limit) // pass the measured number itself, e.g. (await Bun.file(path).arrayBuffer()).byteLength, never a Promise or a string',
|
|
47
|
+
},
|
|
48
|
+
);
|
|
38
49
|
}
|
|
39
50
|
}
|
package/src/matchers.ts
CHANGED
|
@@ -269,6 +269,10 @@ const implementations: ExpectExtendMatchers<UltimateMatchers<unknown>> = {
|
|
|
269
269
|
if (typeof received !== 'number' || !Number.isFinite(received)) {
|
|
270
270
|
throw new TestNumberExpectedError(received);
|
|
271
271
|
}
|
|
272
|
+
// The limit too: a renamed budget key reads `undefined`, and `received <= undefined` is false.
|
|
273
|
+
if (typeof limit !== 'number' || !Number.isFinite(limit)) {
|
|
274
|
+
throw new TestNumberExpectedError(limit, 'limit');
|
|
275
|
+
}
|
|
272
276
|
return result(
|
|
273
277
|
received <= limit,
|
|
274
278
|
() => `expected ${received} to be within the budget of ${limit}`,
|