aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/bun.js/log-test.test.ts60
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);
+ }
+}