The best way to control Claude Code, Codex and more from any computer or phone
| 1 | /** |
| 2 | * The hand-written subscriptions set is pinned byte for byte by snapshot files |
| 3 | * under `test/generated/`, which `pnpm check` typechecks and the |
| 4 | * `Generator.runtime*` tests import. Run with `-u` to update them after an |
| 5 | * intended output change. |
| 6 | * |
| 7 | * The GitHub set is generated during the tests instead of being committed: |
| 8 | * here it is written to a scratch directory and typechecked with `tsc`. |
| 9 | */ |
| 10 | import * as NodeServices from "@effect/platform-node/NodeServices" |
| 11 | import { assert, describe, it } from "@effect/vitest" |
| 12 | import * as Effect from "effect/Effect" |
| 13 | import * as FileSystem from "effect/FileSystem" |
| 14 | import * as Path from "effect/Path" |
| 15 | import { ChildProcess, ChildProcessSpawner } from "effect/process" |
| 16 | import * as Stream from "effect/Stream" |
| 17 | import { fileURLToPath } from "node:url" |
| 18 | import { generateSubscriptions, writeGitHub } from "./utils/generator.ts" |
| 19 | |
| 20 | const repoRoot = fileURLToPath(new URL("../../../../", import.meta.url)) |
| 21 | |
| 22 | describe("Generator snapshots", () => { |
| 23 | it.effect("subscriptions", (ctx) => |
| 24 | Effect.gen(function*() { |
| 25 | const files = ["messages.graphql.ts", "rooms.graphql.ts", "shared.graphql.ts"] |
| 26 | const generated = yield* generateSubscriptions |
| 27 | assert.deepStrictEqual(generated.result.diagnostics, []) |
| 28 | assert.deepStrictEqual(generated.paths, files.map((name) => `subscriptions/${name}`)) |
| 29 | for (const name of files) { |
| 30 | yield* Effect.promise(() => |
| 31 | ctx.expect(generated.file(`subscriptions/${name}`)).toMatchFileSnapshot(`./generated/subscriptions/${name}`) |
| 32 | ) |
| 33 | } |
| 34 | }).pipe(Effect.provide(NodeServices.layer))) |
| 35 | |
| 36 | it.effect("the generated GitHub set typechecks", () => |
| 37 | Effect.gen(function*() { |
| 38 | const fs = yield* FileSystem.FileSystem |
| 39 | const path = yield* Path.Path |
| 40 | const dir = yield* writeGitHub |
| 41 | yield* fs.writeFileString( |
| 42 | path.join(dir, "tsconfig.json"), |
| 43 | JSON.stringify({ |
| 44 | extends: path.join(repoRoot, "tsconfig.base.json"), |
| 45 | compilerOptions: { |
| 46 | noEmit: true, |
| 47 | composite: false, |
| 48 | declaration: false, |
| 49 | declarationMap: false, |
| 50 | rootDir: ".", |
| 51 | types: ["node"] |
| 52 | }, |
| 53 | include: ["*.ts"] |
| 54 | }) |
| 55 | ) |
| 56 | const handle = yield* ChildProcess.make("node", [ |
| 57 | path.join(repoRoot, "node_modules/typescript/bin/tsc"), |
| 58 | "-p", |
| 59 | dir, |
| 60 | "--pretty", |
| 61 | "false" |
| 62 | ]) |
| 63 | const [exitCode, output] = yield* Effect.all( |
| 64 | [handle.exitCode, Stream.mkString(Stream.decodeText(handle.stdout))], |
| 65 | { |
| 66 | concurrency: "unbounded" |
| 67 | } |
| 68 | ) |
| 69 | assert.strictEqual(output, "") |
| 70 | assert.strictEqual(exitCode, ChildProcessSpawner.ExitCode(0)) |
| 71 | }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), 60_000) |
| 72 | }) |