bun-types 1.2.9-canary.20250403T140620 → 1.2.9-canary.20250404T140622

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bun.d.ts CHANGED
@@ -525,7 +525,7 @@ declare module "bun" {
525
525
  *
526
526
  * Changes to `process.env` at runtime won't automatically be reflected in the default value. For that, you can pass `process.env` explicitly.
527
527
  */
528
- const env: Env & NodeJS.ProcessEnv;
528
+ const env: Env & NodeJS.ProcessEnv & ImportMetaEnv;
529
529
 
530
530
  /**
531
531
  * The raw arguments passed to the process, including flags passed to Bun. If you want to easily read flags passed to your script, consider using `process.argv` instead.
@@ -2591,8 +2591,6 @@ declare module "bun" {
2591
2591
  *
2592
2592
  * @see [Bun.password API docs](https://bun.sh/guides/util/hash-a-password)
2593
2593
  *
2594
- * @category Security
2595
- *
2596
2594
  * The underlying implementation of these functions are provided by the Zig
2597
2595
  * Standard Library. Thanks to @jedisct1 and other Zig contributors for their
2598
2596
  * work on this.
@@ -2617,6 +2615,8 @@ declare module "bun" {
2617
2615
  *
2618
2616
  * console.log(verify); // true
2619
2617
  * ```
2618
+ *
2619
+ * @category Security
2620
2620
  */
2621
2621
  const password: {
2622
2622
  /**
@@ -2870,7 +2870,7 @@ declare module "bun" {
2870
2870
  * outdir: './dist',
2871
2871
  * env: 'inline'
2872
2872
  * });
2873
-
2873
+
2874
2874
  * // Only include specific env vars
2875
2875
  * await Bun.build({
2876
2876
  * entrypoints: ['./src/index.tsx'],
@@ -2896,12 +2896,12 @@ declare module "bun" {
2896
2896
  * const result = await Bun.build({
2897
2897
  * entrypoints: ['./src/index.tsx']
2898
2898
  * });
2899
-
2899
+
2900
2900
  * for (const artifact of result.outputs) {
2901
2901
  * const text = await artifact.text();
2902
2902
  * const buffer = await artifact.arrayBuffer();
2903
2903
  * const bytes = await artifact.bytes();
2904
-
2904
+
2905
2905
  * new Response(artifact);
2906
2906
  * await Bun.write(artifact.path, artifact);
2907
2907
  * }
@@ -5889,11 +5889,19 @@ declare module "bun" {
5889
5889
  */
5890
5890
  readonly listener?: SocketListener;
5891
5891
 
5892
+ readonly remoteFamily: "IPv4" | "IPv6";
5893
+
5892
5894
  /**
5893
5895
  * Remote IP address connected to the socket
5894
5896
  */
5895
5897
  readonly remoteAddress: string;
5896
5898
 
5899
+ readonly remotePort: number;
5900
+
5901
+ readonly localFamily: "IPv4" | "IPv6";
5902
+
5903
+ readonly localAddress: string;
5904
+
5897
5905
  /**
5898
5906
  * local port connected to the socket
5899
5907
  */
@@ -6579,7 +6587,8 @@ declare module "bun" {
6579
6587
  timeout?: number;
6580
6588
 
6581
6589
  /**
6582
- * The signal to use when killing the process after a timeout or when the AbortSignal is aborted.
6590
+ * The signal to use when killing the process after a timeout, when the AbortSignal is aborted,
6591
+ * or when the process goes over the `maxBuffer` limit.
6583
6592
  *
6584
6593
  * @default "SIGTERM" (signal 15)
6585
6594
  *
@@ -6594,6 +6603,14 @@ declare module "bun" {
6594
6603
  * ```
6595
6604
  */
6596
6605
  killSignal?: string | number;
6606
+
6607
+ /**
6608
+ * The maximum number of bytes the process may output. If the process goes over this limit,
6609
+ * it is killed with signal `killSignal` (defaults to SIGTERM).
6610
+ *
6611
+ * @default undefined (no limit)
6612
+ */
6613
+ maxBuffer?: number;
6597
6614
  }
6598
6615
 
6599
6616
  type OptionsToSubprocess<Opts extends OptionsObject> =
@@ -6839,7 +6856,8 @@ declare module "bun" {
6839
6856
  resourceUsage: ResourceUsage;
6840
6857
 
6841
6858
  signalCode?: string;
6842
- exitedDueToTimeout?: true;
6859
+ exitedDueToTimeout?: boolean;
6860
+ exitedDueToMaxBuffer?: boolean;
6843
6861
  pid: number;
6844
6862
  }
6845
6863
 
package/docs/api/fetch.md CHANGED
@@ -337,7 +337,7 @@ This will print the request and response headers to your terminal:
337
337
  ```sh
338
338
  [fetch] > HTTP/1.1 GET http://example.com/
339
339
  [fetch] > Connection: keep-alive
340
- [fetch] > User-Agent: Bun/1.2.9-canary.20250403T140620
340
+ [fetch] > User-Agent: Bun/1.2.9-canary.20250404T140622
341
341
  [fetch] > Accept: */*
342
342
  [fetch] > Host: example.com
343
343
  [fetch] > Accept-Encoding: gzip, deflate, br
package/docs/api/spawn.md CHANGED
@@ -120,7 +120,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
120
120
  ```ts
121
121
  const proc = Bun.spawn(["bun", "--version"]);
122
122
  const text = await new Response(proc.stdout).text();
123
- console.log(text); // => "1.2.9-canary.20250403T140620"
123
+ console.log(text); // => "1.2.9-canary.20250404T140622"
124
124
  ```
125
125
 
126
126
  Configure the output stream by passing one of the following values to `stdout/stderr`:
@@ -253,6 +253,19 @@ const proc = Bun.spawn({
253
253
 
254
254
  The `killSignal` option also controls which signal is sent when an AbortSignal is aborted.
255
255
 
256
+ ## Using maxBuffer
257
+
258
+ For spawnSync, you can limit the maximum number of bytes of output before the process is killed:
259
+
260
+ ```ts
261
+ // KIll 'yes' after it emits over 100 bytes of output
262
+ const result = Bun.spawnSync({
263
+ cmd: ["yes"], // or ["bun", "exec", "yes"] on windows
264
+ maxBuffer: 100,
265
+ });
266
+ // process exits
267
+ ```
268
+
256
269
  ## Inter-process communication (IPC)
257
270
 
258
271
  Bun supports direct inter-process communication channel between two `bun` processes. To receive messages from a spawned Bun subprocess, specify an `ipc` handler.
@@ -423,6 +436,7 @@ namespace SpawnOptions {
423
436
  signal?: AbortSignal;
424
437
  timeout?: number;
425
438
  killSignal?: string | number;
439
+ maxBuffer?: number;
426
440
  }
427
441
 
428
442
  type Readable =
@@ -7,7 +7,7 @@ Use `bun publish` to publish a package to the npm registry.
7
7
  $ bun publish
8
8
 
9
9
  ## Output
10
- bun publish v1.2.9-canary.20250403T140620 (ca7428e9)
10
+ bun publish v1.2.9-canary.20250404T140622 (ca7428e9)
11
11
 
12
12
  packed 203B package.json
13
13
  packed 224B README.md
@@ -9,7 +9,7 @@ $ bunx nuxi init my-nuxt-app
9
9
  ✔ Which package manager would you like to use?
10
10
  bun
11
11
  ◐ Installing dependencies...
12
- bun install v1.2.9-canary.20250403T140620 (16b4bf34)
12
+ bun install v1.2.9-canary.20250404T140622 (16b4bf34)
13
13
  + @nuxt/devtools@0.8.2
14
14
  + nuxt@3.7.0
15
15
  785 packages installed [2.67s]
@@ -16,7 +16,7 @@ This will add the package to `peerDependencies` in `package.json`.
16
16
  ```json-diff
17
17
  {
18
18
  "peerDependencies": {
19
- + "@types/bun": "^1.2.9-canary.20250403T140620"
19
+ + "@types/bun": "^1.2.9-canary.20250404T140622"
20
20
  }
21
21
  }
22
22
  ```
@@ -28,7 +28,7 @@ Running `bun install` will install peer dependencies by default, unless marked o
28
28
  ```json-diff
29
29
  {
30
30
  "peerDependencies": {
31
- "@types/bun": "^1.2.9-canary.20250403T140620"
31
+ "@types/bun": "^1.2.9-canary.20250404T140622"
32
32
  },
33
33
  "peerDependenciesMeta": {
34
34
  + "@types/bun": {
@@ -97,7 +97,7 @@ $ bun update
97
97
  $ bun update @types/bun --latest
98
98
 
99
99
  # Update a dependency to a specific version
100
- $ bun update @types/bun@1.2.9-canary.20250403T140620
100
+ $ bun update @types/bun@1.2.9-canary.20250404T140622
101
101
 
102
102
  # Update all dependencies to the latest versions
103
103
  $ bun update --latest
@@ -21,7 +21,7 @@ Here's what the output of a typical test run looks like. In this case, there are
21
21
 
22
22
  ```sh
23
23
  $ bun test
24
- bun test v1.2.9-canary.20250403T140620 (9c68abdb)
24
+ bun test v1.2.9-canary.20250404T140622 (9c68abdb)
25
25
 
26
26
  test.test.js:
27
27
  ✓ add [0.87ms]
@@ -47,7 +47,7 @@ To only run certain test files, pass a positional argument to `bun test`. The ru
47
47
 
48
48
  ```sh
49
49
  $ bun test test3
50
- bun test v1.2.9-canary.20250403T140620 (9c68abdb)
50
+ bun test v1.2.9-canary.20250404T140622 (9c68abdb)
51
51
 
52
52
  test3.test.js:
53
53
  ✓ add [1.40ms]
@@ -85,7 +85,7 @@ Adding `-t add` will only run tests with "add" in the name. This works with test
85
85
 
86
86
  ```sh
87
87
  $ bun test -t add
88
- bun test v1.2.9-canary.20250403T140620 (9c68abdb)
88
+ bun test v1.2.9-canary.20250404T140622 (9c68abdb)
89
89
 
90
90
  test.test.js:
91
91
  ✓ add [1.79ms]
@@ -18,7 +18,7 @@ The first time this test is executed, Bun will evaluate the value passed into `e
18
18
 
19
19
  ```sh
20
20
  $ bun test test/snap
21
- bun test v1.2.9-canary.20250403T140620 (9c68abdb)
21
+ bun test v1.2.9-canary.20250404T140622 (9c68abdb)
22
22
 
23
23
  test/snap.test.ts:
24
24
  ✓ snapshot [1.48ms]
@@ -61,7 +61,7 @@ Later, when this test file is executed again, Bun will read the snapshot file an
61
61
 
62
62
  ```sh
63
63
  $ bun test
64
- bun test v1.2.9-canary.20250403T140620 (9c68abdb)
64
+ bun test v1.2.9-canary.20250404T140622 (9c68abdb)
65
65
 
66
66
  test/snap.test.ts:
67
67
  ✓ snapshot [1.05ms]
@@ -78,7 +78,7 @@ To update snapshots, use the `--update-snapshots` flag.
78
78
 
79
79
  ```sh
80
80
  $ bun test --update-snapshots
81
- bun test v1.2.9-canary.20250403T140620 (9c68abdb)
81
+ bun test v1.2.9-canary.20250404T140622 (9c68abdb)
82
82
 
83
83
  test/snap.test.ts:
84
84
  ✓ snapshot [0.86ms]
@@ -29,7 +29,7 @@ To regenerate snapshots, use the `--update-snapshots` flag.
29
29
 
30
30
  ```sh
31
31
  $ bun test --update-snapshots
32
- bun test v1.2.9-canary.20250403T140620 (9c68abdb)
32
+ bun test v1.2.9-canary.20250404T140622 (9c68abdb)
33
33
 
34
34
  test/snap.test.ts:
35
35
  ✓ snapshot [0.86ms]
@@ -5,7 +5,7 @@ name: Get the current Bun version
5
5
  Get the current version of Bun in a semver format.
6
6
 
7
7
  ```ts#index.ts
8
- Bun.version; // => "1.2.9-canary.20250403T140620"
8
+ Bun.version; // => "1.2.9-canary.20250404T140622"
9
9
  ```
10
10
 
11
11
  ---
@@ -14,7 +14,7 @@ Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1. Us
14
14
  ```bash#macOS/Linux_(curl)
15
15
  $ curl -fsSL https://bun.sh/install | bash # for macOS, Linux, and WSL
16
16
  # to install a specific version
17
- $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.9-canary.20250403T140620"
17
+ $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.9-canary.20250404T140622"
18
18
  ```
19
19
 
20
20
  ```bash#npm
@@ -189,10 +189,10 @@ Since Bun is a single binary, you can install older versions of Bun by re-runnin
189
189
 
190
190
  ### Installing a specific version of Bun on Linux/Mac
191
191
 
192
- To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.9-canary.20250403T140620`.
192
+ To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.9-canary.20250404T140622`.
193
193
 
194
194
  ```sh
195
- $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.9-canary.20250403T140620"
195
+ $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.9-canary.20250404T140622"
196
196
  ```
197
197
 
198
198
  ### Installing a specific version of Bun on Windows
@@ -201,7 +201,7 @@ On Windows, you can install a specific version of Bun by passing the version num
201
201
 
202
202
  ```sh
203
203
  # PowerShell:
204
- $ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.2.9-canary.20250403T140620"
204
+ $ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.2.9-canary.20250404T140622"
205
205
  ```
206
206
 
207
207
  ## Downloading Bun binaries directly
@@ -124,11 +124,11 @@ await fetch("https://example.com", {
124
124
  This prints the `fetch` request as a single-line `curl` command to let you copy-paste into your terminal to replicate the request.
125
125
 
126
126
  ```sh
127
- [fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.9-canary.20250403T140620" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
127
+ [fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.9-canary.20250404T140622" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
128
128
  [fetch] > HTTP/1.1 POST https://example.com/
129
129
  [fetch] > content-type: application/json
130
130
  [fetch] > Connection: keep-alive
131
- [fetch] > User-Agent: Bun/1.2.9-canary.20250403T140620
131
+ [fetch] > User-Agent: Bun/1.2.9-canary.20250404T140622
132
132
  [fetch] > Accept: */*
133
133
  [fetch] > Host: example.com
134
134
  [fetch] > Accept-Encoding: gzip, deflate, br
@@ -170,7 +170,7 @@ This prints the following to the console:
170
170
  [fetch] > HTTP/1.1 POST https://example.com/
171
171
  [fetch] > content-type: application/json
172
172
  [fetch] > Connection: keep-alive
173
- [fetch] > User-Agent: Bun/1.2.9-canary.20250403T140620
173
+ [fetch] > User-Agent: Bun/1.2.9-canary.20250404T140622
174
174
  [fetch] > Accept: */*
175
175
  [fetch] > Host: example.com
176
176
  [fetch] > Accept-Encoding: gzip, deflate, br
@@ -0,0 +1,87 @@
1
+ Configure `bun test` via `bunfig.toml` file and command-line options. This page documents the available configuration options for `bun test`.
2
+
3
+ ## bunfig.toml options
4
+
5
+ You can configure `bun test` behavior by adding a `[test]` section to your `bunfig.toml` file:
6
+
7
+ ```toml
8
+ [test]
9
+ # Options go here
10
+ ```
11
+
12
+ ### Test discovery
13
+
14
+ #### root
15
+
16
+ The `root` option specifies a root directory for test discovery, overriding the default behavior of scanning from the project root.
17
+
18
+ ```toml
19
+ [test]
20
+ root = "src" # Only scan for tests in the src directory
21
+ ```
22
+
23
+ ### Reporters
24
+
25
+ #### reporter.junit
26
+
27
+ Configure the JUnit reporter output file path directly in the config file:
28
+
29
+ ```toml
30
+ [test.reporter]
31
+ junit = "path/to/junit.xml" # Output path for JUnit XML report
32
+ ```
33
+
34
+ This complements the `--reporter=junit` and `--reporter-outfile` CLI flags.
35
+
36
+ ### Memory usage
37
+
38
+ #### smol
39
+
40
+ Enable the `--smol` memory-saving mode specifically for the test runner:
41
+
42
+ ```toml
43
+ [test]
44
+ smol = true # Reduce memory usage during test runs
45
+ ```
46
+
47
+ This is equivalent to using the `--smol` flag on the command line.
48
+
49
+ ### Coverage options
50
+
51
+ In addition to the options documented in the [coverage documentation](./coverage.md), the following options are available:
52
+
53
+ #### coverageSkipTestFiles
54
+
55
+ Exclude files matching test patterns (e.g., \*.test.ts) from the coverage report:
56
+
57
+ ```toml
58
+ [test]
59
+ coverageSkipTestFiles = true # Exclude test files from coverage reports
60
+ ```
61
+
62
+ #### coverageThreshold (Object form)
63
+
64
+ The coverage threshold can be specified either as a number (as shown in the coverage documentation) or as an object with specific thresholds:
65
+
66
+ ```toml
67
+ [test]
68
+ # Set specific thresholds for different coverage metrics
69
+ coverageThreshold = { lines = 0.9, functions = 0.8, statements = 0.85 }
70
+ ```
71
+
72
+ Setting any of these enables `fail_on_low_coverage`, causing the test run to fail if coverage is below the threshold.
73
+
74
+ #### coverageIgnoreSourcemaps
75
+
76
+ Internally, Bun transpiles every file. That means code coverage must also go through sourcemaps before they can be reported. We expose this as a flag to allow you to opt out of this behavior, but it will be confusing because during the transpilation process, Bun may move code around and change variable names. This option is mostly useful for debugging coverage issues.
77
+
78
+ ```toml
79
+ [test]
80
+ coverageIgnoreSourcemaps = true # Don't use sourcemaps for coverage analysis
81
+ ```
82
+
83
+ When using this option, you probably want to stick a `// @bun` comment at the top of the source file to opt out of the transpilation process.
84
+
85
+ ### Install settings inheritance
86
+
87
+ The `bun test` command inherits relevant network and installation configuration (registry, cafile, prefer, exact, etc.) from the `[install]` section of bunfig.toml. This is important if tests need to interact with private registries or require specific install behaviors triggered during the test run.
@@ -52,9 +52,22 @@ It is possible to specify a coverage threshold in `bunfig.toml`. If your test su
52
52
  coverageThreshold = 0.9
53
53
 
54
54
  # to set different thresholds for lines and functions
55
- coverageThreshold = { lines = 0.9, functions = 0.9 }
55
+ coverageThreshold = { lines = 0.9, functions = 0.9, statements = 0.9 }
56
56
  ```
57
57
 
58
+ Setting any of these thresholds enables `fail_on_low_coverage`, causing the test run to fail if coverage is below the threshold.
59
+
60
+ ### Exclude test files from coverage
61
+
62
+ By default, test files themselves are included in coverage reports. You can exclude them with:
63
+
64
+ ```toml
65
+ [test]
66
+ coverageSkipTestFiles = true # default false
67
+ ```
68
+
69
+ This will exclude files matching test patterns (e.g., _.test.ts, _\_spec.js) from the coverage report.
70
+
58
71
  ### Sourcemaps
59
72
 
60
73
  Internally, Bun transpiles all files by default, so Bun automatically generates an internal [source map](https://web.dev/source-maps/) that maps lines of your original source code onto Bun's internal representation. If for any reason you want to disable this, set `test.coverageIgnoreSourcemaps` to `true`; this will rarely be desirable outside of advanced use cases.
@@ -64,6 +77,14 @@ Internally, Bun transpiles all files by default, so Bun automatically generates
64
77
  coverageIgnoreSourcemaps = true # default false
65
78
  ```
66
79
 
80
+ ### Coverage defaults
81
+
82
+ By default, coverage reports:
83
+
84
+ 1. Exclude `node_modules` directories
85
+ 2. Exclude files loaded via non-JS/TS loaders (e.g., .css, .txt) unless a custom JS loader is specified
86
+ 3. Include test files themselves (can be disabled with `coverageSkipTestFiles = true` as shown above)
87
+
67
88
  ### Coverage reporters
68
89
 
69
90
  By default, coverage reports will be printed to the console.
@@ -0,0 +1,85 @@
1
+ bun test's file discovery mechanism determines which files to run as tests. Understanding how it works helps you structure your test files effectively.
2
+
3
+ ## Default Discovery Logic
4
+
5
+ By default, `bun test` recursively searches the project directory for files that match specific patterns:
6
+
7
+ - `*.test.{js|jsx|ts|tsx}` - Files ending with `.test.js`, `.test.jsx`, `.test.ts`, or `.test.tsx`
8
+ - `*_test.{js|jsx|ts|tsx}` - Files ending with `_test.js`, `_test.jsx`, `_test.ts`, or `_test.tsx`
9
+ - `*.spec.{js|jsx|ts|tsx}` - Files ending with `.spec.js`, `.spec.jsx`, `.spec.ts`, or `.spec.tsx`
10
+ - `*_spec.{js|jsx|ts|tsx}` - Files ending with `_spec.js`, `_spec.jsx`, `_spec.ts`, or `_spec.tsx`
11
+
12
+ ## Exclusions
13
+
14
+ By default, Bun test ignores:
15
+
16
+ - `node_modules` directories
17
+ - Hidden directories (those starting with a period `.`)
18
+ - Files that don't have JavaScript-like extensions (based on available loaders)
19
+
20
+ ## Customizing Test Discovery
21
+
22
+ ### Position Arguments as Filters
23
+
24
+ You can filter which test files run by passing additional positional arguments to `bun test`:
25
+
26
+ ```bash
27
+ $ bun test <filter> <filter> ...
28
+ ```
29
+
30
+ Any test file with a path that contains one of the filters will run. These filters are simple substring matches, not glob patterns.
31
+
32
+ For example, to run all tests in a `utils` directory:
33
+
34
+ ```bash
35
+ $ bun test utils
36
+ ```
37
+
38
+ This would match files like `src/utils/string.test.ts` and `lib/utils/array_test.js`.
39
+
40
+ ### Specifying Exact File Paths
41
+
42
+ To run a specific file in the test runner, make sure the path starts with `./` or `/` to distinguish it from a filter name:
43
+
44
+ ```bash
45
+ $ bun test ./test/specific-file.test.ts
46
+ ```
47
+
48
+ ### Filter by Test Name
49
+
50
+ To filter tests by name rather than file path, use the `-t`/`--test-name-pattern` flag with a regex pattern:
51
+
52
+ ```sh
53
+ # run all tests with "addition" in the name
54
+ $ bun test --test-name-pattern addition
55
+ ```
56
+
57
+ The pattern is matched against a concatenated string of the test name prepended with the labels of all its parent describe blocks, separated by spaces. For example, a test defined as:
58
+
59
+ ```js
60
+ describe("Math", () => {
61
+ describe("operations", () => {
62
+ test("should add correctly", () => {
63
+ // ...
64
+ });
65
+ });
66
+ });
67
+ ```
68
+
69
+ Would be matched against the string "Math operations should add correctly".
70
+
71
+ ### Changing the Root Directory
72
+
73
+ By default, Bun looks for test files starting from the current working directory. You can change this with the `root` option in your `bunfig.toml`:
74
+
75
+ ```toml
76
+ [test]
77
+ root = "src" # Only scan for tests in the src directory
78
+ ```
79
+
80
+ ## Execution Order
81
+
82
+ Tests are run in the following order:
83
+
84
+ 1. Test files are executed sequentially (not in parallel)
85
+ 2. Within each file, tests run sequentially based on their definition order
package/docs/test/dom.md CHANGED
@@ -55,7 +55,7 @@ Let's run this test with `bun test`:
55
55
 
56
56
  ```bash
57
57
  $ bun test
58
- bun test v1.2.9-canary.20250403T140620
58
+ bun test v1.2.9-canary.20250404T140622
59
59
 
60
60
  dom.test.ts:
61
61
  ✓ dom test [0.82ms]
@@ -56,9 +56,9 @@ The following properties and methods are implemented on mock functions.
56
56
  - [x] [mockFn.mock.instances](https://jestjs.io/docs/mock-function-api#mockfnmockinstances)
57
57
  - [x] [mockFn.mock.contexts](https://jestjs.io/docs/mock-function-api#mockfnmockcontexts)
58
58
  - [x] [mockFn.mock.lastCall](https://jestjs.io/docs/mock-function-api#mockfnmocklastcall)
59
- - [x] [mockFn.mockClear()](https://jestjs.io/docs/mock-function-api#mockfnmockclear)
60
- - [x] [mockFn.mockReset()](https://jestjs.io/docs/mock-function-api#mockfnmockreset)
61
- - [x] [mockFn.mockRestore()](https://jestjs.io/docs/mock-function-api#mockfnmockrestore)
59
+ - [x] [mockFn.mockClear()](https://jestjs.io/docs/mock-function-api#mockfnmockclear) - Clears call history
60
+ - [x] [mockFn.mockReset()](https://jestjs.io/docs/mock-function-api#mockfnmockreset) - Clears call history and removes implementation
61
+ - [x] [mockFn.mockRestore()](https://jestjs.io/docs/mock-function-api#mockfnmockrestore) - Restores original implementation
62
62
  - [x] [mockFn.mockImplementation(fn)](https://jestjs.io/docs/mock-function-api#mockfnmockimplementationfn)
63
63
  - [x] [mockFn.mockImplementationOnce(fn)](https://jestjs.io/docs/mock-function-api#mockfnmockimplementationoncefn)
64
64
  - [x] [mockFn.mockName(name)](https://jestjs.io/docs/mock-function-api#mockfnmocknamename)
@@ -197,7 +197,59 @@ After resolution, the mocked module is stored in the ES Module registry **and**
197
197
 
198
198
  The callback function is called lazily, only if the module is imported or required. This means that you can use `mock.module()` to mock modules that don't exist yet, and it means that you can use `mock.module()` to mock modules that are imported by other modules.
199
199
 
200
- ## Restore all function mocks to their original values with `mock.restore()`
200
+ ### Module Mock Implementation Details
201
+
202
+ Understanding how `mock.module()` works helps you use it more effectively:
203
+
204
+ 1. **Cache Interaction**: Module mocks interacts with both ESM and CommonJS module caches.
205
+
206
+ 2. **Lazy Evaluation**: The mock factory callback is only evaluated when the module is actually imported or required.
207
+
208
+ 3. **Path Resolution**: Bun automatically resolves the module specifier as though you were doing an import, supporting:
209
+ - Relative paths (`'./module'`)
210
+ - Absolute paths (`'/path/to/module'`)
211
+ - Package names (`'lodash'`)
212
+
213
+ 4. **Import Timing Effects**:
214
+ - When mocking before first import: No side effects from the original module occur
215
+ - When mocking after import: The original module's side effects have already happened
216
+ - For this reason, using `--preload` is recommended for mocks that need to prevent side effects
217
+
218
+ 5. **Live Bindings**: Mocked ESM modules maintain live bindings, so changing the mock will update all existing imports
219
+
220
+ ## Global Mock Functions
221
+
222
+ ### Clear all mocks with `mock.clearAllMocks()`
223
+
224
+ Reset all mock function state (calls, results, etc.) without restoring their original implementation:
225
+
226
+ ```ts
227
+ import { expect, mock, test } from "bun:test";
228
+
229
+ const random1 = mock(() => Math.random());
230
+ const random2 = mock(() => Math.random());
231
+
232
+ test("clearing all mocks", () => {
233
+ random1();
234
+ random2();
235
+
236
+ expect(random1).toHaveBeenCalledTimes(1);
237
+ expect(random2).toHaveBeenCalledTimes(1);
238
+
239
+ mock.clearAllMocks();
240
+
241
+ expect(random1).toHaveBeenCalledTimes(0);
242
+ expect(random2).toHaveBeenCalledTimes(0);
243
+
244
+ // Note: implementations are preserved
245
+ expect(typeof random1()).toBe("number");
246
+ expect(typeof random2()).toBe("number");
247
+ });
248
+ ```
249
+
250
+ This resets the `.mock.calls`, `.mock.instances`, `.mock.contexts`, and `.mock.results` properties of all mocks, but unlike `mock.restore()`, it does not restore the original implementation.
251
+
252
+ ### Restore all function mocks with `mock.restore()`
201
253
 
202
254
  Instead of manually restoring each mock individually with `mockFn.mockRestore()`, restore all mocks with one command by calling `mock.restore()`. Doing so does not reset the value of modules overridden with `mock.module()`.
203
255
 
@@ -234,3 +286,28 @@ test('foo, bar, baz', () => {
234
286
  expect(bazSpy).toBe('baz');
235
287
  });
236
288
  ```
289
+
290
+ ## Vitest Compatibility
291
+
292
+ For added compatibility with tests written for [Vitest](https://vitest.dev/), Bun provides the `vi` global object as an alias for parts of the Jest mocking API:
293
+
294
+ ```ts
295
+ import { test, expect } from "bun:test";
296
+
297
+ // Using the 'vi' alias similar to Vitest
298
+ test("vitest compatibility", () => {
299
+ const mockFn = vi.fn(() => 42);
300
+
301
+ mockFn();
302
+ expect(mockFn).toHaveBeenCalled();
303
+
304
+ // The following functions are available on the vi object:
305
+ // vi.fn
306
+ // vi.spyOn
307
+ // vi.mock
308
+ // vi.restoreAllMocks
309
+ // vi.clearAllMocks
310
+ });
311
+ ```
312
+
313
+ This makes it easier to port tests from Vitest to Bun without having to rewrite all your mocks.