( name: string, layer: Layer.Layer<ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path>, options: Options )
| 34 | ) |
| 35 | |
| 36 | export const suite = ( |
| 37 | name: string, |
| 38 | layer: Layer.Layer<ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path>, |
| 39 | options: Options |
| 40 | ) => |
| 41 | describe(name, () => { |
| 42 | it.layer(layer)((it) => { |
| 43 | describe("spawn", () => { |
| 44 | describe("basic spawning", () => { |
| 45 | it.effect("should spawn a simple command and collect output", () => |
| 46 | Effect.gen(function*() { |
| 47 | const handle = yield* ChildProcess.make("sh", ["-c", "printf portable"]) |
| 48 | const output = yield* decodeByteStream(handle.stdout) |
| 49 | const exitCode = yield* handle.exitCode |
| 50 | |
| 51 | assert.strictEqual(exitCode, ChildProcessSpawner.ExitCode(0)) |
| 52 | assert.strictEqual(output, "portable") |
| 53 | })) |
| 54 | |
| 55 | it.effect("should spawn echo command", () => |
| 56 | Effect.gen(function*() { |
| 57 | const handle = yield* ChildProcess.make("echo", ["hello", "world"]) |
| 58 | const output = yield* decodeByteStream(handle.stdout) |
| 59 | const exitCode = yield* handle.exitCode |
| 60 | |
| 61 | assert.strictEqual(exitCode, ChildProcessSpawner.ExitCode(0)) |
| 62 | assert.strictEqual(output, "hello world") |
| 63 | })) |
| 64 | |
| 65 | it.effect("should spawn with template literal", () => |
| 66 | Effect.gen(function*() { |
| 67 | const handle = yield* ChildProcess.make`echo spawned` |
| 68 | const output = yield* decodeByteStream(handle.stdout) |
| 69 | const exitCode = yield* handle.exitCode |
| 70 | |
| 71 | assert.strictEqual(exitCode, ChildProcessSpawner.ExitCode(0)) |
| 72 | assert.strictEqual(output, "spawned") |
| 73 | })) |
| 74 | }) |
| 75 | |
| 76 | describe("cwd option", () => { |
| 77 | it.effect("should handle command with working directory", () => |
| 78 | Effect.gen(function*() { |
| 79 | const handle = yield* ChildProcess.make("pwd", [], { cwd: "/tmp" }) |
| 80 | const output = yield* decodeByteStream(handle.stdout) |
| 81 | const exitCode = yield* handle.exitCode |
| 82 | |
| 83 | assert.strictEqual(exitCode, ChildProcessSpawner.ExitCode(0)) |
| 84 | // On macOS, /tmp is a symlink to /private/tmp |
| 85 | assert.isTrue(output.includes("tmp")) |
| 86 | })) |
| 87 | |
| 88 | it.effect("should use cwd with template literal form", () => |
| 89 | Effect.gen(function*() { |
| 90 | const handle = yield* ChildProcess.make({ cwd: "/tmp" })`pwd` |
| 91 | const output = yield* decodeByteStream(handle.stdout) |
| 92 | const exitCode = yield* handle.exitCode |
| 93 |
nothing calls this directly
no test coverage detected