Files
bun.sh/test/js/node/process/process-on.test.ts

87 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
import path from "path";
describe("process.on", () => {
it("when called from the main thread", () => {
const result = Bun.spawnSync({
cmd: [bunExe(), path.join(__dirname, "process-on-fixture.ts")],
env: bunEnv,
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
});
expect(result.exitCode).toBe(0);
});
it("should work inside --compile", () => {
const dir = tempDirWithFiles("process-on-test", {
"process-on-fixture.ts": require("fs").readFileSync(require.resolve("./process-on-fixture.ts"), "utf-8"),
"package.json": `{
"name": "process-on-test",
"type": "module",
"scripts": {
"start": "bun run process-on-fixture.ts"
}
}`,
});
const result1 = Bun.spawnSync({
cmd: [bunExe(), "build", "--compile", path.join(dir, "./process-on-fixture.ts"), "--outfile=./out"],
env: bunEnv,
cwd: dir,
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
});
expect(result1.exitCode).toBe(0);
const result2 = Bun.spawnSync({
cmd: ["./out"],
env: bunEnv,
cwd: dir,
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
});
expect(result2.exitCode).toBe(0);
});
it("should work inside a macro", () => {
const dir = tempDirWithFiles("process-on-test", {
"process-on-fixture.ts": require("fs").readFileSync(require.resolve("./process-on-fixture.ts"), "utf-8"),
"entry.ts": `import { initialize } from "./process-on-fixture.ts" with {type: "macro"};
initialize();`,
"package.json": `{
"name": "process-on-test",
"type": "module",
"scripts": {
"start": "bun run entry.ts"
}
}`,
});
expect(
Bun.spawnSync({
cmd: [bunExe(), "build", "--target=bun", path.join(dir, "entry.ts"), "--outfile=./out.ts"],
env: bunEnv,
cwd: dir,
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
}).exitCode,
).toBe(0);
const result2 = Bun.spawnSync({
cmd: [bunExe(), "run", "./out.ts"],
env: bunEnv,
cwd: dir,
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
});
expect(result2.exitCode).toBe(0);
});
});