Skip to content

bun test will not load environment variables from .env.local #19542

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

Open
DonIsaac opened this issue May 8, 2025 · 1 comment · May be fixed by #19562
Open

bun test will not load environment variables from .env.local #19542

DonIsaac opened this issue May 8, 2025 · 1 comment · May be fixed by #19562
Labels
bug Something isn't working bun:test Something related to the `bun test` runner

Comments

@DonIsaac
Copy link
Contributor

DonIsaac commented May 8, 2025

What version of Bun is running?

1.2.13-canary.23+500199fe8

What platform is your computer?

Darwin 24.4.0 arm64 arm

What steps can reproduce the bug?

Create these files

// foo.test.ts
it("works", () => {
    expect(process.env.FOO).toBe("foo")
});
 # .env.local
FOO=foo

Then run bun test

What is the expected behavior?

Test passes

What do you see instead?

bun test v1.2.13-canary.23 (500199fe)

index.test.ts:
1 | it("works", () => {
2 |     expect(process.env.FOO).toBe("foo")
                                ^
error: expect(received).toBe(expected)

Expected: "foo"
Received: undefined

Additional information

.env files are loaded correctly

@DonIsaac DonIsaac added bug Something isn't working needs triage labels May 8, 2025
@RiskyMH RiskyMH added bun:test Something related to the `bun test` runner and removed needs triage labels May 9, 2025
zimirza added a commit to zimirza/bun that referenced this issue May 9, 2025
@zimirza zimirza linked a pull request May 9, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun:test Something related to the `bun test` runner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@DonIsaac @RiskyMH and others