diff --git a/docs/bundler/executables.mdx b/docs/bundler/executables.mdx index 8de435e715..fefa2769e6 100644 --- a/docs/bundler/executables.mdx +++ b/docs/bundler/executables.mdx @@ -183,6 +183,35 @@ console.log(process.execArgv); // ["--smol", "--user-agent=MyBot"] --- +## Disabling automatic config loading + +By default, standalone executables look for `.env` and `bunfig.toml` files in the directory where the executable is run. You can disable this behavior at build time for deterministic execution regardless of the user's working directory. + +```bash icon="terminal" terminal +# Disable .env loading +bun build --compile --no-compile-autoload-dotenv ./app.ts --outfile myapp + +# Disable bunfig.toml loading +bun build --compile --no-compile-autoload-bunfig ./app.ts --outfile myapp + +# Disable both +bun build --compile --no-compile-autoload-dotenv --no-compile-autoload-bunfig ./app.ts --outfile myapp +``` + +You can also configure this via the JavaScript API: + +```ts +await Bun.build({ + entrypoints: ["./app.ts"], + compile: { + autoloadDotenv: false, // Disable .env loading + autoloadBunfig: false, // Disable bunfig.toml loading + }, +}); +``` + +--- + ## Act as the Bun CLI New in Bun v1.2.16 diff --git a/docs/runtime/environment-variables.mdx b/docs/runtime/environment-variables.mdx index c1b38edc1b..529b5348af 100644 --- a/docs/runtime/environment-variables.mdx +++ b/docs/runtime/environment-variables.mdx @@ -72,6 +72,23 @@ bun --env-file=.env.1 src/index.ts bun --env-file=.env.abc --env-file=.env.def run build ``` +## Disabling automatic `.env` loading + +Use `--no-env-file` to disable Bun's automatic `.env` file loading. This is useful in production environments or CI/CD pipelines where you want to rely solely on system environment variables. + +```sh +bun run --no-env-file index.ts +``` + +This can also be configured in `bunfig.toml`: + +```toml bunfig.toml icon="settings" +# Disable loading .env files +env = false +``` + +Explicitly provided environment files via `--env-file` will still be loaded even when default loading is disabled. + --- ## Quotation marks diff --git a/docs/test/writing-tests.mdx b/docs/test/writing-tests.mdx index a2de3839a5..5fee977356 100644 --- a/docs/test/writing-tests.mdx +++ b/docs/test/writing-tests.mdx @@ -78,6 +78,43 @@ In `bun:test`, test timeouts throw an uncatchable exception to force the test to The default timeout for each test is 5000ms (5 seconds) if not overridden by this timeout option or `jest.setDefaultTimeout()`. +## Retries and Repeats + +### test.retry + +Use the `retry` option to automatically retry a test if it fails. The test passes if it succeeds within the specified number of attempts. This is useful for flaky tests that may fail intermittently. + +```ts title="example.test.ts" icon="/icons/typescript.svg" +import { test } from "bun:test"; + +test( + "flaky network request", + async () => { + const response = await fetch("https://example.com/api"); + expect(response.ok).toBe(true); + }, + { retry: 3 }, // Retry up to 3 times if the test fails +); +``` + +### test.repeats + +Use the `repeats` option to run a test multiple times regardless of pass/fail status. The test fails if any iteration fails. This is useful for detecting flaky tests or stress testing. Note that `repeats: N` runs the test N+1 times total (1 initial run + N repeats). + +```ts title="example.test.ts" icon="/icons/typescript.svg" +import { test } from "bun:test"; + +test( + "ensure test is stable", + () => { + expect(Math.random()).toBeLessThan(1); + }, + { repeats: 20 }, // Runs 21 times total (1 initial + 20 repeats) +); +``` + +You cannot use both `retry` and `repeats` on the same test. + ### 🧟 Zombie Process Killer When a test times out and processes spawned in the test via `Bun.spawn`, `Bun.spawnSync`, or `node:child_process` are not killed, they will be automatically killed and a message will be logged to the console. This prevents zombie processes from lingering in the background after timed-out tests.