mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Clarify .env.local loading when NODE_ENV=test (#22139)
This commit is contained in:
@@ -17,7 +17,7 @@ Bun reads the following files automatically (listed in order of increasing prece
|
||||
|
||||
- `.env`
|
||||
- `.env.production`, `.env.development`, `.env.test` (depending on value of `NODE_ENV`)
|
||||
- `.env.local`
|
||||
- `.env.local` (not loaded when `NODE_ENV=test`)
|
||||
|
||||
```txt#.env
|
||||
FOO=hello
|
||||
|
||||
@@ -8,6 +8,10 @@ Bun reads the following files automatically (listed in order of increasing prece
|
||||
- `.env.production`, `.env.development`, `.env.test` (depending on value of `NODE_ENV`)
|
||||
- `.env.local`
|
||||
|
||||
{% callout %}
|
||||
**Note:** When `NODE_ENV=test`, `.env.local` is **not** loaded. This ensures consistent test environments across different executions by preventing local overrides during testing. This behavior matches popular frameworks like [Next.js](https://nextjs.org/docs/pages/guides/environment-variables#test-environment-variables) and [Create React App](https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used).
|
||||
{% /callout %}
|
||||
|
||||
```txt#.env
|
||||
FOO=hello
|
||||
BAR=world
|
||||
|
||||
@@ -12,6 +12,8 @@ test("NODE_ENV is set to test", () => {
|
||||
});
|
||||
```
|
||||
|
||||
When `NODE_ENV` is set to `"test"`, Bun will not load `.env.local` files. This ensures consistent test environments across different executions by preventing local overrides during testing. Instead, use `.env.test` for test-specific environment variables, which should be committed to your repository for consistency across all developers and CI environments.
|
||||
|
||||
#### `$TZ` environment variable
|
||||
|
||||
By default, all `bun test` runs use UTC (`Etc/UTC`) as the time zone unless overridden by the `TZ` environment variable. This ensures consistent date and time behavior across different development environments.
|
||||
|
||||
Reference in New Issue
Block a user