oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
72.18k stars 2.58k forks source link

Values in `bunfig.toml` take precedence over command line args #12216

Open jakeboone02 opened 3 weeks ago

jakeboone02 commented 3 weeks ago

What version of Bun is running?

1.1.17+bb66bba1b

What platform is your computer?

Linux 5.15.153.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

bunfig.toml:

[test]
coverage = false

index.js:

export const x = () => "x";
export const y = () => "y";

idx.test.js:

import { x } from ".";
it("works", () => { expect(x()).toBe("x"); });
bun test idx.test.js --coverage

What is the expected behavior?

The --coverage flag on the command line should override the coverage = false configuration in bunfig.toml, and coverage should be collected/reported.

What do you see instead?

The coverage value configured in bunfig.toml always takes precedence over the --coverage command line flag. In the example above, coverage is not reported due to the coverage = false in bunfig.toml.

Additional information

I was starting to address #4346, but ran into this issue.

jakeboone02 commented 3 weeks ago

I added this test locally to /test/cli/test/coverage.test.ts to track it. If you remove the coverage = false line or change it to coverage = true, the test passes.

test("command line flag --coverage overrides bunfig", async () => {
  const dir = tempDirWithFiles("cmd-line-overrides-bunfig", {
    "cmd-line-overrides-bunfig.test.ts": `
import { covered } from "./cmd-line-overrides-bunfig";

test("cmd line overrides bunfig", () => {
  expect(covered()).toBe(42);
});
`,
    "cmd-line-overrides-bunfig.ts": `
export function covered() {
  // this function IS covered
  return 42;
}

export function uncovered() {
  // this function is not covered
  return 43;
}
`,
    "bunfig.toml": `
[test]
coverage = false
`,
    "package.json": JSON.stringify(
      {
        name: "cmd-line-overrides-bunfig",
        version: "1.0.0",
      },
      null,
      2,
    ),
  });
  const { stderr, exitCode } = Bun.spawnSync({
    cmd: [bunExe(), "test", "cmd-line-overrides-bunfig.test.ts", "--coverage"],
    cwd: dir,
    env: bunEnv,
    stderr: "pipe",
    stdout: "pipe",
    stdin: "inherit",
  });
  expect(stderr.toString().trim()).toContain("% Funcs");
  expect(exitCode).toBe(0);
});