Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jakeboone02 opened this issue Jun 27, 2024 · 1 comment
Open

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

jakeboone02 opened this issue Jun 27, 2024 · 1 comment
Labels
bug Something isn't working needs triage

Comments

@jakeboone02
Copy link
Contributor

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 jakeboone02 added bug Something isn't working needs triage labels Jun 27, 2024
@jakeboone02
Copy link
Contributor Author

jakeboone02 commented Jun 27, 2024

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant