import { join } from "node:path"; import * as NodeServices from "@effect/platform-node/NodeServices"; import { assert, describe, it } from "@effect/vitest"; import { Effect } from "effect"; import { SourceProcess } from "../src/index.js"; const ECHO = join(import.meta.dirname, "fixtures", "echo.mts"); describe("SourceProcess.run", () => { it.effect( "runs a TypeScript fixture under tsx and answers its exit code and both streams, a non-zero exit as data", () => Effect.gen(function* () { const result = yield* SourceProcess.run(ECHO, { args: ["a", "b"], env: { GREETING: "hi" }, stdin: "piped", }); assert.strictEqual(result.exitCode, 3, result.stderr); assert.strictEqual(result.stdout, "OUT args=a,b stdin=piped\n"); assert.strictEqual(result.stderr, "err greeting=hi vitest=-\n", "only PATH and env reach the child"); }).pipe(Effect.provide(NodeServices.layer)), { timeout: 30_000 }, ); it.effect( "omitted stdin is closed at once, so a child reading it to its end never waits", () => Effect.gen(function* () { const result = yield* SourceProcess.run(ECHO); assert.strictEqual(result.stdout, "OUT args= stdin=\n"); }).pipe(Effect.provide(NodeServices.layer)), { timeout: 30_000 }, ); it("control: the test process itself does have VITEST set, so the empty reading above is not vacuous", () => { assert.isDefined(process.env.VITEST); }); it("the register module the child is started with is an absolute path to an existing file", () => { assert.isTrue(SourceProcess.register.endsWith("register-ts.mjs")); assert.isTrue(SourceProcess.register.startsWith("/")); }); });