bun-types 1.3.2-canary.20251104T140728 → 1.3.2-canary.20251106T140813
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 +4 -4
- package/docs/README.md +28 -0
- package/globals.d.ts +0 -1
- package/overrides.d.ts +45 -15
- package/package.json +1 -1
- package/test.d.ts +1 -1
- package/docs/api/binary-data.md +0 -1038
- package/docs/api/cc.md +0 -197
- package/docs/api/color.md +0 -262
- package/docs/api/console.md +0 -57
- package/docs/api/cookie.md +0 -449
- package/docs/api/dns.md +0 -110
- package/docs/api/fetch.md +0 -463
- package/docs/api/ffi.md +0 -557
- package/docs/api/file-io.md +0 -366
- package/docs/api/file-system-router.md +0 -112
- package/docs/api/file.md +0 -19
- package/docs/api/glob.md +0 -178
- package/docs/api/globals.md +0 -387
- package/docs/api/hashing.md +0 -319
- package/docs/api/html-rewriter.md +0 -334
- package/docs/api/http.md +0 -1408
- package/docs/api/import-meta.md +0 -69
- package/docs/api/node-api.md +0 -14
- package/docs/api/redis.md +0 -597
- package/docs/api/s3.md +0 -850
- package/docs/api/secrets.md +0 -319
- package/docs/api/semver.md +0 -52
- package/docs/api/spawn.md +0 -582
- package/docs/api/sql.md +0 -1374
- package/docs/api/sqlite.md +0 -694
- package/docs/api/streams.md +0 -230
- package/docs/api/tcp.md +0 -221
- package/docs/api/transpiler.md +0 -276
- package/docs/api/udp.md +0 -123
- package/docs/api/utils.md +0 -891
- package/docs/api/websockets.md +0 -573
- package/docs/api/workers.md +0 -322
- package/docs/api/yaml.md +0 -668
- package/docs/benchmarks.md +0 -120
- package/docs/bun-flavored-toml.md +0 -42
- package/docs/bundler/css.md +0 -1028
- package/docs/bundler/css_modules.md +0 -145
- package/docs/bundler/executables.md +0 -626
- package/docs/bundler/fullstack.md +0 -418
- package/docs/bundler/hmr.md +0 -234
- package/docs/bundler/html.md +0 -349
- package/docs/bundler/index.md +0 -1735
- package/docs/bundler/intro.md +0 -75
- package/docs/bundler/loaders.md +0 -410
- package/docs/bundler/macros.md +0 -329
- package/docs/bundler/plugins.md +0 -449
- package/docs/bundler/vs-esbuild.md +0 -1127
- package/docs/cli/add.md +0 -173
- package/docs/cli/bun-completions.md +0 -3
- package/docs/cli/bun-create.md +0 -338
- package/docs/cli/bun-install.md +0 -349
- package/docs/cli/bun-upgrade.md +0 -39
- package/docs/cli/bunx.md +0 -89
- package/docs/cli/filter.md +0 -90
- package/docs/cli/info.md +0 -65
- package/docs/cli/init.md +0 -85
- package/docs/cli/install.md +0 -344
- package/docs/cli/link.md +0 -40
- package/docs/cli/outdated.md +0 -90
- package/docs/cli/patch-commit.md +0 -11
- package/docs/cli/pm.md +0 -285
- package/docs/cli/publish.md +0 -120
- package/docs/cli/remove.md +0 -7
- package/docs/cli/run.md +0 -261
- package/docs/cli/test.md +0 -397
- package/docs/cli/unlink.md +0 -9
- package/docs/cli/update.md +0 -129
- package/docs/cli/why.md +0 -67
- package/docs/contributing/upgrading-webkit.md +0 -57
- package/docs/ecosystem/elysia.md +0 -24
- package/docs/ecosystem/express.md +0 -37
- package/docs/ecosystem/hono.md +0 -18
- package/docs/ecosystem/react.md +0 -65
- package/docs/ecosystem/stric.md +0 -38
- package/docs/guides/binary/arraybuffer-to-array.md +0 -27
- package/docs/guides/binary/arraybuffer-to-blob.md +0 -24
- package/docs/guides/binary/arraybuffer-to-buffer.md +0 -25
- package/docs/guides/binary/arraybuffer-to-string.md +0 -15
- package/docs/guides/binary/arraybuffer-to-typedarray.md +0 -39
- package/docs/guides/binary/blob-to-arraybuffer.md +0 -14
- package/docs/guides/binary/blob-to-dataview.md +0 -14
- package/docs/guides/binary/blob-to-stream.md +0 -14
- package/docs/guides/binary/blob-to-string.md +0 -15
- package/docs/guides/binary/blob-to-typedarray.md +0 -14
- package/docs/guides/binary/buffer-to-arraybuffer.md +0 -14
- package/docs/guides/binary/buffer-to-blob.md +0 -14
- package/docs/guides/binary/buffer-to-readablestream.md +0 -41
- package/docs/guides/binary/buffer-to-string.md +0 -25
- package/docs/guides/binary/buffer-to-typedarray.md +0 -14
- package/docs/guides/binary/dataview-to-string.md +0 -15
- package/docs/guides/binary/typedarray-to-arraybuffer.md +0 -25
- package/docs/guides/binary/typedarray-to-blob.md +0 -16
- package/docs/guides/binary/typedarray-to-buffer.md +0 -14
- package/docs/guides/binary/typedarray-to-dataview.md +0 -14
- package/docs/guides/binary/typedarray-to-readablestream.md +0 -41
- package/docs/guides/binary/typedarray-to-string.md +0 -16
- package/docs/guides/deployment/railway.md +0 -157
- package/docs/guides/ecosystem/astro.md +0 -72
- package/docs/guides/ecosystem/discordjs.md +0 -77
- package/docs/guides/ecosystem/docker.md +0 -140
- package/docs/guides/ecosystem/drizzle.md +0 -185
- package/docs/guides/ecosystem/edgedb.md +0 -228
- package/docs/guides/ecosystem/elysia.md +0 -31
- package/docs/guides/ecosystem/express.md +0 -40
- package/docs/guides/ecosystem/hono.md +0 -39
- package/docs/guides/ecosystem/mongoose.md +0 -87
- package/docs/guides/ecosystem/neon-drizzle.md +0 -220
- package/docs/guides/ecosystem/neon-serverless-postgres.md +0 -55
- package/docs/guides/ecosystem/nextjs.md +0 -49
- package/docs/guides/ecosystem/nuxt.md +0 -56
- package/docs/guides/ecosystem/pm2.md +0 -57
- package/docs/guides/ecosystem/prisma.md +0 -141
- package/docs/guides/ecosystem/qwik.md +0 -107
- package/docs/guides/ecosystem/react.md +0 -50
- package/docs/guides/ecosystem/remix.md +0 -78
- package/docs/guides/ecosystem/render.md +0 -79
- package/docs/guides/ecosystem/sentry.md +0 -52
- package/docs/guides/ecosystem/solidstart.md +0 -58
- package/docs/guides/ecosystem/ssr-react.md +0 -51
- package/docs/guides/ecosystem/stric.md +0 -55
- package/docs/guides/ecosystem/sveltekit.md +0 -125
- package/docs/guides/ecosystem/systemd.md +0 -113
- package/docs/guides/ecosystem/vite.md +0 -71
- package/docs/guides/html-rewriter/extract-links.md +0 -68
- package/docs/guides/html-rewriter/extract-social-meta.md +0 -93
- package/docs/guides/http/cluster.md +0 -66
- package/docs/guides/http/fetch-unix.md +0 -33
- package/docs/guides/http/fetch.md +0 -24
- package/docs/guides/http/file-uploads.md +0 -94
- package/docs/guides/http/hot.md +0 -26
- package/docs/guides/http/proxy.md +0 -24
- package/docs/guides/http/server.md +0 -46
- package/docs/guides/http/simple.md +0 -18
- package/docs/guides/http/stream-file.md +0 -48
- package/docs/guides/http/stream-iterator.md +0 -47
- package/docs/guides/http/stream-node-streams-in-bun.md +0 -20
- package/docs/guides/http/tls.md +0 -30
- package/docs/guides/install/add-dev.md +0 -26
- package/docs/guides/install/add-git.md +0 -36
- package/docs/guides/install/add-optional.md +0 -25
- package/docs/guides/install/add-peer.md +0 -43
- package/docs/guides/install/add-tarball.md +0 -33
- package/docs/guides/install/add.md +0 -42
- package/docs/guides/install/azure-artifacts.md +0 -73
- package/docs/guides/install/cicd.md +0 -41
- package/docs/guides/install/custom-registry.md +0 -30
- package/docs/guides/install/from-npm-install-to-bun-install.md +0 -214
- package/docs/guides/install/git-diff-bun-lockfile.md +0 -44
- package/docs/guides/install/jfrog-artifactory.md +0 -28
- package/docs/guides/install/npm-alias.md +0 -23
- package/docs/guides/install/registry-scope.md +0 -38
- package/docs/guides/install/trusted.md +0 -46
- package/docs/guides/install/workspaces.md +0 -70
- package/docs/guides/install/yarnlock.md +0 -44
- package/docs/guides/process/argv.md +0 -58
- package/docs/guides/process/ctrl-c.md +0 -16
- package/docs/guides/process/ipc.md +0 -66
- package/docs/guides/process/nanoseconds.md +0 -13
- package/docs/guides/process/os-signals.md +0 -39
- package/docs/guides/process/spawn-stderr.md +0 -31
- package/docs/guides/process/spawn-stdout.md +0 -26
- package/docs/guides/process/spawn.md +0 -41
- package/docs/guides/process/stdin.md +0 -54
- package/docs/guides/read-file/arraybuffer.md +0 -28
- package/docs/guides/read-file/buffer.md +0 -19
- package/docs/guides/read-file/exists.md +0 -16
- package/docs/guides/read-file/json.md +0 -17
- package/docs/guides/read-file/mime.md +0 -20
- package/docs/guides/read-file/stream.md +0 -26
- package/docs/guides/read-file/string.md +0 -22
- package/docs/guides/read-file/uint8array.md +0 -21
- package/docs/guides/read-file/watch.md +0 -68
- package/docs/guides/runtime/build-time-constants.md +0 -293
- package/docs/guides/runtime/cicd.md +0 -43
- package/docs/guides/runtime/codesign-macos-executable.md +0 -56
- package/docs/guides/runtime/define-constant.md +0 -145
- package/docs/guides/runtime/delete-directory.md +0 -37
- package/docs/guides/runtime/delete-file.md +0 -19
- package/docs/guides/runtime/heap-snapshot.md +0 -26
- package/docs/guides/runtime/import-html.md +0 -15
- package/docs/guides/runtime/import-json.md +0 -44
- package/docs/guides/runtime/import-toml.md +0 -30
- package/docs/guides/runtime/import-yaml.md +0 -102
- package/docs/guides/runtime/read-env.md +0 -32
- package/docs/guides/runtime/set-env.md +0 -47
- package/docs/guides/runtime/shell.md +0 -40
- package/docs/guides/runtime/timezone.md +0 -35
- package/docs/guides/runtime/tsconfig-paths.md +0 -29
- package/docs/guides/runtime/typescript.md +0 -49
- package/docs/guides/runtime/vscode-debugger.md +0 -47
- package/docs/guides/runtime/web-debugger.md +0 -82
- package/docs/guides/streams/node-readable-to-arraybuffer.md +0 -11
- package/docs/guides/streams/node-readable-to-blob.md +0 -11
- package/docs/guides/streams/node-readable-to-json.md +0 -12
- package/docs/guides/streams/node-readable-to-string.md +0 -12
- package/docs/guides/streams/node-readable-to-uint8array.md +0 -11
- package/docs/guides/streams/to-array.md +0 -14
- package/docs/guides/streams/to-arraybuffer.md +0 -14
- package/docs/guides/streams/to-blob.md +0 -14
- package/docs/guides/streams/to-buffer.md +0 -15
- package/docs/guides/streams/to-json.md +0 -14
- package/docs/guides/streams/to-string.md +0 -14
- package/docs/guides/streams/to-typedarray.md +0 -22
- package/docs/guides/test/bail.md +0 -22
- package/docs/guides/test/coverage-threshold.md +0 -60
- package/docs/guides/test/coverage.md +0 -44
- package/docs/guides/test/happy-dom.md +0 -68
- package/docs/guides/test/migrate-from-jest.md +0 -143
- package/docs/guides/test/mock-clock.md +0 -48
- package/docs/guides/test/mock-functions.md +0 -68
- package/docs/guides/test/rerun-each.md +0 -14
- package/docs/guides/test/run-tests.md +0 -111
- package/docs/guides/test/skip-tests.md +0 -39
- package/docs/guides/test/snapshot.md +0 -95
- package/docs/guides/test/spy-on.md +0 -46
- package/docs/guides/test/svelte-test.md +0 -120
- package/docs/guides/test/testing-library.md +0 -92
- package/docs/guides/test/timeout.md +0 -15
- package/docs/guides/test/todo-tests.md +0 -67
- package/docs/guides/test/update-snapshots.md +0 -46
- package/docs/guides/test/watch-mode.md +0 -19
- package/docs/guides/util/base64.md +0 -15
- package/docs/guides/util/deep-equals.md +0 -39
- package/docs/guides/util/deflate.md +0 -18
- package/docs/guides/util/detect-bun.md +0 -23
- package/docs/guides/util/entrypoint.md +0 -17
- package/docs/guides/util/escape-html.md +0 -22
- package/docs/guides/util/file-url-to-path.md +0 -14
- package/docs/guides/util/gzip.md +0 -18
- package/docs/guides/util/hash-a-password.md +0 -54
- package/docs/guides/util/import-meta-dir.md +0 -13
- package/docs/guides/util/import-meta-file.md +0 -13
- package/docs/guides/util/import-meta-path.md +0 -13
- package/docs/guides/util/javascript-uuid.md +0 -23
- package/docs/guides/util/main.md +0 -32
- package/docs/guides/util/path-to-file-url.md +0 -14
- package/docs/guides/util/sleep.md +0 -22
- package/docs/guides/util/version.md +0 -21
- package/docs/guides/util/which-path-to-executable-bin.md +0 -15
- package/docs/guides/websocket/compression.md +0 -31
- package/docs/guides/websocket/context.md +0 -77
- package/docs/guides/websocket/pubsub.md +0 -41
- package/docs/guides/websocket/simple.md +0 -33
- package/docs/guides/write-file/append.md +0 -52
- package/docs/guides/write-file/basic.md +0 -44
- package/docs/guides/write-file/blob.md +0 -28
- package/docs/guides/write-file/cat.md +0 -17
- package/docs/guides/write-file/file-cp.md +0 -16
- package/docs/guides/write-file/filesink.md +0 -52
- package/docs/guides/write-file/response.md +0 -17
- package/docs/guides/write-file/stdout.md +0 -21
- package/docs/guides/write-file/stream.md +0 -17
- package/docs/guides/write-file/unlink.md +0 -16
- package/docs/index.md +0 -77
- package/docs/install/audit.md +0 -57
- package/docs/install/cache.md +0 -59
- package/docs/install/catalogs.md +0 -298
- package/docs/install/index.md +0 -248
- package/docs/install/isolated.md +0 -197
- package/docs/install/lifecycle.md +0 -46
- package/docs/install/lockfile.md +0 -58
- package/docs/install/npmrc.md +0 -105
- package/docs/install/overrides.md +0 -73
- package/docs/install/patch.md +0 -59
- package/docs/install/registries.md +0 -30
- package/docs/install/security-scanner-api.md +0 -81
- package/docs/install/workspaces.md +0 -114
- package/docs/installation.md +0 -327
- package/docs/project/asan.md +0 -124
- package/docs/project/benchmarking.md +0 -203
- package/docs/project/bindgen.md +0 -225
- package/docs/project/building-windows.md +0 -162
- package/docs/project/contributing.md +0 -347
- package/docs/project/internals/build-process-for-ci.md +0 -75
- package/docs/project/licensing.md +0 -73
- package/docs/project/roadmap.md +0 -87
- package/docs/quickstart.md +0 -157
- package/docs/runtime/autoimport.md +0 -94
- package/docs/runtime/bun-apis.md +0 -207
- package/docs/runtime/bunfig.md +0 -772
- package/docs/runtime/debugger.md +0 -325
- package/docs/runtime/env.md +0 -253
- package/docs/runtime/hot.md +0 -145
- package/docs/runtime/index.md +0 -312
- package/docs/runtime/jsx.md +0 -385
- package/docs/runtime/loaders.md +0 -130
- package/docs/runtime/modules.md +0 -320
- package/docs/runtime/nodejs-apis.md +0 -463
- package/docs/runtime/plugins.md +0 -561
- package/docs/runtime/shell.md +0 -605
- package/docs/runtime/typescript.md +0 -139
- package/docs/runtime/web-apis.md +0 -128
- package/docs/test/configuration.md +0 -154
- package/docs/test/coverage.md +0 -142
- package/docs/test/discovery.md +0 -85
- package/docs/test/dom.md +0 -75
- package/docs/test/examples/concurrent-test-glob.md +0 -132
- package/docs/test/hot.md +0 -15
- package/docs/test/lifecycle.md +0 -81
- package/docs/test/mocks.md +0 -313
- package/docs/test/reporters.md +0 -117
- package/docs/test/runtime-behavior.md +0 -95
- package/docs/test/snapshots.md +0 -68
- package/docs/test/time.md +0 -126
- package/docs/test/writing.md +0 -825
- package/docs/typescript.md +0 -53
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a ReadableStream to a Uint8Array
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats. This snippet reads the contents of a `ReadableStream` to an [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), then creates a [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) that points to the buffer.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
const stream = new ReadableStream();
|
|
9
|
-
const buf = await Bun.readableStreamToArrayBuffer(stream);
|
|
10
|
-
const uint8 = new Uint8Array(buf);
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Additionally, there is a convenience method to convert to `Uint8Array` directly.
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
const stream = new ReadableStream();
|
|
17
|
-
const uint8 = await Bun.readableStreamToBytes(stream);
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
package/docs/guides/test/bail.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Bail early with the Bun test runner
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Use the `--bail` flag to bail on a test run after a single failure. This is useful for aborting as soon as possible in a continuous integration environment.
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
$ bun test --bail
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
To bail after a certain threshold of failures, optionally specify a number after the flag.
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
# bail after 10 failures
|
|
17
|
-
$ bun test --bail=10
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
See [Docs > Test runner](https://bun.sh/docs/cli/test) for complete documentation of `bun test`.
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Set a code coverage threshold with the Bun test runner
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun's test runner supports built-in code coverage reporting via the `--coverage` flag.
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
$ bun test --coverage
|
|
9
|
-
|
|
10
|
-
test.test.ts:
|
|
11
|
-
✓ math > add [0.71ms]
|
|
12
|
-
✓ math > multiply [0.03ms]
|
|
13
|
-
✓ random [0.13ms]
|
|
14
|
-
-------------|---------|---------|-------------------
|
|
15
|
-
File | % Funcs | % Lines | Uncovered Line #s
|
|
16
|
-
-------------|---------|---------|-------------------
|
|
17
|
-
All files | 66.67 | 77.78 |
|
|
18
|
-
math.ts | 50.00 | 66.67 |
|
|
19
|
-
random.ts | 50.00 | 66.67 |
|
|
20
|
-
-------------|---------|---------|-------------------
|
|
21
|
-
|
|
22
|
-
3 pass
|
|
23
|
-
0 fail
|
|
24
|
-
3 expect() calls
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
To set a minimum coverage threshold, add the following line to your `bunfig.toml`. This requires that 90% of your codebase is covered by tests.
|
|
30
|
-
|
|
31
|
-
```toml
|
|
32
|
-
[test]
|
|
33
|
-
# to require 90% line-level and function-level coverage
|
|
34
|
-
coverageThreshold = 0.9
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
If your test suite does not meet this threshold, `bun test` will exit with a non-zero exit code to signal a failure.
|
|
40
|
-
|
|
41
|
-
```sh
|
|
42
|
-
$ bun test --coverage
|
|
43
|
-
<test output>
|
|
44
|
-
$ echo $?
|
|
45
|
-
1 # this is the exit code of the previous command
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
Different thresholds can be set for line-level and function-level coverage.
|
|
51
|
-
|
|
52
|
-
```toml
|
|
53
|
-
[test]
|
|
54
|
-
# to set different thresholds for lines and functions
|
|
55
|
-
coverageThreshold = { lines = 0.5, functions = 0.7 }
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
See [Docs > Test runner > Coverage](https://bun.sh/docs/test/coverage) for complete documentation on code coverage reporting in Bun.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Generate code coverage reports with the Bun test runner
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun's test runner supports built-in _code coverage reporting_. This makes it easy to see how much of the codebase is covered by tests and find areas that are not currently well-tested.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
Pass the `--coverage` flag to `bun test` to enable this feature. This will print a coverage report after the test run.
|
|
10
|
-
|
|
11
|
-
The coverage report lists the source files that were executed during the test run, the percentage of functions and lines that were executed, and the line ranges that were not executed during the run.
|
|
12
|
-
|
|
13
|
-
```sh
|
|
14
|
-
$ bun test --coverage
|
|
15
|
-
|
|
16
|
-
test.test.ts:
|
|
17
|
-
✓ math > add [0.71ms]
|
|
18
|
-
✓ math > multiply [0.03ms]
|
|
19
|
-
✓ random [0.13ms]
|
|
20
|
-
-------------|---------|---------|-------------------
|
|
21
|
-
File | % Funcs | % Lines | Uncovered Line #s
|
|
22
|
-
-------------|---------|---------|-------------------
|
|
23
|
-
All files | 66.67 | 77.78 |
|
|
24
|
-
math.ts | 50.00 | 66.67 |
|
|
25
|
-
random.ts | 50.00 | 66.67 |
|
|
26
|
-
-------------|---------|---------|-------------------
|
|
27
|
-
|
|
28
|
-
3 pass
|
|
29
|
-
0 fail
|
|
30
|
-
3 expect() calls
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
To always enable coverage reporting by default, add the following line to your `bunfig.toml`:
|
|
36
|
-
|
|
37
|
-
```toml
|
|
38
|
-
[test]
|
|
39
|
-
coverage = true # always enable coverage
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
|
|
44
|
-
Refer to [Docs > Test runner > Coverage](https://bun.sh/docs/test/coverage) for complete documentation on code coverage reporting in Bun.
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Write browser DOM tests with Bun and happy-dom
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
You can write and run browser tests with Bun's test runner in conjunction with [Happy DOM](https://github.com/capricorn86/happy-dom). Happy DOM implements mocked versions of browser APIs like `document` and `location`.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
To get started, install `happy-dom`.
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
$ bun add -d @happy-dom/global-registrator
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
This module exports a "registrator" that injects the mocked browser APIs to the global scope.
|
|
18
|
-
|
|
19
|
-
```ts#happydom.ts
|
|
20
|
-
import { GlobalRegistrator } from "@happy-dom/global-registrator";
|
|
21
|
-
|
|
22
|
-
GlobalRegistrator.register();
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
We need to make sure this file is executed before any of our test files. That's a job for Bun's built-in [_preload_]() functionality. Create a `bunfig.toml` file in the root of your project (if it doesn't already exist) and add the following lines.
|
|
28
|
-
|
|
29
|
-
The `./happydom.ts` file should contain the registration code above.
|
|
30
|
-
|
|
31
|
-
```toml#bunfig.toml
|
|
32
|
-
[test]
|
|
33
|
-
preload = "./happydom.ts"
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
Now running `bun test` inside our project will automatically execute `happydom.ts` first. We can start writing tests that use browser APIs.
|
|
39
|
-
|
|
40
|
-
```ts
|
|
41
|
-
import { test, expect } from "bun:test";
|
|
42
|
-
|
|
43
|
-
test("set button text", () => {
|
|
44
|
-
document.body.innerHTML = `<button>My button</button>`;
|
|
45
|
-
const button = document.querySelector("button");
|
|
46
|
-
expect(button?.innerText).toEqual("My button");
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
With Happy DOM properly configured, this test runs as expected.
|
|
53
|
-
|
|
54
|
-
```sh
|
|
55
|
-
$ bun test
|
|
56
|
-
|
|
57
|
-
dom.test.ts:
|
|
58
|
-
✓ set button text [0.82ms]
|
|
59
|
-
|
|
60
|
-
1 pass
|
|
61
|
-
0 fail
|
|
62
|
-
1 expect() calls
|
|
63
|
-
Ran 1 tests across 1 files. 1 total [125.00ms]
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
Refer to the [Happy DOM repo](https://github.com/capricorn86/happy-dom) and [Docs > Test runner > DOM](https://bun.sh/docs/test/dom) for complete documentation on writing browser tests with Bun.
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Migrate from Jest to Bun's test runner
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
In many cases, Bun's test runner can run Jest test suites with no code changes. Just run `bun test` instead of `npx jest`, `yarn test`, etc.
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
- $ npx jest
|
|
9
|
-
- $ yarn test
|
|
10
|
-
+ $ bun test
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
There's often no need for code changes.
|
|
16
|
-
|
|
17
|
-
- Bun internally re-writes imports from `@jest/globals` to use the `bun:test` equivalents.
|
|
18
|
-
- If you're relying on Jest to inject `test`, `expect`, etc. as globals, Bun does that too.
|
|
19
|
-
|
|
20
|
-
But if you'd rather switch to the `bun:test` imports, you can do that too.
|
|
21
|
-
|
|
22
|
-
```ts-diff
|
|
23
|
-
- import {test, expect} from "@jest/globals";
|
|
24
|
-
+ import {test, expect} from "bun:test";
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
Since Bun v1.2.19, you can enable **TypeScript support** for global test functions with a single triple-slash directive. This makes migrating from Jest even easier since you only need to add the directive once in your entire project:
|
|
30
|
-
|
|
31
|
-
Add this directive to _just one file_ in your project, such as:
|
|
32
|
-
|
|
33
|
-
- A `global.d.ts` file in your project root
|
|
34
|
-
- Your test `preload.ts` setup file (if using `preload` in bunfig.toml)
|
|
35
|
-
- Any single `.ts` file that TypeScript includes in your compilation
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
/// <reference types="bun-types/test-globals" />
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
Once added, all test files in your project automatically get TypeScript support for Jest globals:
|
|
44
|
-
|
|
45
|
-
```ts#math.test.ts
|
|
46
|
-
describe("my test suite", () => {
|
|
47
|
-
test("should work", () => {
|
|
48
|
-
expect(1 + 1).toBe(2);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
beforeAll(() => {
|
|
52
|
-
// setup code
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
afterEach(() => {
|
|
56
|
-
// cleanup code
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
Bun implements the vast majority of Jest's matchers, but compatibility isn't 100% yet. Refer to the full compatibility table at [Docs > Test runner > Writing tests](https://bun.sh/docs/test/writing#matchers).
|
|
64
|
-
|
|
65
|
-
Some notable missing features:
|
|
66
|
-
|
|
67
|
-
- `expect().toHaveReturned()`
|
|
68
|
-
|
|
69
|
-
---
|
|
70
|
-
|
|
71
|
-
If you're using `testEnvironment: "jsdom"` to run your tests in a browser-like environment, you should follow the [DOM testing with Bun and happy-dom](/guides/test/happy-dom) guide to inject browser APIs into the global scope. This guide relies on [`happy-dom`](https://github.com/capricorn86/happy-dom), which is a leaner and faster alternative to [`jsdom`](https://github.com/jsdom/jsdom).
|
|
72
|
-
|
|
73
|
-
At the moment jsdom does not work in Bun due to its internal use of V8 APIs. Track support for it [here](https://github.com/oven-sh/bun/issues/3554).
|
|
74
|
-
|
|
75
|
-
```toml#bunfig.toml
|
|
76
|
-
[test]
|
|
77
|
-
preload = ["./happy-dom.ts"]
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
Replace `bail` in your Jest config with the `--bail` CLI flag.
|
|
83
|
-
|
|
84
|
-
<!-- ```ts-diff
|
|
85
|
-
- import type {Config} from 'jest';
|
|
86
|
-
-
|
|
87
|
-
- const config: Config = {
|
|
88
|
-
- bail: 3
|
|
89
|
-
- };
|
|
90
|
-
``` -->
|
|
91
|
-
|
|
92
|
-
```sh
|
|
93
|
-
$ bun test --bail=3
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
---
|
|
97
|
-
|
|
98
|
-
Replace `collectCoverage` with the `--coverage` CLI flag.
|
|
99
|
-
|
|
100
|
-
<!-- ```ts-diff
|
|
101
|
-
- import type {Config} from 'jest';
|
|
102
|
-
-
|
|
103
|
-
- const config: Config = {
|
|
104
|
-
- collectCoverageFrom: [
|
|
105
|
-
- '**/*.{js,jsx}',
|
|
106
|
-
- '!**/node_modules/**',
|
|
107
|
-
- '!**/vendor/**',
|
|
108
|
-
- ],
|
|
109
|
-
- };
|
|
110
|
-
``` -->
|
|
111
|
-
|
|
112
|
-
```sh
|
|
113
|
-
$ bun test --coverage
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
Replace `testTimeout` with the `--test-timeout` CLI flag.
|
|
119
|
-
|
|
120
|
-
```sh
|
|
121
|
-
$ bun test --timeout 10000
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
---
|
|
125
|
-
|
|
126
|
-
Many other flags become irrelevant or obsolete when using `bun test`.
|
|
127
|
-
|
|
128
|
-
- `transform` — Bun supports TypeScript & JSX. Other file types can be configured with [Plugins](https://bun.sh/docs/runtime/plugins).
|
|
129
|
-
- `extensionsToTreatAsEsm`
|
|
130
|
-
- `haste` — Bun uses it's own internal source maps
|
|
131
|
-
- `watchman`, `watchPlugins`, `watchPathIgnorePatterns` — use `--watch` to run tests in watch mode
|
|
132
|
-
- `verbose` — set `logLevel: "debug"` in [`bunfig.toml`](https://bun.sh/docs/runtime/bunfig#loglevel)
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
Settings that aren't mentioned here are not supported or have no equivalent. Please [file a feature request](https://github.com/oven-sh/bun) if something important is missing.
|
|
137
|
-
|
|
138
|
-
---
|
|
139
|
-
|
|
140
|
-
See also:
|
|
141
|
-
|
|
142
|
-
- [Mark a test as a todo](/guides/test/todo-tests)
|
|
143
|
-
- [Docs > Test runner > Writing tests](https://bun.sh/docs/test/writing)
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Set the system time in Bun's test runner
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun's test runner supports setting the system time programmatically with the `setSystemTime` function.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { test, expect, setSystemTime } from "bun:test";
|
|
9
|
-
|
|
10
|
-
test("party like it's 1999", () => {
|
|
11
|
-
const date = new Date("1999-01-01T00:00:00.000Z");
|
|
12
|
-
setSystemTime(date); // it's now January 1, 1999
|
|
13
|
-
|
|
14
|
-
const now = new Date();
|
|
15
|
-
expect(now.getFullYear()).toBe(1999);
|
|
16
|
-
expect(now.getMonth()).toBe(0);
|
|
17
|
-
expect(now.getDate()).toBe(1);
|
|
18
|
-
});
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
The `setSystemTime` function is commonly used on conjunction with [Lifecycle Hooks](https://bun.sh/docs/test/lifecycle) to configure a testing environment with a deterministic "fake clock".
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import { test, expect, beforeAll, setSystemTime } from "bun:test";
|
|
27
|
-
|
|
28
|
-
beforeAll(() => {
|
|
29
|
-
const date = new Date("1999-01-01T00:00:00.000Z");
|
|
30
|
-
setSystemTime(date); // it's now January 1, 1999
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// tests...
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
To reset the system clock to the actual time, call `setSystemTime` with no arguments.
|
|
39
|
-
|
|
40
|
-
```ts
|
|
41
|
-
import { test, expect, beforeAll, setSystemTime } from "bun:test";
|
|
42
|
-
|
|
43
|
-
setSystemTime(); // reset to actual time
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
See [Docs > Test Runner > Date and time](https://bun.sh/docs/test/time) for complete documentation on mocking with the Bun test runner.
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Mock functions in `bun test`
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Create mocks with the `mock` function from `bun:test`.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { test, expect, mock } from "bun:test";
|
|
9
|
-
|
|
10
|
-
const random = mock(() => Math.random());
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
The mock function can accept arguments.
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { test, expect, mock } from "bun:test";
|
|
19
|
-
|
|
20
|
-
const random = mock((multiplier: number) => multiplier * Math.random());
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
The result of `mock()` is a new function that's been decorated with some additional properties.
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
import { mock } from "bun:test";
|
|
29
|
-
|
|
30
|
-
const random = mock((multiplier: number) => multiplier * Math.random());
|
|
31
|
-
|
|
32
|
-
random(2);
|
|
33
|
-
random(10);
|
|
34
|
-
|
|
35
|
-
random.mock.calls;
|
|
36
|
-
// [[ 2 ], [ 10 ]]
|
|
37
|
-
|
|
38
|
-
random.mock.results;
|
|
39
|
-
// [
|
|
40
|
-
// { type: "return", value: 0.6533907460954099 },
|
|
41
|
-
// { type: "return", value: 0.6452713933037312 }
|
|
42
|
-
// ]
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
These extra properties make it possible to write `expect` assertions about usage of the mock function, including how many times it was called, the arguments, and the return values.
|
|
48
|
-
|
|
49
|
-
```ts
|
|
50
|
-
import { test, expect, mock } from "bun:test";
|
|
51
|
-
|
|
52
|
-
const random = mock((multiplier: number) => multiplier * Math.random());
|
|
53
|
-
|
|
54
|
-
test("random", async () => {
|
|
55
|
-
const a = random(1);
|
|
56
|
-
const b = random(2);
|
|
57
|
-
const c = random(3);
|
|
58
|
-
|
|
59
|
-
expect(random).toHaveBeenCalled();
|
|
60
|
-
expect(random).toHaveBeenCalledTimes(3);
|
|
61
|
-
expect(random.mock.args).toEqual([[1], [2], [3]]);
|
|
62
|
-
expect(random.mock.results[0]).toEqual({ type: "return", value: a });
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
See [Docs > Test Runner > Mocks](https://bun.sh/docs/test/mocks) for complete documentation on mocking with the Bun test runner.
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Re-run tests multiple times with the Bun test runner
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Use the `--rerun-each` flag to re-run every test multiple times with the Bun test runner. This is useful for finding flaky or non-deterministic tests.
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
# re-run each test 10 times
|
|
9
|
-
$ bun test --rerun-each 10
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
See [Docs > Test runner](https://bun.sh/docs/cli/test) for complete documentation of `bun test`.
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Run your tests with the Bun test runner
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun has a built-in [test runner](https://bun.sh/docs/cli/test) with a Jest-like `expect` API.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
To use it, run the `bun test` command from your project directory. The test runner will recursively search for all files in the directory that match the following patterns and execute the tests they contain.
|
|
10
|
-
|
|
11
|
-
```txt
|
|
12
|
-
*.test.{js|jsx|ts|tsx}
|
|
13
|
-
*_test.{js|jsx|ts|tsx}
|
|
14
|
-
*.spec.{js|jsx|ts|tsx}
|
|
15
|
-
*_spec.{js|jsx|ts|tsx}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
Here's what the output of a typical test run looks like. In this case, there are three tests files (`test.test.js`, `test2.test.js`, and `test3.test.js`) containing two tests each (`add` and `multiply`).
|
|
21
|
-
|
|
22
|
-
```sh
|
|
23
|
-
$ bun test
|
|
24
|
-
bun test v1.3.2-canary.20251104T140728 (9c68abdb)
|
|
25
|
-
|
|
26
|
-
test.test.js:
|
|
27
|
-
✓ add [0.87ms]
|
|
28
|
-
✓ multiply [0.02ms]
|
|
29
|
-
|
|
30
|
-
test2.test.js:
|
|
31
|
-
✓ add [0.72ms]
|
|
32
|
-
✓ multiply [0.01ms]
|
|
33
|
-
|
|
34
|
-
test3.test.js:
|
|
35
|
-
✓ add [0.54ms]
|
|
36
|
-
✓ multiply [0.01ms]
|
|
37
|
-
|
|
38
|
-
6 pass
|
|
39
|
-
0 fail
|
|
40
|
-
6 expect() calls
|
|
41
|
-
Ran 6 tests across 3 files. [9.00ms]
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
To only run certain test files, pass a positional argument to `bun test`. The runner will only execute files that contain that argument in their path.
|
|
47
|
-
|
|
48
|
-
```sh
|
|
49
|
-
$ bun test test3
|
|
50
|
-
bun test v1.3.2-canary.20251104T140728 (9c68abdb)
|
|
51
|
-
|
|
52
|
-
test3.test.js:
|
|
53
|
-
✓ add [1.40ms]
|
|
54
|
-
✓ multiply [0.03ms]
|
|
55
|
-
|
|
56
|
-
2 pass
|
|
57
|
-
0 fail
|
|
58
|
-
2 expect() calls
|
|
59
|
-
Ran 2 tests across 1 files. [15.00ms]
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
---
|
|
63
|
-
|
|
64
|
-
All tests have a name, defined using the first parameter to the `test` function. Tests can also be grouped into suites with `describe`.
|
|
65
|
-
|
|
66
|
-
```ts
|
|
67
|
-
import { test, expect, describe } from "bun:test";
|
|
68
|
-
|
|
69
|
-
describe("math", () => {
|
|
70
|
-
test("add", () => {
|
|
71
|
-
expect(2 + 2).toEqual(4);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("multiply", () => {
|
|
75
|
-
expect(2 * 2).toEqual(4);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
To filter which tests are executed by name, use the `-t`/`--test-name-pattern` flag.
|
|
83
|
-
|
|
84
|
-
Adding `-t add` will only run tests with "add" in the name. This works with test names defined with `test` or test suite names defined with `describe`.
|
|
85
|
-
|
|
86
|
-
```sh
|
|
87
|
-
$ bun test -t add
|
|
88
|
-
bun test v1.3.2-canary.20251104T140728 (9c68abdb)
|
|
89
|
-
|
|
90
|
-
test.test.js:
|
|
91
|
-
✓ add [1.79ms]
|
|
92
|
-
» multiply
|
|
93
|
-
|
|
94
|
-
test2.test.js:
|
|
95
|
-
✓ add [2.30ms]
|
|
96
|
-
» multiply
|
|
97
|
-
|
|
98
|
-
test3.test.js:
|
|
99
|
-
✓ add [0.32ms]
|
|
100
|
-
» multiply
|
|
101
|
-
|
|
102
|
-
3 pass
|
|
103
|
-
3 skip
|
|
104
|
-
0 fail
|
|
105
|
-
3 expect() calls
|
|
106
|
-
Ran 6 tests across 3 files. [59.00ms]
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
See [Docs > Test Runner](https://bun.sh/docs/cli/test) for complete documentation on the test runner.
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Skip tests with the Bun test runner
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
To skip a test with the Bun test runner, use the `test.skip` function.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { test } from "bun:test";
|
|
9
|
-
|
|
10
|
-
test.skip("unimplemented feature", () => {
|
|
11
|
-
expect(Bun.isAwesome()).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
Running `bun test` will not execute this test. It will be marked as skipped in the terminal output.
|
|
18
|
-
|
|
19
|
-
```sh
|
|
20
|
-
$ bun test
|
|
21
|
-
|
|
22
|
-
test.test.ts:
|
|
23
|
-
✓ add [0.03ms]
|
|
24
|
-
✓ multiply [0.02ms]
|
|
25
|
-
» unimplemented feature
|
|
26
|
-
|
|
27
|
-
2 pass
|
|
28
|
-
1 skip
|
|
29
|
-
0 fail
|
|
30
|
-
2 expect() calls
|
|
31
|
-
Ran 3 tests across 1 files. [74.00ms]
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
See also:
|
|
37
|
-
|
|
38
|
-
- [Mark a test as a todo](/guides/test/todo-tests)
|
|
39
|
-
- [Docs > Test runner > Writing tests](https://bun.sh/docs/test/writing)
|