36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { EventEmitter } from "node:events";
|
|
import { PassThrough } from "node:stream";
|
|
import { expect, it } from "vitest";
|
|
import { ProviderProcessSupervisor } from "./ProviderProcess.js";
|
|
|
|
it("exit does not establish complete output when a producer closes its streams later", async () => {
|
|
const producer = Object.assign(new EventEmitter(), {
|
|
stdout: new PassThrough(),
|
|
stderr: new PassThrough(),
|
|
exitCode: null,
|
|
signalCode: null,
|
|
kill: () => false,
|
|
});
|
|
const supervisor = new ProviderProcessSupervisor({
|
|
process: producer,
|
|
ownsProcessLifetime: false,
|
|
});
|
|
try {
|
|
producer.stdout.write("first");
|
|
producer.emit("exit", 0, null);
|
|
expect(await supervisor.waitForExit(0)).toBe(true);
|
|
expect(await supervisor.waitForOutputClose(0)).toBe(false);
|
|
producer.stdout.end("last");
|
|
producer.stderr.end("diagnostic");
|
|
producer.emit("close", 0, null);
|
|
expect(await supervisor.waitForOutputClose(0)).toBe(true);
|
|
expect(supervisor.snapshot()).toMatchObject({
|
|
stdout: { text: "firstlast" },
|
|
stderr: { text: "diagnostic" },
|
|
exitCode: 0,
|
|
});
|
|
} finally {
|
|
supervisor.dispose();
|
|
}
|
|
});
|