diff --git a/test/cli/run/log-test.test.ts b/test/cli/run/log-test.test.ts index c23fb2c1ed4f..2c6b5cd7dc77 100644 --- a/test/cli/run/log-test.test.ts +++ b/test/cli/run/log-test.test.ts @@ -1,18 +1,16 @@ import { spawnSync } from "bun"; import { expect, it } from "bun:test"; -import * as fs from "fs"; -import { bunEnv, bunExe } from "harness"; -import { dirname, join, resolve } from "path"; +import { bunEnv, bunExe, tempDir } from "harness"; it("should not log .env when quiet", async () => { - writeDirectoryTree("/tmp/log-test-silent", { + using dir = tempDir("log-test-silent", { ".env": "FOO=bar", "bunfig.toml": `logLevel = "error"`, "index.ts": "export default console.log('Here');", }); const { stderr } = spawnSync({ cmd: [bunExe(), "index.ts"], - cwd: "/tmp/log-test-silent", + cwd: String(dir), env: bunEnv, }); @@ -20,7 +18,7 @@ it("should not log .env when quiet", async () => { }); it("should log .env by default", async () => { - writeDirectoryTree("/tmp/log-test-silent", { + using dir = tempDir("log-test-silent", { ".env": "FOO=bar", "bunfig.toml": ``, "index.ts": "export default console.log('Here');", @@ -28,27 +26,9 @@ it("should log .env by default", async () => { const { stderr } = spawnSync({ cmd: [bunExe(), "index.ts"], - cwd: "/tmp/log-test-silent", + cwd: String(dir), env: bunEnv, }); expect(stderr?.toString().includes(".env")).toBe(false); }); - -function writeDirectoryTree(base: string, paths: Record) { - base = resolve(base); - for (const path of Object.keys(paths)) { - const content = paths[path]; - const joined = join(base, path); - - try { - fs.mkdirSync(join(base, dirname(path)), { recursive: true }); - } catch (e) {} - - try { - fs.unlinkSync(joined); - } catch (e) {} - - fs.writeFileSync(joined, content); - } -}