Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

DeviceToolchain.test.ts

39 lines1.6 KB

1import { expect, it } from "@effect/vitest";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Path from "effect/Path";
6import * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
7​
8import * as ProcessRunner from "../processRunner.ts";
9import { ensureDeviceHub, isDeviceHubInstalled } from "./DeviceToolchain.ts";
10​
11it.effect("failed installation cleans staging and exposes only a safe failure message", () =>
12 Effect.gen(function* () {
13 const fs = yield* FileSystem.FileSystem;
14 const path = yield* Path.Path;
15 const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-device-install-" });
16 const result = {
17 code: ChildProcessSpawner.ExitCode(1),
18 stdout: "",
19 stderr: "registry rejected https://private:credential@example.test/package",
20 timedOut: false,
21 stdoutTruncated: false,
22 stderrTruncated: false,
23 stdoutInvalidUtf8: false,
24 stderrInvalidUtf8: false,
25 };
26 const error = yield* ensureDeviceHub(baseDir).pipe(
27 Effect.provideService(ProcessRunner.ProcessRunner, {
28 run: () => Effect.succeed(result),
29 }),
30 Effect.flip,
31 );
32 expect(error.message).toBe(
33 "Installing expo-device-hub failed while running npm install (exit code 1).",
34 );
35 expect(error.cause).toBe(result);
36 expect(yield* isDeviceHubInstalled(baseDir)).toBe(false);
37 expect(yield* fs.readDirectory(path.join(baseDir, "tools", "expo-device-hub"))).toEqual([]);
38 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
39);