Open History to see the last commit
1import { it as effectIt } from "@effect/vitest";
2import * as Effect from "effect/Effect";
3import { describe, expect } from "vite-plus/test";
4
5import {
6 extractPlaywrightInjectedRuntimeSource,
7 playwrightInjectedRuntimeInstallExpression,
8 playwrightInjectedRuntimeSource,
9} from "./PlaywrightInjectedRuntime.ts";
10
11const bundleWithSourceLiteral = (literal: string): string =>
12 `const source3 = ${literal};\n }\n});`;
13
14describe("playwright injected runtime", () => {
15 effectIt.effect("extracts the pinned runtime from playwright-core", () =>
16 Effect.gen(function* () {
17 const source = yield* playwrightInjectedRuntimeSource();
18 expect(source.length).toBeGreaterThan(100_000);
19 expect(source).toContain("InjectedScript");
20 }),
21 );
22
23 effectIt.effect("builds an idempotent install expression", () =>
24 Effect.gen(function* () {
25 const expression = yield* playwrightInjectedRuntimeInstallExpression();
26 expect(expression).toContain("__t3PlaywrightInjected");
27 expect(expression).toContain('testIdAttributeName":"data-testid');
28 }),
29 );
30
31 effectIt.effect("reports a missing source marker without an artificial cause", () =>
32 Effect.gen(function* () {
33 const error = yield* Effect.flip(
34 extractPlaywrightInjectedRuntimeSource("const source = 'missing';", "/tmp/coreBundle.js"),
35 );
36
37 expect(error).toMatchObject({
38 _tag: "PlaywrightSourceMarkerNotFoundError",
39 bundlePath: "/tmp/coreBundle.js",
40 marker: "source3 = ",
41 });
42 expect("cause" in error).toBe(false);
43 }),
44 );
45
46 effectIt.effect("keeps source validation metadata cause-free", () =>
47 Effect.gen(function* () {
48 const error = yield* Effect.flip(
49 extractPlaywrightInjectedRuntimeSource(
50 bundleWithSourceLiteral('"short"'),
51 "/tmp/coreBundle.js",
52 ),
53 );
54
55 expect(error).toMatchObject({
56 _tag: "PlaywrightSourceValidationError",
57 bundlePath: "/tmp/coreBundle.js",
58 actualType: "string",
59 actualLength: 5,
60 minimumLength: 100_000,
61 });
62 expect("cause" in error).toBe(false);
63 }),
64 );
65
66 effectIt.effect("preserves the source evaluation cause", () =>
67 Effect.gen(function* () {
68 const error = yield* Effect.flip(
69 extractPlaywrightInjectedRuntimeSource(bundleWithSourceLiteral("("), "/tmp/coreBundle.js"),
70 );
71
72 expect(error).toMatchObject({
73 _tag: "PlaywrightSourceEvaluationError",
74 bundlePath: "/tmp/coreBundle.js",
75 timeoutMs: 1_000,
76 cause: expect.objectContaining({ name: "SyntaxError" }),
77 });
78 }),
79 );
80});