diff --git a/docs/runtime/bunfig.mdx b/docs/runtime/bunfig.mdx index 2ed368d9ba..a4258d8377 100644 --- a/docs/runtime/bunfig.mdx +++ b/docs/runtime/bunfig.mdx @@ -115,6 +115,26 @@ Currently we do not collect telemetry and this setting is only used for enabling 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` Configure console output behavior. diff --git a/docs/test/configuration.mdx b/docs/test/configuration.mdx index 9fff440301..8a8406c6d0 100644 --- a/docs/test/configuration.mdx +++ b/docs/test/configuration.mdx @@ -376,16 +376,18 @@ timeout = 10000 ## 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" -[env] -NODE_ENV = "test" -DATABASE_URL = "postgresql://localhost:5432/test_db" -LOG_LEVEL = "error" +```ini title=".env.test" icon="settings" +NODE_ENV=test +DATABASE_URL=postgresql://localhost:5432/test_db +LOG_LEVEL=error +``` -[test] -coverage = true +Then load it with `--env-file`: + +```bash terminal icon="terminal" +bun test --env-file=.env.test ``` ## Complete Configuration Example @@ -398,13 +400,6 @@ Here's a comprehensive example showing all available test configuration options: registry = "https://registry.npmjs.org/" 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 discovery root = "src"