MCPcopy Create free account
hub / github.com/Effect-TS/effect / suite

Function suite

packages/effect/test/unstable/process/ChildProcessSpawnerTest.ts:36–1170  ·  view source on GitHub ↗
(
  name: string,
  layer: Layer.Layer<ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem | Path.Path>,
  options: Options
)

Source from the content-addressed store, hash-verified

34)
35
36export 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

Callers

nothing calls this directly

Calls 15

longRunningCommandFunction · 0.85
countMatchingProcessesFunction · 0.85
killMatchingProcessesFunction · 0.85
joinMethod · 0.80
allMethod · 0.80
filterMethod · 0.80
withLiveMethod · 0.80
makeMethod · 0.65
pipeMethod · 0.65
sleepMethod · 0.65
closeMethod · 0.65
splitMethod · 0.45

Tested by

no test coverage detected