Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Path from "effect/Path";
6
7import { copyRequiredBuildAsset } from "./cliBuildAssets.ts";
8
9it.layer(NodeServices.layer)("server CLI build assets", (it) => {
10 it.effect("fails when a required build asset is missing", () =>
11 Effect.gen(function* () {
12 const fileSystem = yield* FileSystem.FileSystem;
13 const path = yield* Path.Path;
14 const tempDir = yield* fileSystem.makeTempDirectoryScoped({
15 prefix: "t3-cli-required-asset-",
16 });
17 const sourcePath = path.join(tempDir, "missing.ts");
18 const targetPath = path.join(tempDir, "dist", "required.ts");
19
20 const error = yield* copyRequiredBuildAsset(sourcePath, targetPath).pipe(Effect.flip);
21
22 assert.equal(error._tag, "ServerCliBuildAssetMissingError");
23 if (error._tag !== "ServerCliBuildAssetMissingError") {
24 return assert.fail(`Unexpected error: ${error._tag}`);
25 }
26 assert.equal(error.assetPath, sourcePath);
27 assert.equal(yield* fileSystem.exists(targetPath), false);
28 }),
29 );
30
31 it.effect("copies a required build asset into its target directory", () =>
32 Effect.gen(function* () {
33 const fileSystem = yield* FileSystem.FileSystem;
34 const path = yield* Path.Path;
35 const tempDir = yield* fileSystem.makeTempDirectoryScoped({
36 prefix: "t3-cli-required-asset-",
37 });
38 const sourcePath = path.join(tempDir, "required.ts");
39 const targetPath = path.join(tempDir, "dist", "assets", "required.ts");
40 yield* fileSystem.writeFileString(sourcePath, "export const required = true;\n");
41
42 yield* copyRequiredBuildAsset(sourcePath, targetPath);
43
44 assert.equal(yield* fileSystem.readFileString(targetPath), "export const required = true;\n");
45 }),
46 );
47});