@ricsam/isolate-playwright 0.0.1 → 0.1.2

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.
@@ -0,0 +1,693 @@
1
+ // @bun
2
+ // packages/playwright/src/index.ts
3
+ import ivm from "isolated-vm";
4
+ var KNOWN_ERROR_TYPES = [
5
+ "TypeError",
6
+ "RangeError",
7
+ "SyntaxError",
8
+ "ReferenceError",
9
+ "URIError",
10
+ "EvalError",
11
+ "TimeoutError"
12
+ ];
13
+ function getErrorConstructorName(errorType) {
14
+ return KNOWN_ERROR_TYPES.includes(errorType) ? errorType : "Error";
15
+ }
16
+ function encodeErrorForTransfer(err) {
17
+ const errorType = getErrorConstructorName(err.name);
18
+ return new Error(`[${errorType}]${err.message}`);
19
+ }
20
+ var DECODE_ERROR_JS = `
21
+ function __decodeError(err) {
22
+ if (!(err instanceof Error)) return err;
23
+ const match = err.message.match(/^\\[(TypeError|RangeError|SyntaxError|ReferenceError|URIError|EvalError|TimeoutError|Error)\\](.*)$/);
24
+ if (match) {
25
+ const ErrorType = globalThis[match[1]] || Error;
26
+ return new ErrorType(match[2]);
27
+ }
28
+ return err;
29
+ }
30
+ `.trim();
31
+ function getLocator(page, selectorType, selectorValue, roleOptionsJson) {
32
+ switch (selectorType) {
33
+ case "css":
34
+ return page.locator(selectorValue);
35
+ case "role": {
36
+ const roleOptions = roleOptionsJson ? JSON.parse(roleOptionsJson) : undefined;
37
+ return page.getByRole(selectorValue, roleOptions);
38
+ }
39
+ case "text":
40
+ return page.getByText(selectorValue);
41
+ case "label":
42
+ return page.getByLabel(selectorValue);
43
+ case "placeholder":
44
+ return page.getByPlaceholder(selectorValue);
45
+ case "testId":
46
+ return page.getByTestId(selectorValue);
47
+ default:
48
+ return page.locator(selectorValue);
49
+ }
50
+ }
51
+ async function setupPlaywright(context, options) {
52
+ const { page, timeout = 30000, baseUrl } = options;
53
+ const consoleLogs = [];
54
+ const networkRequests = [];
55
+ const networkResponses = [];
56
+ const global = context.global;
57
+ const requestHandler = (request) => {
58
+ const info = {
59
+ url: request.url(),
60
+ method: request.method(),
61
+ headers: request.headers(),
62
+ postData: request.postData() ?? undefined,
63
+ resourceType: request.resourceType(),
64
+ timestamp: Date.now()
65
+ };
66
+ networkRequests.push(info);
67
+ options.onNetworkRequest?.(info);
68
+ };
69
+ const responseHandler = (response) => {
70
+ const info = {
71
+ url: response.url(),
72
+ status: response.status(),
73
+ statusText: response.statusText(),
74
+ headers: response.headers(),
75
+ timestamp: Date.now()
76
+ };
77
+ networkResponses.push(info);
78
+ options.onNetworkResponse?.(info);
79
+ };
80
+ const consoleHandler = (msg) => {
81
+ const entry = {
82
+ level: msg.type(),
83
+ args: msg.args().map((arg) => String(arg)),
84
+ timestamp: Date.now()
85
+ };
86
+ consoleLogs.push(entry);
87
+ options.onConsoleLog?.(entry.level, ...entry.args);
88
+ };
89
+ page.on("request", requestHandler);
90
+ page.on("response", responseHandler);
91
+ page.on("console", consoleHandler);
92
+ global.setSync("__Playwright_goto_ref", new ivm.Reference(async (url, waitUntil) => {
93
+ try {
94
+ const targetUrl = baseUrl && !url.startsWith("http") ? `${baseUrl}${url}` : url;
95
+ await page.goto(targetUrl, {
96
+ timeout,
97
+ waitUntil: waitUntil ?? "load"
98
+ });
99
+ } catch (err) {
100
+ if (err instanceof Error) {
101
+ throw encodeErrorForTransfer(err);
102
+ }
103
+ throw err;
104
+ }
105
+ }));
106
+ global.setSync("__Playwright_reload_ref", new ivm.Reference(async () => {
107
+ try {
108
+ await page.reload({ timeout });
109
+ } catch (err) {
110
+ if (err instanceof Error) {
111
+ throw encodeErrorForTransfer(err);
112
+ }
113
+ throw err;
114
+ }
115
+ }));
116
+ global.setSync("__Playwright_url", new ivm.Callback(() => {
117
+ return page.url();
118
+ }));
119
+ global.setSync("__Playwright_title_ref", new ivm.Reference(async () => {
120
+ try {
121
+ return await page.title();
122
+ } catch (err) {
123
+ if (err instanceof Error) {
124
+ throw encodeErrorForTransfer(err);
125
+ }
126
+ throw err;
127
+ }
128
+ }));
129
+ global.setSync("__Playwright_content_ref", new ivm.Reference(async () => {
130
+ try {
131
+ return await page.content();
132
+ } catch (err) {
133
+ if (err instanceof Error) {
134
+ throw encodeErrorForTransfer(err);
135
+ }
136
+ throw err;
137
+ }
138
+ }));
139
+ global.setSync("__Playwright_waitForSelector_ref", new ivm.Reference(async (selector, optionsJson) => {
140
+ try {
141
+ const opts = optionsJson ? JSON.parse(optionsJson) : {};
142
+ await page.waitForSelector(selector, { timeout, ...opts });
143
+ } catch (err) {
144
+ if (err instanceof Error) {
145
+ throw encodeErrorForTransfer(err);
146
+ }
147
+ throw err;
148
+ }
149
+ }));
150
+ global.setSync("__Playwright_waitForTimeout_ref", new ivm.Reference(async (ms) => {
151
+ try {
152
+ await page.waitForTimeout(ms);
153
+ } catch (err) {
154
+ if (err instanceof Error) {
155
+ throw encodeErrorForTransfer(err);
156
+ }
157
+ throw err;
158
+ }
159
+ }));
160
+ global.setSync("__Playwright_waitForLoadState_ref", new ivm.Reference(async (state) => {
161
+ try {
162
+ await page.waitForLoadState(state ?? "load", { timeout });
163
+ } catch (err) {
164
+ if (err instanceof Error) {
165
+ throw encodeErrorForTransfer(err);
166
+ }
167
+ throw err;
168
+ }
169
+ }));
170
+ global.setSync("__Playwright_evaluate_ref", new ivm.Reference(async (script) => {
171
+ try {
172
+ const result = await page.evaluate(script);
173
+ return JSON.stringify(result);
174
+ } catch (err) {
175
+ if (err instanceof Error) {
176
+ throw encodeErrorForTransfer(err);
177
+ }
178
+ throw err;
179
+ }
180
+ }));
181
+ global.setSync("__Playwright_locatorAction_ref", new ivm.Reference(async (selectorType, selectorValue, roleOptionsJson, action, actionArg) => {
182
+ try {
183
+ const locator = getLocator(page, selectorType, selectorValue, roleOptionsJson);
184
+ switch (action) {
185
+ case "click":
186
+ await locator.click({ timeout });
187
+ return null;
188
+ case "dblclick":
189
+ await locator.dblclick({ timeout });
190
+ return null;
191
+ case "fill":
192
+ await locator.fill(actionArg ?? "", { timeout });
193
+ return null;
194
+ case "type":
195
+ await locator.pressSequentially(actionArg ?? "", { timeout });
196
+ return null;
197
+ case "check":
198
+ await locator.check({ timeout });
199
+ return null;
200
+ case "uncheck":
201
+ await locator.uncheck({ timeout });
202
+ return null;
203
+ case "selectOption":
204
+ await locator.selectOption(actionArg ?? "", { timeout });
205
+ return null;
206
+ case "clear":
207
+ await locator.clear({ timeout });
208
+ return null;
209
+ case "press":
210
+ await locator.press(actionArg ?? "", { timeout });
211
+ return null;
212
+ case "hover":
213
+ await locator.hover({ timeout });
214
+ return null;
215
+ case "focus":
216
+ await locator.focus({ timeout });
217
+ return null;
218
+ case "getText":
219
+ return await locator.textContent({ timeout });
220
+ case "getValue":
221
+ return await locator.inputValue({ timeout });
222
+ case "isVisible":
223
+ return await locator.isVisible();
224
+ case "isEnabled":
225
+ return await locator.isEnabled();
226
+ case "isChecked":
227
+ return await locator.isChecked();
228
+ case "count":
229
+ return await locator.count();
230
+ default:
231
+ throw new Error(`Unknown action: ${action}`);
232
+ }
233
+ } catch (err) {
234
+ if (err instanceof Error) {
235
+ throw encodeErrorForTransfer(err);
236
+ }
237
+ throw err;
238
+ }
239
+ }));
240
+ global.setSync("__Playwright_expectVisible_ref", new ivm.Reference(async (selectorType, selectorValue, roleOptionsJson, not) => {
241
+ try {
242
+ const locator = getLocator(page, selectorType, selectorValue, roleOptionsJson);
243
+ const isVisible = await locator.isVisible();
244
+ if (not) {
245
+ if (isVisible) {
246
+ throw new Error(`Expected element to not be visible, but it was visible`);
247
+ }
248
+ } else {
249
+ if (!isVisible) {
250
+ throw new Error(`Expected element to be visible, but it was not`);
251
+ }
252
+ }
253
+ } catch (err) {
254
+ if (err instanceof Error) {
255
+ throw encodeErrorForTransfer(err);
256
+ }
257
+ throw err;
258
+ }
259
+ }));
260
+ global.setSync("__Playwright_expectText_ref", new ivm.Reference(async (selectorType, selectorValue, roleOptionsJson, expected, not) => {
261
+ try {
262
+ const locator = getLocator(page, selectorType, selectorValue, roleOptionsJson);
263
+ const text = await locator.textContent({ timeout });
264
+ const matches = text?.includes(expected) ?? false;
265
+ if (not) {
266
+ if (matches) {
267
+ throw new Error(`Expected text to not contain "${expected}", but got "${text}"`);
268
+ }
269
+ } else {
270
+ if (!matches) {
271
+ throw new Error(`Expected text to contain "${expected}", but got "${text}"`);
272
+ }
273
+ }
274
+ } catch (err) {
275
+ if (err instanceof Error) {
276
+ throw encodeErrorForTransfer(err);
277
+ }
278
+ throw err;
279
+ }
280
+ }));
281
+ global.setSync("__Playwright_expectValue_ref", new ivm.Reference(async (selectorType, selectorValue, roleOptionsJson, expected, not) => {
282
+ try {
283
+ const locator = getLocator(page, selectorType, selectorValue, roleOptionsJson);
284
+ const value = await locator.inputValue({ timeout });
285
+ const matches = value === expected;
286
+ if (not) {
287
+ if (matches) {
288
+ throw new Error(`Expected value to not be "${expected}", but it was`);
289
+ }
290
+ } else {
291
+ if (!matches) {
292
+ throw new Error(`Expected value to be "${expected}", but got "${value}"`);
293
+ }
294
+ }
295
+ } catch (err) {
296
+ if (err instanceof Error) {
297
+ throw encodeErrorForTransfer(err);
298
+ }
299
+ throw err;
300
+ }
301
+ }));
302
+ global.setSync("__Playwright_expectEnabled_ref", new ivm.Reference(async (selectorType, selectorValue, roleOptionsJson, not) => {
303
+ try {
304
+ const locator = getLocator(page, selectorType, selectorValue, roleOptionsJson);
305
+ const isEnabled = await locator.isEnabled();
306
+ if (not) {
307
+ if (isEnabled) {
308
+ throw new Error(`Expected element to be disabled, but it was enabled`);
309
+ }
310
+ } else {
311
+ if (!isEnabled) {
312
+ throw new Error(`Expected element to be enabled, but it was disabled`);
313
+ }
314
+ }
315
+ } catch (err) {
316
+ if (err instanceof Error) {
317
+ throw encodeErrorForTransfer(err);
318
+ }
319
+ throw err;
320
+ }
321
+ }));
322
+ global.setSync("__Playwright_expectChecked_ref", new ivm.Reference(async (selectorType, selectorValue, roleOptionsJson, not) => {
323
+ try {
324
+ const locator = getLocator(page, selectorType, selectorValue, roleOptionsJson);
325
+ const isChecked = await locator.isChecked();
326
+ if (not) {
327
+ if (isChecked) {
328
+ throw new Error(`Expected element to not be checked, but it was checked`);
329
+ }
330
+ } else {
331
+ if (!isChecked) {
332
+ throw new Error(`Expected element to be checked, but it was not`);
333
+ }
334
+ }
335
+ } catch (err) {
336
+ if (err instanceof Error) {
337
+ throw encodeErrorForTransfer(err);
338
+ }
339
+ throw err;
340
+ }
341
+ }));
342
+ context.evalSync(DECODE_ERROR_JS);
343
+ context.evalSync(`
344
+ (function() {
345
+ const tests = [];
346
+ globalThis.test = (name, fn) => tests.push({ name, fn });
347
+
348
+ globalThis.__runPlaywrightTests = async () => {
349
+ const results = [];
350
+ for (const t of tests) {
351
+ const start = Date.now();
352
+ try {
353
+ await t.fn();
354
+ results.push({ name: t.name, passed: true, duration: Date.now() - start });
355
+ } catch (err) {
356
+ results.push({ name: t.name, passed: false, error: err.message, duration: Date.now() - start });
357
+ }
358
+ }
359
+ const passed = results.filter(r => r.passed).length;
360
+ const failed = results.filter(r => !r.passed).length;
361
+ return JSON.stringify({ passed, failed, total: results.length, results });
362
+ };
363
+
364
+ globalThis.__resetPlaywrightTests = () => { tests.length = 0; };
365
+ })();
366
+ `);
367
+ context.evalSync(`
368
+ (function() {
369
+ globalThis.page = {
370
+ async goto(url, options) {
371
+ try {
372
+ return __Playwright_goto_ref.applySyncPromise(undefined, [url, options?.waitUntil || null]);
373
+ } catch (err) { throw __decodeError(err); }
374
+ },
375
+ async reload() {
376
+ try {
377
+ return __Playwright_reload_ref.applySyncPromise(undefined, []);
378
+ } catch (err) { throw __decodeError(err); }
379
+ },
380
+ url() { return __Playwright_url(); },
381
+ async title() {
382
+ try {
383
+ return __Playwright_title_ref.applySyncPromise(undefined, []);
384
+ } catch (err) { throw __decodeError(err); }
385
+ },
386
+ async content() {
387
+ try {
388
+ return __Playwright_content_ref.applySyncPromise(undefined, []);
389
+ } catch (err) { throw __decodeError(err); }
390
+ },
391
+ async waitForSelector(selector, options) {
392
+ try {
393
+ return __Playwright_waitForSelector_ref.applySyncPromise(undefined, [selector, options ? JSON.stringify(options) : null]);
394
+ } catch (err) { throw __decodeError(err); }
395
+ },
396
+ async waitForTimeout(ms) {
397
+ try {
398
+ return __Playwright_waitForTimeout_ref.applySyncPromise(undefined, [ms]);
399
+ } catch (err) { throw __decodeError(err); }
400
+ },
401
+ async waitForLoadState(state) {
402
+ try {
403
+ return __Playwright_waitForLoadState_ref.applySyncPromise(undefined, [state]);
404
+ } catch (err) { throw __decodeError(err); }
405
+ },
406
+ async evaluate(script) {
407
+ try {
408
+ const resultJson = __Playwright_evaluate_ref.applySyncPromise(undefined, [script]);
409
+ return resultJson ? JSON.parse(resultJson) : undefined;
410
+ } catch (err) { throw __decodeError(err); }
411
+ },
412
+ locator(selector) { return new Locator("css", selector, null); },
413
+ getByRole(role, options) { return new Locator("role", role, options ? JSON.stringify(options) : null); },
414
+ getByText(text) { return new Locator("text", text, null); },
415
+ getByLabel(label) { return new Locator("label", label, null); },
416
+ getByPlaceholder(p) { return new Locator("placeholder", p, null); },
417
+ getByTestId(id) { return new Locator("testId", id, null); },
418
+ };
419
+ })();
420
+ `);
421
+ context.evalSync(`
422
+ (function() {
423
+ class Locator {
424
+ #type; #value; #options;
425
+ constructor(type, value, options) {
426
+ this.#type = type;
427
+ this.#value = value;
428
+ this.#options = options;
429
+ }
430
+
431
+ _getInfo() { return [this.#type, this.#value, this.#options]; }
432
+
433
+ async click() {
434
+ try {
435
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "click", null]);
436
+ } catch (err) { throw __decodeError(err); }
437
+ }
438
+
439
+ async dblclick() {
440
+ try {
441
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "dblclick", null]);
442
+ } catch (err) { throw __decodeError(err); }
443
+ }
444
+
445
+ async fill(text) {
446
+ try {
447
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "fill", text]);
448
+ } catch (err) { throw __decodeError(err); }
449
+ }
450
+
451
+ async type(text) {
452
+ try {
453
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "type", text]);
454
+ } catch (err) { throw __decodeError(err); }
455
+ }
456
+
457
+ async check() {
458
+ try {
459
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "check", null]);
460
+ } catch (err) { throw __decodeError(err); }
461
+ }
462
+
463
+ async uncheck() {
464
+ try {
465
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "uncheck", null]);
466
+ } catch (err) { throw __decodeError(err); }
467
+ }
468
+
469
+ async selectOption(value) {
470
+ try {
471
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "selectOption", value]);
472
+ } catch (err) { throw __decodeError(err); }
473
+ }
474
+
475
+ async clear() {
476
+ try {
477
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "clear", null]);
478
+ } catch (err) { throw __decodeError(err); }
479
+ }
480
+
481
+ async press(key) {
482
+ try {
483
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "press", key]);
484
+ } catch (err) { throw __decodeError(err); }
485
+ }
486
+
487
+ async hover() {
488
+ try {
489
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "hover", null]);
490
+ } catch (err) { throw __decodeError(err); }
491
+ }
492
+
493
+ async focus() {
494
+ try {
495
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "focus", null]);
496
+ } catch (err) { throw __decodeError(err); }
497
+ }
498
+
499
+ async textContent() {
500
+ try {
501
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "getText", null]);
502
+ } catch (err) { throw __decodeError(err); }
503
+ }
504
+
505
+ async inputValue() {
506
+ try {
507
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "getValue", null]);
508
+ } catch (err) { throw __decodeError(err); }
509
+ }
510
+
511
+ async isVisible() {
512
+ try {
513
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "isVisible", null]);
514
+ } catch (err) { throw __decodeError(err); }
515
+ }
516
+
517
+ async isEnabled() {
518
+ try {
519
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "isEnabled", null]);
520
+ } catch (err) { throw __decodeError(err); }
521
+ }
522
+
523
+ async isChecked() {
524
+ try {
525
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "isChecked", null]);
526
+ } catch (err) { throw __decodeError(err); }
527
+ }
528
+
529
+ async count() {
530
+ try {
531
+ return __Playwright_locatorAction_ref.applySyncPromise(undefined, [...this._getInfo(), "count", null]);
532
+ } catch (err) { throw __decodeError(err); }
533
+ }
534
+ }
535
+ globalThis.Locator = Locator;
536
+ })();
537
+ `);
538
+ context.evalSync(`
539
+ (function() {
540
+ globalThis.expect = (actual) => {
541
+ if (actual instanceof Locator) {
542
+ const info = actual._getInfo();
543
+ return {
544
+ async toBeVisible() {
545
+ try {
546
+ await __Playwright_expectVisible_ref.applySyncPromise(undefined, [...info, false]);
547
+ } catch (err) { throw __decodeError(err); }
548
+ },
549
+ async toContainText(expected) {
550
+ try {
551
+ await __Playwright_expectText_ref.applySyncPromise(undefined, [...info, expected, false]);
552
+ } catch (err) { throw __decodeError(err); }
553
+ },
554
+ async toHaveValue(expected) {
555
+ try {
556
+ await __Playwright_expectValue_ref.applySyncPromise(undefined, [...info, expected, false]);
557
+ } catch (err) { throw __decodeError(err); }
558
+ },
559
+ async toBeEnabled() {
560
+ try {
561
+ await __Playwright_expectEnabled_ref.applySyncPromise(undefined, [...info, false]);
562
+ } catch (err) { throw __decodeError(err); }
563
+ },
564
+ async toBeChecked() {
565
+ try {
566
+ await __Playwright_expectChecked_ref.applySyncPromise(undefined, [...info, false]);
567
+ } catch (err) { throw __decodeError(err); }
568
+ },
569
+ not: {
570
+ async toBeVisible() {
571
+ try {
572
+ await __Playwright_expectVisible_ref.applySyncPromise(undefined, [...info, true]);
573
+ } catch (err) { throw __decodeError(err); }
574
+ },
575
+ async toContainText(expected) {
576
+ try {
577
+ await __Playwright_expectText_ref.applySyncPromise(undefined, [...info, expected, true]);
578
+ } catch (err) { throw __decodeError(err); }
579
+ },
580
+ async toHaveValue(expected) {
581
+ try {
582
+ await __Playwright_expectValue_ref.applySyncPromise(undefined, [...info, expected, true]);
583
+ } catch (err) { throw __decodeError(err); }
584
+ },
585
+ async toBeEnabled() {
586
+ try {
587
+ await __Playwright_expectEnabled_ref.applySyncPromise(undefined, [...info, true]);
588
+ } catch (err) { throw __decodeError(err); }
589
+ },
590
+ async toBeChecked() {
591
+ try {
592
+ await __Playwright_expectChecked_ref.applySyncPromise(undefined, [...info, true]);
593
+ } catch (err) { throw __decodeError(err); }
594
+ },
595
+ },
596
+ };
597
+ }
598
+ // Fallback: basic matchers for primitives
599
+ return {
600
+ toBe(expected) {
601
+ if (actual !== expected) throw new Error(\`Expected \${JSON.stringify(actual)} to be \${JSON.stringify(expected)}\`);
602
+ },
603
+ toEqual(expected) {
604
+ if (JSON.stringify(actual) !== JSON.stringify(expected)) {
605
+ throw new Error(\`Expected \${JSON.stringify(actual)} to equal \${JSON.stringify(expected)}\`);
606
+ }
607
+ },
608
+ toBeTruthy() {
609
+ if (!actual) throw new Error(\`Expected \${JSON.stringify(actual)} to be truthy\`);
610
+ },
611
+ toBeFalsy() {
612
+ if (actual) throw new Error(\`Expected \${JSON.stringify(actual)} to be falsy\`);
613
+ },
614
+ toContain(expected) {
615
+ if (typeof actual === 'string' && !actual.includes(expected)) {
616
+ throw new Error(\`Expected "\${actual}" to contain "\${expected}"\`);
617
+ }
618
+ if (Array.isArray(actual) && !actual.includes(expected)) {
619
+ throw new Error(\`Expected array to contain \${JSON.stringify(expected)}\`);
620
+ }
621
+ },
622
+ not: {
623
+ toBe(expected) {
624
+ if (actual === expected) throw new Error(\`Expected \${JSON.stringify(actual)} to not be \${JSON.stringify(expected)}\`);
625
+ },
626
+ toEqual(expected) {
627
+ if (JSON.stringify(actual) === JSON.stringify(expected)) {
628
+ throw new Error(\`Expected \${JSON.stringify(actual)} to not equal \${JSON.stringify(expected)}\`);
629
+ }
630
+ },
631
+ toBeTruthy() {
632
+ if (actual) throw new Error(\`Expected \${JSON.stringify(actual)} to not be truthy\`);
633
+ },
634
+ toBeFalsy() {
635
+ if (!actual) throw new Error(\`Expected \${JSON.stringify(actual)} to not be falsy\`);
636
+ },
637
+ toContain(expected) {
638
+ if (typeof actual === 'string' && actual.includes(expected)) {
639
+ throw new Error(\`Expected "\${actual}" to not contain "\${expected}"\`);
640
+ }
641
+ if (Array.isArray(actual) && actual.includes(expected)) {
642
+ throw new Error(\`Expected array to not contain \${JSON.stringify(expected)}\`);
643
+ }
644
+ },
645
+ },
646
+ };
647
+ };
648
+ })();
649
+ `);
650
+ return {
651
+ dispose() {
652
+ page.off("request", requestHandler);
653
+ page.off("response", responseHandler);
654
+ page.off("console", consoleHandler);
655
+ consoleLogs.length = 0;
656
+ networkRequests.length = 0;
657
+ networkResponses.length = 0;
658
+ },
659
+ getConsoleLogs() {
660
+ return [...consoleLogs];
661
+ },
662
+ getNetworkRequests() {
663
+ return [...networkRequests];
664
+ },
665
+ getNetworkResponses() {
666
+ return [...networkResponses];
667
+ },
668
+ clearCollected() {
669
+ consoleLogs.length = 0;
670
+ networkRequests.length = 0;
671
+ networkResponses.length = 0;
672
+ }
673
+ };
674
+ }
675
+ async function runPlaywrightTests(context) {
676
+ const runTestsRef = context.global.getSync("__runPlaywrightTests", {
677
+ reference: true
678
+ });
679
+ const resultJson = await runTestsRef.apply(undefined, [], {
680
+ result: { promise: true }
681
+ });
682
+ return JSON.parse(resultJson);
683
+ }
684
+ async function resetPlaywrightTests(context) {
685
+ context.evalSync("__resetPlaywrightTests()");
686
+ }
687
+ export {
688
+ setupPlaywright,
689
+ runPlaywrightTests,
690
+ resetPlaywrightTests
691
+ };
692
+
693
+ //# debugId=402D5D86BA4CC3C564756E2164756E21