| 1 | import { test } from "@playwright/test"; |
| 2 | import { installTailwindNodeCompat } from "./TailwindNodeCompat.ts"; |
| 3 | import * as Exit from "effect/Exit"; |
| 4 | import * as ManagedRuntime from "effect/ManagedRuntime"; |
| 5 | import * as Scope from "effect/Scope"; |
| 6 | import * as Runtime from "./Runtime.ts"; |
| 7 | import * as Server from "./Server.ts"; |
| 8 | |
| 9 | // Guard every playwright worker process before vite can load tailwind. |
| 10 | installTailwindNodeCompat(); |
| 11 | |
| 12 | export const SERVER_METHODS = ["live", "dev"] as const; |
| 13 | export type ServerMethod = (typeof SERVER_METHODS)[number]; |
| 14 | |
| 15 | export const make = (method: ServerMethod) => |
| 16 | test.extend<{}, { readonly server: Server.Instance }>({ |
| 17 | server: [ |
| 18 | // oxlint-disable-next-line no-empty-pattern |
| 19 | async ({}, use) => { |
| 20 | const harness = await makeServerInstance(method); |
| 21 | await use(harness); |
| 22 | await harness.dispose(); |
| 23 | }, |
| 24 | { scope: "worker" }, |
| 25 | ], |
| 26 | }); |
| 27 | |
| 28 | const makeServerInstance = async (method: ServerMethod) => { |
| 29 | const scope = Scope.makeUnsafe(); |
| 30 | const runtime = ManagedRuntime.make(Runtime.layer); |
| 31 | const instance = await runtime.runPromise( |
| 32 | Server.Server.use((server) => server[method]()).pipe(Scope.provide(scope)), |
| 33 | ); |
| 34 | return { |
| 35 | ...instance, |
| 36 | dispose: () => runtime.runPromise(Scope.close(scope, Exit.void)), |
| 37 | }; |
| 38 | }; |