| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 | import { it, expect } from "bun:test";
import { basename, dirname, join } from "path";
import * as fs from "fs";
import { readableStreamToText, spawnSync } from "bun";
import { bunExe } from "bunExe";
import { bunEnv } from "bunEnv";
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 { stderr } = spawnSync({
    cmd: [bunExe(), "index.ts"],
    cwd: "/tmp/log-test-silent",
    env: bunEnv,
  });
  expect(stderr!.toString()).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 { stderr } = spawnSync({
    cmd: [bunExe(), "index.ts"],
    cwd: "/tmp/log-test-silent",
    env: bunEnv,
  });
  expect(stderr?.toString().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.mkdirSync(join(base, dirname(path)), { recursive: true });
    } catch (e) {}
    try {
      fs.unlinkSync(joined);
    } catch (e) {}
    fs.writeFileSync(joined, content);
  }
}
 |