@dream_engine/testing 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/LICENSE +21 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/browser-fixtures.d.ts +26 -0
- package/dist/browser-fixtures.d.ts.map +1 -0
- package/dist/browser-fixtures.js +134 -0
- package/dist/browser-fixtures.js.map +1 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +56 -0
- package/dist/config.js.map +1 -0
- package/dist/discovery.d.ts +24 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +117 -0
- package/dist/discovery.js.map +1 -0
- package/dist/expect.d.ts +116 -0
- package/dist/expect.d.ts.map +1 -0
- package/dist/expect.js +454 -0
- package/dist/expect.js.map +1 -0
- package/dist/fixtures.d.ts +38 -0
- package/dist/fixtures.d.ts.map +1 -0
- package/dist/fixtures.js +135 -0
- package/dist/fixtures.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +58 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +250 -0
- package/dist/registry.js.map +1 -0
- package/dist/reporters/dot.d.ts +11 -0
- package/dist/reporters/dot.d.ts.map +1 -0
- package/dist/reporters/dot.js +18 -0
- package/dist/reporters/dot.js.map +1 -0
- package/dist/reporters/html.d.ts +8 -0
- package/dist/reporters/html.d.ts.map +1 -0
- package/dist/reporters/html.js +63 -0
- package/dist/reporters/html.js.map +1 -0
- package/dist/reporters/index.d.ts +38 -0
- package/dist/reporters/index.d.ts.map +1 -0
- package/dist/reporters/index.js +47 -0
- package/dist/reporters/index.js.map +1 -0
- package/dist/reporters/json.d.ts +9 -0
- package/dist/reporters/json.d.ts.map +1 -0
- package/dist/reporters/json.js +42 -0
- package/dist/reporters/json.js.map +1 -0
- package/dist/reporters/junit.d.ts +8 -0
- package/dist/reporters/junit.d.ts.map +1 -0
- package/dist/reporters/junit.js +44 -0
- package/dist/reporters/junit.js.map +1 -0
- package/dist/reporters/list.d.ts +10 -0
- package/dist/reporters/list.d.ts.map +1 -0
- package/dist/reporters/list.js +17 -0
- package/dist/reporters/list.js.map +1 -0
- package/dist/reporters/terminal.d.ts +13 -0
- package/dist/reporters/terminal.d.ts.map +1 -0
- package/dist/reporters/terminal.js +44 -0
- package/dist/reporters/terminal.js.map +1 -0
- package/dist/runner.d.ts +13 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +481 -0
- package/dist/runner.js.map +1 -0
- package/dist/types.d.ts +231 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +35 -3
- package/README.md +0 -3
package/dist/expect.js
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `expect()` — generic matchers plus auto-retrying web matchers for BashirWeb
|
|
3
|
+
* pages and locators, `expect.poll()`, `expect.toPass()`, custom matchers and negation.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { BashirWebError } from '@dream_engine/core';
|
|
7
|
+
import { compareScreenshots } from '@dream_engine/browser';
|
|
8
|
+
/** Default polling interval for auto-retrying assertions. */
|
|
9
|
+
const POLL_INTERVAL = 100;
|
|
10
|
+
export class AssertionError extends BashirWebError {
|
|
11
|
+
constructor(message, options = {}) {
|
|
12
|
+
super('ASSERT', message, options);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Reads the expect timeout from the ambient test info when available. */
|
|
16
|
+
function currentExpectTimeout() {
|
|
17
|
+
return ambientTimeout ?? 5_000;
|
|
18
|
+
}
|
|
19
|
+
let ambientTimeout;
|
|
20
|
+
let ambientTestTitle;
|
|
21
|
+
/** Sets the expect timeout for assertions running inside the given test (runner-managed). */
|
|
22
|
+
export function setAmbientExpectTimeout(ms) {
|
|
23
|
+
ambientTimeout = ms;
|
|
24
|
+
}
|
|
25
|
+
/** Sets the ambient test title, used to name screenshots (runner-managed). */
|
|
26
|
+
export function setAmbientTestTitle(title) {
|
|
27
|
+
ambientTestTitle = title;
|
|
28
|
+
}
|
|
29
|
+
function fail(message, details) {
|
|
30
|
+
throw new AssertionError(message, { details });
|
|
31
|
+
}
|
|
32
|
+
function show(value) {
|
|
33
|
+
if (typeof value === 'string')
|
|
34
|
+
return JSON.stringify(value);
|
|
35
|
+
if (value === undefined)
|
|
36
|
+
return 'undefined';
|
|
37
|
+
if (value === null)
|
|
38
|
+
return 'null';
|
|
39
|
+
if (value instanceof Error)
|
|
40
|
+
return `${value.name}: ${value.message}`;
|
|
41
|
+
try {
|
|
42
|
+
return JSON.stringify(value);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return String(value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Deep equality used by toEqual. */
|
|
49
|
+
export function deepEqual(a, b) {
|
|
50
|
+
if (a === b)
|
|
51
|
+
return true;
|
|
52
|
+
if (Number.isNaN(a) && Number.isNaN(b))
|
|
53
|
+
return true;
|
|
54
|
+
if (a === null || b === null || a === undefined || b === undefined)
|
|
55
|
+
return a === b;
|
|
56
|
+
if (typeof a !== typeof b)
|
|
57
|
+
return false;
|
|
58
|
+
if (a instanceof Date && b instanceof Date)
|
|
59
|
+
return a.getTime() === b.getTime();
|
|
60
|
+
if (a instanceof RegExp && b instanceof RegExp)
|
|
61
|
+
return a.source === b.source && a.flags === b.flags;
|
|
62
|
+
if (a instanceof Error && b instanceof Error)
|
|
63
|
+
return a.message === b.message && a.name === b.name;
|
|
64
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
65
|
+
if (a.length !== b.length)
|
|
66
|
+
return false;
|
|
67
|
+
return a.every((v, i) => deepEqual(v, b[i]));
|
|
68
|
+
}
|
|
69
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
70
|
+
return false;
|
|
71
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
72
|
+
const keysA = Object.keys(a);
|
|
73
|
+
const keysB = Object.keys(b);
|
|
74
|
+
if (keysA.length !== keysB.length)
|
|
75
|
+
return false;
|
|
76
|
+
return keysA.every((k) => deepEqual(a[k], b[k]));
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/** Deep equality used by toStrictEqual (also compares prototypes and undefined keys). */
|
|
81
|
+
export function deepStrictEqual(a, b) {
|
|
82
|
+
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b))
|
|
83
|
+
return false;
|
|
84
|
+
return deepEqual(a, b);
|
|
85
|
+
}
|
|
86
|
+
/** Polls `check` until it returns true or the timeout elapses. */
|
|
87
|
+
async function pollUntil(check, timeout, label) {
|
|
88
|
+
const deadline = Date.now() + timeout;
|
|
89
|
+
let lastError;
|
|
90
|
+
while (Date.now() < deadline) {
|
|
91
|
+
try {
|
|
92
|
+
if (await check())
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
lastError = error;
|
|
97
|
+
}
|
|
98
|
+
await new Promise((r) => setTimeout(r, POLL_INTERVAL));
|
|
99
|
+
}
|
|
100
|
+
if (lastError)
|
|
101
|
+
fail(`Timed out waiting for ${label}: ${lastError.message}`, { timeout });
|
|
102
|
+
fail(`Timed out waiting for ${label} after ${timeout}ms`);
|
|
103
|
+
}
|
|
104
|
+
function textMatches(text, expected) {
|
|
105
|
+
if (expected instanceof RegExp)
|
|
106
|
+
return expected.test(text);
|
|
107
|
+
return text.includes(expected);
|
|
108
|
+
}
|
|
109
|
+
function asLocator(subject) {
|
|
110
|
+
if (subject && typeof subject === 'object' && typeof subject.isVisible === 'function') {
|
|
111
|
+
return subject;
|
|
112
|
+
}
|
|
113
|
+
fail('Expected a locator for this assertion, received a non-locator value');
|
|
114
|
+
}
|
|
115
|
+
function asPage(subject) {
|
|
116
|
+
if (subject && typeof subject === 'object' && typeof subject.url === 'function') {
|
|
117
|
+
return subject;
|
|
118
|
+
}
|
|
119
|
+
fail('Expected a page for this assertion, received a non-page value');
|
|
120
|
+
}
|
|
121
|
+
const customMatchers = {};
|
|
122
|
+
/** Registers custom matchers, e.g. `expect.extend({ toBeWithinRange(received, min, max) {...} })`. */
|
|
123
|
+
export function extendExpect(matchers) {
|
|
124
|
+
Object.assign(customMatchers, matchers);
|
|
125
|
+
}
|
|
126
|
+
function runCustom(name, received, args) {
|
|
127
|
+
const matcher = customMatchers[name];
|
|
128
|
+
if (!matcher)
|
|
129
|
+
fail(`Unknown custom matcher "${name}"`);
|
|
130
|
+
const result = matcher(received, ...args);
|
|
131
|
+
if (result.pass)
|
|
132
|
+
return;
|
|
133
|
+
fail(result.message());
|
|
134
|
+
}
|
|
135
|
+
function createExpectation(received, negated) {
|
|
136
|
+
const assert = (pass, message) => {
|
|
137
|
+
if (pass === negated)
|
|
138
|
+
fail(message());
|
|
139
|
+
};
|
|
140
|
+
const expectation = {
|
|
141
|
+
get not() {
|
|
142
|
+
return createExpectation(received, !negated);
|
|
143
|
+
},
|
|
144
|
+
toBe(expected) {
|
|
145
|
+
assert(Object.is(received, expected), () => `expected ${show(received)} to be ${show(expected)}`);
|
|
146
|
+
},
|
|
147
|
+
toEqual(expected) {
|
|
148
|
+
assert(deepEqual(received, expected), () => `expected ${show(received)} to deeply equal ${show(expected)}`);
|
|
149
|
+
},
|
|
150
|
+
toStrictEqual(expected) {
|
|
151
|
+
assert(deepStrictEqual(received, expected), () => `expected ${show(received)} to strictly equal ${show(expected)}`);
|
|
152
|
+
},
|
|
153
|
+
toContain(item) {
|
|
154
|
+
const pass = typeof received === 'string' ? received.includes(String(item)) : Array.isArray(received) ? received.includes(item) : false;
|
|
155
|
+
assert(pass, () => `expected ${show(received)} to contain ${show(item)}`);
|
|
156
|
+
},
|
|
157
|
+
toMatch(pattern) {
|
|
158
|
+
const pass = pattern instanceof RegExp ? pattern.test(String(received)) : String(received).includes(pattern);
|
|
159
|
+
assert(pass, () => `expected ${show(received)} to match ${show(pattern)}`);
|
|
160
|
+
},
|
|
161
|
+
toBeTruthy() {
|
|
162
|
+
assert(Boolean(received), () => `expected ${show(received)} to be truthy`);
|
|
163
|
+
},
|
|
164
|
+
toBeFalsy() {
|
|
165
|
+
assert(!received, () => `expected ${show(received)} to be falsy`);
|
|
166
|
+
},
|
|
167
|
+
toBeNull() {
|
|
168
|
+
assert(received === null, () => `expected ${show(received)} to be null`);
|
|
169
|
+
},
|
|
170
|
+
toBeUndefined() {
|
|
171
|
+
assert(received === undefined, () => `expected ${show(received)} to be undefined`);
|
|
172
|
+
},
|
|
173
|
+
toBeDefined() {
|
|
174
|
+
assert(received !== undefined, () => `expected ${show(received)} to be defined`);
|
|
175
|
+
},
|
|
176
|
+
toBeGreaterThan(n) {
|
|
177
|
+
assert(received > n, () => `expected ${show(received)} to be greater than ${n}`);
|
|
178
|
+
},
|
|
179
|
+
toBeLessThan(n) {
|
|
180
|
+
assert(received < n, () => `expected ${show(received)} to be less than ${n}`);
|
|
181
|
+
},
|
|
182
|
+
toBeInstanceOf(cls) {
|
|
183
|
+
assert(received instanceof cls, () => `expected ${show(received)} to be an instance of ${cls.name}`);
|
|
184
|
+
},
|
|
185
|
+
toThrow(error) {
|
|
186
|
+
if (typeof received !== 'function')
|
|
187
|
+
fail('toThrow expects a function');
|
|
188
|
+
let thrown;
|
|
189
|
+
try {
|
|
190
|
+
received();
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
thrown = e;
|
|
194
|
+
}
|
|
195
|
+
let pass = thrown !== undefined;
|
|
196
|
+
if (pass && error !== undefined) {
|
|
197
|
+
if (error instanceof RegExp)
|
|
198
|
+
pass = error.test(thrown.message);
|
|
199
|
+
else if (typeof error === 'string')
|
|
200
|
+
pass = thrown.message.includes(error);
|
|
201
|
+
else if (typeof error === 'function')
|
|
202
|
+
pass = thrown instanceof error;
|
|
203
|
+
}
|
|
204
|
+
assert(pass, () => thrown === undefined
|
|
205
|
+
? 'expected the function to throw, but it did not'
|
|
206
|
+
: `expected the function to throw ${show(error ?? 'an error')}, but it threw ${show(thrown)}`);
|
|
207
|
+
},
|
|
208
|
+
toHaveLength(n) {
|
|
209
|
+
const len = received.length;
|
|
210
|
+
assert(len === n, () => `expected ${show(received)} to have length ${n}, received ${len}`);
|
|
211
|
+
},
|
|
212
|
+
// ---- web matchers (auto-retry) -------------------------------------------------
|
|
213
|
+
async toBeVisible(options) {
|
|
214
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
215
|
+
const locator = asLocator(received);
|
|
216
|
+
await pollUntil(() => locator.isVisible(), timeout, 'element to be visible');
|
|
217
|
+
},
|
|
218
|
+
async toBeHidden(options) {
|
|
219
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
220
|
+
const locator = asLocator(received);
|
|
221
|
+
await pollUntil(() => locator.isHidden(), timeout, 'element to be hidden');
|
|
222
|
+
},
|
|
223
|
+
async toBeAttached(options) {
|
|
224
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
225
|
+
const locator = asLocator(received);
|
|
226
|
+
await pollUntil(async () => (await locator.count()) > 0, timeout, 'element to be attached');
|
|
227
|
+
},
|
|
228
|
+
async toBeDetached(options) {
|
|
229
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
230
|
+
const locator = asLocator(received);
|
|
231
|
+
await pollUntil(async () => (await locator.count()) === 0, timeout, 'element to be detached');
|
|
232
|
+
},
|
|
233
|
+
async toBeEnabled(options) {
|
|
234
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
235
|
+
const locator = asLocator(received);
|
|
236
|
+
await pollUntil(() => locator.isEnabled(), timeout, 'element to be enabled');
|
|
237
|
+
},
|
|
238
|
+
async toBeDisabled(options) {
|
|
239
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
240
|
+
const locator = asLocator(received);
|
|
241
|
+
await pollUntil(() => locator.isDisabled(), timeout, 'element to be disabled');
|
|
242
|
+
},
|
|
243
|
+
async toBeEditable(options) {
|
|
244
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
245
|
+
const locator = asLocator(received);
|
|
246
|
+
await pollUntil(() => locator.isEditable(), timeout, 'element to be editable');
|
|
247
|
+
},
|
|
248
|
+
async toBeChecked(options) {
|
|
249
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
250
|
+
const locator = asLocator(received);
|
|
251
|
+
await pollUntil(() => locator.isChecked(), timeout, 'element to be checked');
|
|
252
|
+
},
|
|
253
|
+
async toBeFocused(options) {
|
|
254
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
255
|
+
const locator = asLocator(received);
|
|
256
|
+
await pollUntil(async () => {
|
|
257
|
+
// Requires page code execution (gated by security.codeExecution).
|
|
258
|
+
return (await locator.evaluate(() => document.activeElement !== null));
|
|
259
|
+
}, timeout, 'element to be focused');
|
|
260
|
+
},
|
|
261
|
+
async toBeInViewport(options) {
|
|
262
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
263
|
+
const locator = asLocator(received);
|
|
264
|
+
await pollUntil(async () => {
|
|
265
|
+
const box = await locator.boundingBox();
|
|
266
|
+
if (!box)
|
|
267
|
+
return false;
|
|
268
|
+
const inView = (await locator.evaluate((b) => {
|
|
269
|
+
const viewportWidth = window.innerWidth;
|
|
270
|
+
const viewportHeight = window.innerHeight;
|
|
271
|
+
return b.x >= 0 && b.y >= 0 && b.x + b.width <= viewportWidth && b.y + b.height <= viewportHeight;
|
|
272
|
+
}, box));
|
|
273
|
+
return inView;
|
|
274
|
+
}, timeout, 'element to be in the viewport');
|
|
275
|
+
},
|
|
276
|
+
async toHaveText(text, options) {
|
|
277
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
278
|
+
const locator = asLocator(received);
|
|
279
|
+
await pollUntil(async () => {
|
|
280
|
+
const value = await locator.innerText();
|
|
281
|
+
return options?.exact ? value === text : textMatches(value, text);
|
|
282
|
+
}, timeout, `element to have text ${show(text)}`);
|
|
283
|
+
},
|
|
284
|
+
async toContainText(text, options) {
|
|
285
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
286
|
+
const locator = asLocator(received);
|
|
287
|
+
await pollUntil(async () => {
|
|
288
|
+
const value = await locator.innerText();
|
|
289
|
+
return textMatches(value, text);
|
|
290
|
+
}, timeout, `element to contain text ${show(text)}`);
|
|
291
|
+
},
|
|
292
|
+
async toHaveValue(value, options) {
|
|
293
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
294
|
+
const locator = asLocator(received);
|
|
295
|
+
await pollUntil(async () => {
|
|
296
|
+
const current = await locator.inputValue();
|
|
297
|
+
return value instanceof RegExp ? value.test(current) : current === value;
|
|
298
|
+
}, timeout, `element to have value ${show(value)}`);
|
|
299
|
+
},
|
|
300
|
+
async toHaveAttribute(name, expected, options) {
|
|
301
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
302
|
+
const locator = asLocator(received);
|
|
303
|
+
await pollUntil(async () => {
|
|
304
|
+
const current = await locator.getAttribute(name);
|
|
305
|
+
if (current === null)
|
|
306
|
+
return false;
|
|
307
|
+
if (expected === undefined)
|
|
308
|
+
return true;
|
|
309
|
+
return expected instanceof RegExp ? expected.test(current) : current === expected;
|
|
310
|
+
}, timeout, `element to have attribute ${name}${expected === undefined ? '' : `=${show(expected)}`}`);
|
|
311
|
+
},
|
|
312
|
+
async toHaveClass(value, options) {
|
|
313
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
314
|
+
const locator = asLocator(received);
|
|
315
|
+
await pollUntil(async () => {
|
|
316
|
+
const current = await locator.getAttribute('class');
|
|
317
|
+
if (current === null)
|
|
318
|
+
return false;
|
|
319
|
+
return value instanceof RegExp ? value.test(current) : current === value;
|
|
320
|
+
}, timeout, `element to have class ${show(value)}`);
|
|
321
|
+
},
|
|
322
|
+
async toHaveCount(n, options) {
|
|
323
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
324
|
+
const locator = asLocator(received);
|
|
325
|
+
await pollUntil(async () => (await locator.count()) === n, timeout, `element count to be ${n}`);
|
|
326
|
+
},
|
|
327
|
+
async toHaveURL(url, options) {
|
|
328
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
329
|
+
const page = asPage(received);
|
|
330
|
+
await pollUntil(async () => {
|
|
331
|
+
const current = page.url();
|
|
332
|
+
return url instanceof RegExp ? url.test(current) : current === url;
|
|
333
|
+
}, timeout, `page URL to be ${show(url)}`);
|
|
334
|
+
},
|
|
335
|
+
async toHaveTitle(title, options) {
|
|
336
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
337
|
+
const page = asPage(received);
|
|
338
|
+
await pollUntil(async () => {
|
|
339
|
+
const current = await page.title();
|
|
340
|
+
return title instanceof RegExp ? title.test(current) : current === title;
|
|
341
|
+
}, timeout, `page title to be ${show(title)}`);
|
|
342
|
+
},
|
|
343
|
+
async toHaveScreenshot(options) {
|
|
344
|
+
const timeout = options?.timeout ?? currentExpectTimeout();
|
|
345
|
+
const page = asPage(received);
|
|
346
|
+
const baselineDir = screenshotsDir();
|
|
347
|
+
const name = options?.name ?? `${sanitize(receivedTitle())}.png`;
|
|
348
|
+
const baselinePath = joinPath(baselineDir, name);
|
|
349
|
+
await pollUntil(async () => {
|
|
350
|
+
const shot = await page.screenshot();
|
|
351
|
+
if (!existsSync(baselinePath)) {
|
|
352
|
+
writeFileSync(baselinePath, shot.buffer);
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
const comparison = compareScreenshots(shot.buffer, readFileSync(baselinePath), { threshold: options?.threshold });
|
|
356
|
+
return comparison.identical;
|
|
357
|
+
}, timeout, `screenshot to match the baseline ${name}`);
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
// Custom matchers are reachable through the expectation object.
|
|
361
|
+
for (const name of Object.keys(customMatchers)) {
|
|
362
|
+
expectation[name] = (...args) => runCustom(name, received, args);
|
|
363
|
+
}
|
|
364
|
+
return expectation;
|
|
365
|
+
}
|
|
366
|
+
/** Directory for screenshot baselines (set by the runner). */
|
|
367
|
+
let screenshotsDir = () => process.cwd();
|
|
368
|
+
export function setScreenshotsDir(fn) {
|
|
369
|
+
screenshotsDir = fn;
|
|
370
|
+
}
|
|
371
|
+
function receivedTitle() {
|
|
372
|
+
// Best-effort label for the default screenshot name.
|
|
373
|
+
return ambientTestTitle ?? 'screenshot';
|
|
374
|
+
}
|
|
375
|
+
function sanitize(name) {
|
|
376
|
+
return name.replace(/[^a-z0-9._-]+/gi, '-').replace(/^-+|-+$/g, '') || 'screenshot';
|
|
377
|
+
}
|
|
378
|
+
function joinPath(dir, name) {
|
|
379
|
+
return `${dir.replace(/\/$/, '')}/${name}`;
|
|
380
|
+
}
|
|
381
|
+
/** Creates an expectation. Async web matchers are available on the returned object. */
|
|
382
|
+
export function expect(actual) {
|
|
383
|
+
const resolved = actual instanceof Promise ? actual : actual;
|
|
384
|
+
// For promise actuals, generic matchers operate on the promise itself; web matchers
|
|
385
|
+
// require a resolved value, so callers should await first (documented behaviour).
|
|
386
|
+
return createExpectation(resolved, false);
|
|
387
|
+
}
|
|
388
|
+
/** `expect.poll(fn)` — polls an async function until the matcher passes. */
|
|
389
|
+
export function poll(fn, options = {}) {
|
|
390
|
+
const timeout = options.timeout ?? currentExpectTimeout();
|
|
391
|
+
const expectation = createExpectation(undefined, false);
|
|
392
|
+
const wrap = (matcher) => async (...args) => {
|
|
393
|
+
const deadline = Date.now() + timeout;
|
|
394
|
+
let last;
|
|
395
|
+
let lastError;
|
|
396
|
+
while (Date.now() < deadline) {
|
|
397
|
+
try {
|
|
398
|
+
last = (await fn());
|
|
399
|
+
// Temporarily swap the received value to run the matcher.
|
|
400
|
+
const inner = createExpectation(last, false);
|
|
401
|
+
inner[matcher](...args);
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
lastError = error;
|
|
406
|
+
}
|
|
407
|
+
await new Promise((r) => setTimeout(r, options.intervals?.[0] ?? POLL_INTERVAL));
|
|
408
|
+
}
|
|
409
|
+
fail(`expect.poll timed out after ${timeout}ms` + (lastError ? `: ${lastError.message}` : ` (last value: ${show(last)})`));
|
|
410
|
+
};
|
|
411
|
+
// Attach wrapped matchers for the common generic matchers.
|
|
412
|
+
const generic = [
|
|
413
|
+
'toBe',
|
|
414
|
+
'toEqual',
|
|
415
|
+
'toContain',
|
|
416
|
+
'toMatch',
|
|
417
|
+
'toBeTruthy',
|
|
418
|
+
'toBeFalsy',
|
|
419
|
+
'toBeNull',
|
|
420
|
+
'toBeUndefined',
|
|
421
|
+
'toBeDefined',
|
|
422
|
+
'toBeGreaterThan',
|
|
423
|
+
'toBeLessThan',
|
|
424
|
+
'toBeInstanceOf',
|
|
425
|
+
'toHaveLength',
|
|
426
|
+
];
|
|
427
|
+
for (const m of generic) {
|
|
428
|
+
expectation[m] = wrap(m);
|
|
429
|
+
}
|
|
430
|
+
return expectation;
|
|
431
|
+
}
|
|
432
|
+
/** `expect(fn).toPass()` — retries an assertion function until it passes. */
|
|
433
|
+
export async function toPass(fn, options = {}) {
|
|
434
|
+
const timeout = options.timeout ?? currentExpectTimeout();
|
|
435
|
+
const deadline = Date.now() + timeout;
|
|
436
|
+
let lastError;
|
|
437
|
+
while (true) {
|
|
438
|
+
try {
|
|
439
|
+
return await fn();
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
lastError = error;
|
|
443
|
+
if (Date.now() >= deadline) {
|
|
444
|
+
fail(`expect.toPass timed out after ${timeout}ms: ${lastError.message}`);
|
|
445
|
+
}
|
|
446
|
+
await new Promise((r) => setTimeout(r, POLL_INTERVAL));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/** Exposes the expect timeout for the runner. */
|
|
451
|
+
export function getAmbientExpectTimeout() {
|
|
452
|
+
return currentExpectTimeout();
|
|
453
|
+
}
|
|
454
|
+
//# sourceMappingURL=expect.js.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AmB,CAAC,OAAO,EAAE,CAAC,CAAC;YACtF,CAAC;YACD,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;AACH,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,uBAAuB;IACrC,OAAO,oBAAoB,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixture engine: resolves a fixture map with test/worker scopes, dependency
|
|
3
|
+
* injection, teardown and overrides (from `test.use()` and project `use`).
|
|
4
|
+
*
|
|
5
|
+
* A fixture function receives its dependencies and a `use(value)` callback. Code
|
|
6
|
+
* after `await use(value)` runs as teardown when the scope ends.
|
|
7
|
+
*/
|
|
8
|
+
import type { FixtureFn, FixtureMap, FixtureScope } from './types.js';
|
|
9
|
+
export interface FixturePool {
|
|
10
|
+
/** Resolves the fixture named `name` (throws if unknown). */
|
|
11
|
+
resolve<T = unknown>(name: string): Promise<T>;
|
|
12
|
+
/** Releases all test-scoped fixtures (called after each test). */
|
|
13
|
+
teardown(): Promise<void>;
|
|
14
|
+
/** Releases all worker-scoped fixtures (called when the worker exits). */
|
|
15
|
+
dispose(): Promise<void>;
|
|
16
|
+
/** Values currently held (mainly for diagnostics). */
|
|
17
|
+
values(): Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface ActiveFixture {
|
|
20
|
+
name: string;
|
|
21
|
+
scope: FixtureScope;
|
|
22
|
+
fn: FixtureFn<unknown>;
|
|
23
|
+
value: unknown;
|
|
24
|
+
/** True once the fixture body finished providing the value (teardown can run). */
|
|
25
|
+
provided: boolean;
|
|
26
|
+
/** Teardown promise, started when the scope ends. */
|
|
27
|
+
teardownPromise?: Promise<void>;
|
|
28
|
+
/** The fixture body promise (pending until teardown resolves the `use()` promise). */
|
|
29
|
+
bodyPromise?: Promise<void>;
|
|
30
|
+
/** Resolves the `use()` promise, unblocking the fixture body's teardown code. */
|
|
31
|
+
resolveTeardown?: () => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a fixture pool for one test. Worker-scoped fixtures are cached in
|
|
35
|
+
* `workerShared` so they are created once per worker and torn down by `dispose()`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createFixturePool(fixtures: FixtureMap, workerShared: Map<string, ActiveFixture>, overrides?: Record<string, unknown>): FixturePool;
|
|
38
|
+
//# sourceMappingURL=fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../src/fixtures.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAc,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAElF,MAAM,WAAW,WAAW;IAC1B,6DAA6D;IAC7D,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/C,kEAAkE;IAClE,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,0EAA0E;IAC1E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,sDAAsD;IACtD,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,YAAY,CAAC;IACpB,EAAE,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,kFAAkF;IAClF,QAAQ,EAAE,OAAO,CAAC;IAClB,qDAAqD;IACrD,eAAe,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,sFAAsF;IACtF,WAAW,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;CAC9B;AAOD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,WAAW,CA2HtJ"}
|
package/dist/fixtures.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
function normalize(def) {
|
|
2
|
+
if (Array.isArray(def))
|
|
3
|
+
return { scope: def[0], fn: def[1] };
|
|
4
|
+
return { scope: 'test', fn: def };
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Creates a fixture pool for one test. Worker-scoped fixtures are cached in
|
|
8
|
+
* `workerShared` so they are created once per worker and torn down by `dispose()`.
|
|
9
|
+
*/
|
|
10
|
+
export function createFixturePool(fixtures, workerShared, overrides = {}) {
|
|
11
|
+
const testScoped = new Map();
|
|
12
|
+
async function runFixture(name, fn) {
|
|
13
|
+
let providedValue;
|
|
14
|
+
let provided = false;
|
|
15
|
+
// `use()` returns a promise that resolves only when the scope ends, so the
|
|
16
|
+
// code after `await use(value)` in the fixture body runs as teardown.
|
|
17
|
+
let resolveTeardown;
|
|
18
|
+
let resolveProvided;
|
|
19
|
+
const usePromise = new Promise((res) => {
|
|
20
|
+
resolveTeardown = res;
|
|
21
|
+
});
|
|
22
|
+
const providedPromise = new Promise((res) => {
|
|
23
|
+
resolveProvided = res;
|
|
24
|
+
});
|
|
25
|
+
const use = (value) => {
|
|
26
|
+
provided = true;
|
|
27
|
+
providedValue = value;
|
|
28
|
+
resolveProvided?.();
|
|
29
|
+
return usePromise;
|
|
30
|
+
};
|
|
31
|
+
// Lazy dependency proxy: each dependency is resolved on first access, so a
|
|
32
|
+
// fixture only pays for the fixtures it actually uses.
|
|
33
|
+
const depsCache = {};
|
|
34
|
+
const deps = new Proxy(depsCache, {
|
|
35
|
+
get(_target, prop) {
|
|
36
|
+
if (typeof prop !== 'string')
|
|
37
|
+
return undefined;
|
|
38
|
+
if (Object.prototype.hasOwnProperty.call(depsCache, prop))
|
|
39
|
+
return depsCache[prop];
|
|
40
|
+
if (prop === name || Object.prototype.hasOwnProperty.call(overrides, prop)) {
|
|
41
|
+
return overrides[prop];
|
|
42
|
+
}
|
|
43
|
+
const def = fixtures[prop];
|
|
44
|
+
if (def === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
const p = resolve(prop);
|
|
47
|
+
depsCache[prop] = p;
|
|
48
|
+
return p;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
let bodyError;
|
|
52
|
+
const bodyPromise = (async () => {
|
|
53
|
+
try {
|
|
54
|
+
await fn(deps, use);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
bodyError = error;
|
|
58
|
+
}
|
|
59
|
+
})();
|
|
60
|
+
// Wait until the fixture has called use() (or thrown before it). The body
|
|
61
|
+
// stays suspended at `await use(value)` until teardown resolves the promise.
|
|
62
|
+
await Promise.race([providedPromise, bodyPromise]);
|
|
63
|
+
if (!provided) {
|
|
64
|
+
if (bodyError)
|
|
65
|
+
throw bodyError;
|
|
66
|
+
throw new Error(`Fixture "${name}" never called use()`);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
name,
|
|
70
|
+
scope: normalize(fixtures[name]).scope,
|
|
71
|
+
fn,
|
|
72
|
+
value: providedValue,
|
|
73
|
+
provided: true,
|
|
74
|
+
bodyPromise,
|
|
75
|
+
resolveTeardown: resolveTeardown,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async function resolve(name) {
|
|
79
|
+
if (Object.prototype.hasOwnProperty.call(overrides, name)) {
|
|
80
|
+
return overrides[name];
|
|
81
|
+
}
|
|
82
|
+
const def = fixtures[name];
|
|
83
|
+
if (def === undefined) {
|
|
84
|
+
throw new Error(`Unknown fixture "${name}". Declare it with test.extend({ ${name}: ... }) or override it with test.use().`);
|
|
85
|
+
}
|
|
86
|
+
if (typeof def !== 'function' && !Array.isArray(def)) {
|
|
87
|
+
throw new Error(`Fixture "${name}" has an invalid definition. Use test.extend({ ${name}: (deps, use) => ... }) or override it with test.use().`);
|
|
88
|
+
}
|
|
89
|
+
const { scope, fn } = normalize(def);
|
|
90
|
+
if (scope === 'worker') {
|
|
91
|
+
const existing = workerShared.get(name);
|
|
92
|
+
if (existing)
|
|
93
|
+
return existing.value;
|
|
94
|
+
const active = await runFixture(name, fn);
|
|
95
|
+
workerShared.set(name, active);
|
|
96
|
+
return active.value;
|
|
97
|
+
}
|
|
98
|
+
const existing = testScoped.get(name);
|
|
99
|
+
if (existing)
|
|
100
|
+
return existing.value;
|
|
101
|
+
const active = await runFixture(name, fn);
|
|
102
|
+
testScoped.set(name, active);
|
|
103
|
+
return active.value;
|
|
104
|
+
}
|
|
105
|
+
async function runTeardown(fixture) {
|
|
106
|
+
if (fixture.teardownPromise)
|
|
107
|
+
return fixture.teardownPromise;
|
|
108
|
+
fixture.teardownPromise = (async () => {
|
|
109
|
+
// Resolve the use() promise: the fixture body's code after `await use(value)`
|
|
110
|
+
// now runs as teardown.
|
|
111
|
+
fixture.resolveTeardown?.();
|
|
112
|
+
await fixture.bodyPromise;
|
|
113
|
+
})();
|
|
114
|
+
return fixture.teardownPromise;
|
|
115
|
+
}
|
|
116
|
+
async function teardown() {
|
|
117
|
+
const entries = [...testScoped.values()].reverse();
|
|
118
|
+
testScoped.clear();
|
|
119
|
+
await Promise.all(entries.map((f) => runTeardown(f)));
|
|
120
|
+
}
|
|
121
|
+
async function dispose() {
|
|
122
|
+
await teardown();
|
|
123
|
+
const entries = [...workerShared.values()];
|
|
124
|
+
workerShared.clear();
|
|
125
|
+
await Promise.all(entries.map((f) => runTeardown(f)));
|
|
126
|
+
}
|
|
127
|
+
function values() {
|
|
128
|
+
return {
|
|
129
|
+
...Object.fromEntries([...workerShared.values()].map((f) => [f.name, f.value])),
|
|
130
|
+
...Object.fromEntries([...testScoped.values()].map((f) => [f.name, f.value])),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return { resolve, teardown, dispose, values };
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=fixtures.js.map
|