diff options
author | 2022-10-08 15:58:07 -0700 | |
---|---|---|
committer | 2022-10-09 02:02:46 -0700 | |
commit | 0b3abf2c78f517bad9227b422dd5f068c4af3a91 (patch) | |
tree | 19a59e68c4107d33fa19a75189a2b810163a8971 | |
parent | 9294ef73b78a38a4a06e8f16432089a81abc50ea (diff) | |
download | bun-0b3abf2c78f517bad9227b422dd5f068c4af3a91.tar.gz bun-0b3abf2c78f517bad9227b422dd5f068c4af3a91.tar.zst bun-0b3abf2c78f517bad9227b422dd5f068c4af3a91.zip |
Add a test for not logging .env
-rw-r--r-- | test/bun.js/log-test.test.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/bun.js/log-test.test.ts b/test/bun.js/log-test.test.ts new file mode 100644 index 000000000..883daa5c4 --- /dev/null +++ b/test/bun.js/log-test.test.ts @@ -0,0 +1,60 @@ +import { it, expect } from "bun:test"; +import { basename, dirname, join } from "path"; +import * as fs from "fs"; +import { readableStreamToText, spawn } from "bun"; + +it("should not log .env when quiet", async () => { + writeDirectoryTree("/tmp/log-test-silent", { + ".env": "FOO=bar", + "bunfig.toml": `logLevel = "error"`, + "index.ts": "export default console.log('Here');", + }); + const out = spawn({ + cmd: [process.argv[0], "index.ts"], + stdout: "pipe", + stderr: "pipe", + cwd: "/tmp/log-test-silent", + }); + + out.ref(); + await out.exited; + const text = await readableStreamToText(out.stderr); + expect(text).toBe(""); +}); + +it("should log .env by default", async () => { + writeDirectoryTree("/tmp/log-test-silent", { + ".env": "FOO=bar", + "bunfig.toml": ``, + "index.ts": "export default console.log('Here');", + }); + + const out = spawn({ + cmd: [process.argv[0], "index.ts"], + stdout: "pipe", + stderr: "pipe", + cwd: "/tmp/log-test-silent", + }); + + out.ref(); + await out.exited; + const text = await readableStreamToText(out.stderr); + expect(text.includes(".env")).toBe(true); +}); + +function writeDirectoryTree(base, paths) { + for (const path of Object.keys(paths)) { + const content = paths[path]; + const joined = join(base, path); + + try { + fs.unlinkSync(joined); + } catch (e) {} + + try { + fs.mkdirSync(join(base, dirname(path)), { recursive: true }); + } catch (e) {} + + fs.writeFileSync(joined, content); + } +} |