1import { test } from "@playwright/test";
2import { installTailwindNodeCompat } from "./TailwindNodeCompat.ts";
3import * as Exit from "effect/Exit";
4import * as ManagedRuntime from "effect/ManagedRuntime";
5import * as Scope from "effect/Scope";
6import * as Runtime from "./Runtime.ts";
7import * as Server from "./Server.ts";
8
9// Guard every playwright worker process before vite can load tailwind.
10installTailwindNodeCompat();
11
12export const SERVER_METHODS = ["live", "dev"] as const;
13export type ServerMethod = (typeof SERVER_METHODS)[number];
14
15export 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
28const 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};