Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
vendor
test/snapshots
# written by Jest and Vitest, and compared byte for byte
test/js/bun/test/snapshot-tests/formats
test/bundler/transpiler/react-compiler-fixtures
src/**/*.generated.rs
test/js/deno
Expand Down
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/bundler/css.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,8 @@ This outputs:

The class names are unique to each file, so they don't collide.

Importing a CSS module at runtime (`bun run`, `bun test`) gives you the same object. Server-rendered markup and component tests see the same class names the bundler emits, as long as both run from the same working directory.

### Composition

CSS modules can compose class selectors together to reuse style rules across multiple classes.
Expand Down
1 change: 1 addition & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
"/runtime/xml",
"/runtime/jsonl",
"/runtime/html-rewriter",
"/runtime/dom",
"/runtime/image",
"/runtime/hashing",
"/runtime/glob",
Expand Down
6 changes: 4 additions & 2 deletions docs/guides/test/migrate-from-jest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ Bun implements most of Jest's matchers, but compatibility isn't 100%. See the co

---

If you use `testEnvironment: "jsdom"` to run your tests in a browser-like environment, follow the [DOM testing with Bun and happy-dom](/guides/test/happy-dom) guide to inject browser APIs into the global scope. That guide uses [`happy-dom`](https://github.com/capricorn86/happy-dom), a leaner and faster alternative to [`jsdom`](https://github.com/jsdom/jsdom).
Replace `testEnvironment: "jsdom"` in your Jest config with `environment` in `bunfig.toml`, and install `jsdom` itself (`bun add -d jsdom`). [`happy-dom`](https://github.com/capricorn86/happy-dom) is a leaner and faster alternative.

```toml bunfig.toml icon="settings"
[test]
preload = ["./happydom.ts"]
environment = "jsdom"
```

`@jest-environment jsdom` and `@jest-environment node` comments in test files work as-is. If a comment uses a name Bun doesn't support, such as `jest-environment-jsdom`, Bun prints a warning and runs the file without a DOM. Change it to `jsdom` or `node`. See [DOM testing](/test/dom#test-environments).

---

Replace `bail` in your Jest config with the `--bail` CLI flag.
Expand Down
1 change: 1 addition & 0 deletions docs/project/benchmarking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ BUN_OPTIONS="--cpu-prof-md" bun script.js
```sh terminal icon="terminal"
bun --cpu-prof --cpu-prof-name my-profile.cpuprofile script.js
bun --cpu-prof --cpu-prof-dir ./profiles script.js
bun test --cpu-prof --cpu-prof-dir ./profiles # with --parallel, one profile for each worker
```

| Flag | Description |
Expand Down
1 change: 1 addition & 0 deletions docs/runtime/bun-apis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Use the links in the table to jump to the associated documentation.
| Transpiler | [`Bun.Transpiler`](/runtime/transpiler) |
| Routing | [`Bun.FileSystemRouter`](/runtime/file-system-router) |
| Streaming HTML | [`HTMLRewriter`](/runtime/html-rewriter) |
| DOM | [`bun:dom`](/runtime/dom) |
| Headless Browser | [`Bun.WebView`](/runtime/webview) |
| Hashing | [`Bun.password`](/runtime/hashing#bun-password), [`Bun.hash`](/runtime/hashing#bun-hash), [`Bun.CryptoHasher`](/runtime/hashing#bun-cryptohasher), `Bun.sha` |
| CSRF Protection | [`Bun.CSRF.generate`](/runtime/csrf), [`Bun.CSRF.verify`](/runtime/csrf) |
Expand Down
67 changes: 67 additions & 0 deletions docs/runtime/bunfig.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,47 @@ Same as the top-level `preload` field, but only applies to `bun test`.
preload = ["./setup.ts"]
```

### `test.environment`

The DOM that test files run with. One of `"happy-dom"`, `"jsdom"`, or `"node"` for no DOM. Default `"node"`. A `// @vitest-environment <name>` comment in a test file overrides it. See [DOM testing](/test/dom#test-environments).

```toml title="bunfig.toml" icon="settings"
[test]
environment = "happy-dom"
```

Equivalent CLI flag: `--environment`. It overrides the `bunfig.toml` value.

### `test.globals`

Which module `test`, `expect` and the other globals come from. Default `"bun"`.

- `"bun"`: a file that imports anything from `"vitest"` gets them from `"vitest"`. Any other file gets them from `"bun:test"`.
- `"vitest"`: every file gets them from `"vitest"`, like `globals: true` in a Vitest project.

```toml title="bunfig.toml" icon="settings"
[test]
globals = "vitest"
```

Equivalent CLI flag: `--globals`. It overrides the `bunfig.toml` value.

### `test.reactCompiler`

Compile components and hooks with Bun's built-in React Compiler. Default `false`. Experimental.

- `true`: every JavaScript and TypeScript file, except test files, preload scripts and `node_modules`.
- An array of folders or glob patterns: only the files in them.
- A table with `include` and `exclude`: the files that `include` matches and `exclude` doesn't.

```toml title="bunfig.toml" icon="settings"
[test.reactCompiler]
include = ["src", "packages/ui"]
exclude = ["**/*.stories.*"]
```

Equivalent CLI flag: `--react-compiler`. See [React Compiler](/test/configuration#react-compiler).

### `test.pathIgnorePatterns`

Exclude files and directories from test discovery using glob patterns. The test runner prunes matched directories during scanning, so it never traverses their contents. Use this when your project contains submodules or vendored code with `*.test.ts` files that you don't want `bun test` to pick up.
Expand Down Expand Up @@ -346,6 +387,17 @@ retry = 3

The `--retry` CLI flag overrides this setting.

### `test.clearMocks`

Clear every mock function's calls and results before each test. Default `false`, or `true` for tests that use `test` from `"vitest"`.

```toml title="bunfig.toml" icon="settings"
[test]
clearMocks = true
```

`mockReset`, `restoreMocks`, `unstubEnvs` and `unstubGlobals` work the same way. They call `vi.resetAllMocks()`, `vi.restoreAllMocks()`, `vi.unstubAllEnvs()` and `vi.unstubAllGlobals()` before each test. Default `false`.

### `test.concurrentTestGlob`

Test files matching this glob pattern run all of their tests concurrently, as if you passed the `--concurrent` flag.
Expand Down Expand Up @@ -394,6 +446,21 @@ junit = "test-results.xml"

CI systems and other tools can consume the report.

#### `test.reporter.junitSuites`

How the JUnit report represents `describe` blocks. Default `"nested"`.

- `"nested"`: each block gets its own `<testsuite>` inside its file's `<testsuite>`.
- `"flat"`: each file gets one `<testsuite>`, and each test's name is prefixed with the names of its blocks.

```toml title="bunfig.toml" icon="settings"
[test.reporter]
junit = "test-results.xml"
junitSuites = "flat"
```

Equivalent to the `--reporter-junit-suites` flag.

## Linter

The `[lint]` section configures [`bun lint`](/lint). Run `bun lint --init` to add it.
Expand Down
Loading