1import * as Effect from "effect/Effect";
2import * as FileSystem from "effect/FileSystem";
3import * as Path from "effect/Path";
4import * as Schedule from "effect/Schedule";
5import * as HttpClient from "effect/http/HttpClient";
6
7export const copyViteFixture = Effect.gen(function* () {
8 const fs = yield* FileSystem.FileSystem;
9 const path = yield* Path.Path;
10 const source = yield* path.fromFileUrl(
11 new URL("./fixtures/vite/", import.meta.url),
12 );
13 const modules = yield* path.fromFileUrl(
14 new URL("../../../node_modules/", import.meta.url),
15 );
16 const rootDir = yield* fs.makeTempDirectoryScoped({
17 prefix: "prisma-website-vite-",
18 });
19 yield* fs.copy(source, rootDir);
20 yield* fs.symlink(modules, path.join(rootDir, "node_modules"));
21 return rootDir;
22});
23
24export const bodyContaining = Effect.fn(function* (
25 url: string,
26 expected: string,
27) {
28 return yield* Effect.gen(function* () {
29 const response = yield* HttpClient.get(url);
30 const body = yield* response.text;
31 if (response.status !== 200 || !body.includes(expected)) {
32 return yield* Effect.fail(
33 new Error(
34 `${url} returned ${response.status} without ${expected}: ${body.slice(0, 500)}`,
35 ),
36 );
37 }
38 return body;
39 }).pipe(Effect.retry({ schedule: Schedule.spaced("500 millis"), times: 8 }));
40});