mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
docs: fix incorrect [env] section documentation in bunfig.toml (#25634)
## Summary - Fixed documentation that incorrectly claimed you could use `[env]` as a TOML section to set environment variables directly - The `env` option in bunfig.toml only controls whether automatic `.env` file loading is disabled (via `env = false`) - Updated to show the correct approaches: using preload scripts or `.env` files with `--env-file` ## Test plan - Documentation-only change, no code changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -115,6 +115,26 @@ Currently we do not collect telemetry and this setting is only used for enabling
|
|||||||
telemetry = false
|
telemetry = false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `env`
|
||||||
|
|
||||||
|
Configure automatic `.env` file loading. By default, Bun automatically loads `.env` files. To disable this behavior:
|
||||||
|
|
||||||
|
```toml title="bunfig.toml" icon="settings"
|
||||||
|
# Disable automatic .env file loading
|
||||||
|
env = false
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use object syntax with the `file` property:
|
||||||
|
|
||||||
|
```toml title="bunfig.toml" icon="settings"
|
||||||
|
[env]
|
||||||
|
file = false
|
||||||
|
```
|
||||||
|
|
||||||
|
This is useful in production environments or CI/CD pipelines where you want to rely solely on system environment variables.
|
||||||
|
|
||||||
|
Note: Explicitly provided environment files via `--env-file` will still be loaded even when default loading is disabled.
|
||||||
|
|
||||||
### `console`
|
### `console`
|
||||||
|
|
||||||
Configure console output behavior.
|
Configure console output behavior.
|
||||||
|
|||||||
@@ -376,16 +376,18 @@ timeout = 10000
|
|||||||
|
|
||||||
## Environment Variables
|
## Environment Variables
|
||||||
|
|
||||||
You can also set environment variables in your configuration that affect test behavior:
|
Environment variables for tests should be set using `.env` files. Bun automatically loads `.env` files from your project root. For test-specific variables, create a `.env.test` file:
|
||||||
|
|
||||||
```toml title="bunfig.toml" icon="settings"
|
```ini title=".env.test" icon="settings"
|
||||||
[env]
|
NODE_ENV=test
|
||||||
NODE_ENV = "test"
|
DATABASE_URL=postgresql://localhost:5432/test_db
|
||||||
DATABASE_URL = "postgresql://localhost:5432/test_db"
|
LOG_LEVEL=error
|
||||||
LOG_LEVEL = "error"
|
```
|
||||||
|
|
||||||
[test]
|
Then load it with `--env-file`:
|
||||||
coverage = true
|
|
||||||
|
```bash terminal icon="terminal"
|
||||||
|
bun test --env-file=.env.test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Complete Configuration Example
|
## Complete Configuration Example
|
||||||
@@ -398,13 +400,6 @@ Here's a comprehensive example showing all available test configuration options:
|
|||||||
registry = "https://registry.npmjs.org/"
|
registry = "https://registry.npmjs.org/"
|
||||||
exact = true
|
exact = true
|
||||||
|
|
||||||
[env]
|
|
||||||
# Environment variables for tests
|
|
||||||
NODE_ENV = "test"
|
|
||||||
DATABASE_URL = "postgresql://localhost:5432/test_db"
|
|
||||||
API_URL = "http://localhost:3001"
|
|
||||||
LOG_LEVEL = "error"
|
|
||||||
|
|
||||||
[test]
|
[test]
|
||||||
# Test discovery
|
# Test discovery
|
||||||
root = "src"
|
root = "src"
|
||||||
|
|||||||
Reference in New Issue
Block a user