test: use harness resource-management in outdir/outfile test

Replace tmpdirSync() with tempDir() and wrap Bun.spawn() with
"await using" to ensure proper cleanup of spawned process and
temporary directory.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2025-12-01 20:01:54 +00:00
parent 39b024bee3
commit ed687afccc

View File

@@ -421,18 +421,17 @@ test("log case 2", async () => {
});
test("cannot use both --outdir and --outfile", async () => {
const tmpdir = tmpdirSync();
const inputFile = path.join(tmpdir, "input.js");
using dir = tempDir("outdir-outfile-test", {
"input.js": 'console.log("Hello, world!");',
});
writeFileSync(inputFile, 'console.log("Hello, world!");');
const { exited, stderr } = Bun.spawn({
cmd: [bunExe(), "build", "--outdir=" + tmpdir + "/out", "--outfile=" + tmpdir + "/out.js", inputFile],
await using subprocess = Bun.spawn({
cmd: [bunExe(), "build", "--outdir=" + dir + "/out", "--outfile=" + dir + "/out.js", dir + "/input.js"],
env: bunEnv,
cwd: tmpdir,
cwd: String(dir),
stderr: "pipe",
});
expect(await stderr.text()).toContain("cannot use both --outdir and --outfile");
expect(await exited).not.toBe(0);
expect(await subprocess.stderr.text()).toContain("cannot use both --outdir and --outfile");
expect(await subprocess.exited).not.toBe(0);
});