bun-types 1.3.2-canary.20251106T140813 → 1.3.2-canary.20251108T140624
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 +102 -6
- package/docs/bundler/bytecode.mdx +465 -0
- package/docs/bundler/css.mdx +1024 -0
- package/docs/bundler/esbuild.mdx +253 -0
- package/docs/bundler/executables.mdx +535 -0
- package/docs/bundler/fullstack.mdx +1064 -0
- package/docs/bundler/hot-reloading.mdx +229 -0
- package/docs/bundler/html-static.mdx +386 -0
- package/docs/bundler/index.mdx +1499 -0
- package/docs/bundler/loaders.mdx +356 -0
- package/docs/bundler/macros.mdx +328 -0
- package/docs/bundler/minifier.mdx +1306 -0
- package/docs/bundler/plugins.mdx +411 -0
- package/docs/feedback.mdx +85 -0
- package/docs/guides/binary/arraybuffer-to-array.mdx +29 -0
- package/docs/guides/binary/arraybuffer-to-blob.mdx +26 -0
- package/docs/guides/binary/arraybuffer-to-buffer.mdx +27 -0
- package/docs/guides/binary/arraybuffer-to-string.mdx +17 -0
- package/docs/guides/binary/arraybuffer-to-typedarray.mdx +41 -0
- package/docs/guides/binary/blob-to-arraybuffer.mdx +16 -0
- package/docs/guides/binary/blob-to-dataview.mdx +16 -0
- package/docs/guides/binary/blob-to-stream.mdx +16 -0
- package/docs/guides/binary/blob-to-string.mdx +17 -0
- package/docs/guides/binary/blob-to-typedarray.mdx +16 -0
- package/docs/guides/binary/buffer-to-arraybuffer.mdx +16 -0
- package/docs/guides/binary/buffer-to-blob.mdx +16 -0
- package/docs/guides/binary/buffer-to-readablestream.mdx +43 -0
- package/docs/guides/binary/buffer-to-string.mdx +27 -0
- package/docs/guides/binary/buffer-to-typedarray.mdx +16 -0
- package/docs/guides/binary/dataview-to-string.mdx +17 -0
- package/docs/guides/binary/typedarray-to-arraybuffer.mdx +27 -0
- package/docs/guides/binary/typedarray-to-blob.mdx +18 -0
- package/docs/guides/binary/typedarray-to-buffer.mdx +16 -0
- package/docs/guides/binary/typedarray-to-dataview.mdx +16 -0
- package/docs/guides/binary/typedarray-to-readablestream.mdx +43 -0
- package/docs/guides/binary/typedarray-to-string.mdx +18 -0
- package/docs/guides/deployment/aws-lambda.mdx +204 -0
- package/docs/guides/deployment/digital-ocean.mdx +161 -0
- package/docs/guides/deployment/google-cloud-run.mdx +197 -0
- package/docs/guides/deployment/railway.mdx +145 -0
- package/docs/guides/deployment/render.mdx +82 -0
- package/docs/guides/deployment/vercel.mdx +99 -0
- package/docs/guides/ecosystem/astro.mdx +82 -0
- package/docs/guides/ecosystem/discordjs.mdx +80 -0
- package/docs/guides/ecosystem/docker.mdx +151 -0
- package/docs/guides/ecosystem/drizzle.mdx +195 -0
- package/docs/guides/ecosystem/edgedb.mdx +257 -0
- package/docs/guides/ecosystem/elysia.mdx +31 -0
- package/docs/guides/ecosystem/express.mdx +43 -0
- package/docs/guides/ecosystem/hono.mdx +47 -0
- package/docs/guides/ecosystem/mongoose.mdx +92 -0
- package/docs/guides/ecosystem/neon-drizzle.mdx +234 -0
- package/docs/guides/ecosystem/neon-serverless-postgres.mdx +60 -0
- package/docs/guides/ecosystem/nextjs.mdx +57 -0
- package/docs/guides/ecosystem/nuxt.mdx +90 -0
- package/docs/guides/ecosystem/pm2.mdx +55 -0
- package/docs/guides/ecosystem/prisma-postgres.mdx +169 -0
- package/docs/guides/ecosystem/prisma.mdx +164 -0
- package/docs/guides/ecosystem/qwik.mdx +114 -0
- package/docs/guides/ecosystem/react.mdx +52 -0
- package/docs/guides/ecosystem/remix.mdx +97 -0
- package/docs/guides/ecosystem/sentry.mdx +54 -0
- package/docs/guides/ecosystem/solidstart.mdx +66 -0
- package/docs/guides/ecosystem/ssr-react.mdx +49 -0
- package/docs/guides/ecosystem/stric.mdx +54 -0
- package/docs/guides/ecosystem/sveltekit.mdx +138 -0
- package/docs/guides/ecosystem/systemd.mdx +114 -0
- package/docs/guides/ecosystem/upstash.mdx +87 -0
- package/docs/guides/ecosystem/vite.mdx +77 -0
- package/docs/guides/html-rewriter/extract-links.mdx +72 -0
- package/docs/guides/html-rewriter/extract-social-meta.mdx +97 -0
- package/docs/guides/http/cluster.mdx +69 -0
- package/docs/guides/http/fetch-unix.mdx +35 -0
- package/docs/guides/http/fetch.mdx +26 -0
- package/docs/guides/http/file-uploads.mdx +97 -0
- package/docs/guides/http/hot.mdx +28 -0
- package/docs/guides/http/proxy.mdx +26 -0
- package/docs/guides/http/server.mdx +48 -0
- package/docs/guides/http/simple.mdx +20 -0
- package/docs/guides/http/stream-file.mdx +50 -0
- package/docs/guides/http/stream-iterator.mdx +49 -0
- package/docs/guides/http/stream-node-streams-in-bun.mdx +22 -0
- package/docs/guides/http/tls.mdx +32 -0
- package/docs/guides/index.mdx +10 -0
- package/docs/guides/install/add-dev.mdx +28 -0
- package/docs/guides/install/add-git.mdx +38 -0
- package/docs/guides/install/add-optional.mdx +27 -0
- package/docs/guides/install/add-peer.mdx +45 -0
- package/docs/guides/install/add-tarball.mdx +35 -0
- package/docs/guides/install/add.mdx +44 -0
- package/docs/guides/install/azure-artifacts.mdx +76 -0
- package/docs/guides/install/cicd.mdx +43 -0
- package/docs/guides/install/custom-registry.mdx +32 -0
- package/docs/guides/install/from-npm-install-to-bun-install.mdx +230 -0
- package/docs/guides/install/git-diff-bun-lockfile.mdx +47 -0
- package/docs/guides/install/jfrog-artifactory.mdx +28 -0
- package/docs/guides/install/npm-alias.mdx +25 -0
- package/docs/guides/install/registry-scope.mdx +40 -0
- package/docs/guides/install/trusted.mdx +50 -0
- package/docs/guides/install/workspaces.mdx +70 -0
- package/docs/guides/install/yarnlock.mdx +50 -0
- package/docs/guides/process/argv.mdx +66 -0
- package/docs/guides/process/ctrl-c.mdx +18 -0
- package/docs/guides/process/ipc.mdx +69 -0
- package/docs/guides/process/nanoseconds.mdx +15 -0
- package/docs/guides/process/os-signals.mdx +41 -0
- package/docs/guides/process/spawn-stderr.mdx +34 -0
- package/docs/guides/process/spawn-stdout.mdx +28 -0
- package/docs/guides/process/spawn.mdx +43 -0
- package/docs/guides/process/stdin.mdx +62 -0
- package/docs/guides/read-file/arraybuffer.mdx +30 -0
- package/docs/guides/read-file/buffer.mdx +21 -0
- package/docs/guides/read-file/exists.mdx +18 -0
- package/docs/guides/read-file/json.mdx +19 -0
- package/docs/guides/read-file/mime.mdx +22 -0
- package/docs/guides/read-file/stream.mdx +28 -0
- package/docs/guides/read-file/string.mdx +24 -0
- package/docs/guides/read-file/uint8array.mdx +23 -0
- package/docs/guides/read-file/watch.mdx +66 -0
- package/docs/guides/runtime/build-time-constants.mdx +295 -0
- package/docs/guides/runtime/cicd.mdx +45 -0
- package/docs/guides/runtime/codesign-macos-executable.mdx +61 -0
- package/docs/guides/runtime/define-constant.mdx +149 -0
- package/docs/guides/runtime/delete-directory.mdx +39 -0
- package/docs/guides/runtime/delete-file.mdx +21 -0
- package/docs/guides/runtime/heap-snapshot.mdx +28 -0
- package/docs/guides/runtime/import-html.mdx +17 -0
- package/docs/guides/runtime/import-json.mdx +46 -0
- package/docs/guides/runtime/import-toml.mdx +32 -0
- package/docs/guides/runtime/import-yaml.mdx +104 -0
- package/docs/guides/runtime/read-env.mdx +37 -0
- package/docs/guides/runtime/set-env.mdx +51 -0
- package/docs/guides/runtime/shell.mdx +42 -0
- package/docs/guides/runtime/timezone.mdx +38 -0
- package/docs/guides/runtime/tsconfig-paths.mdx +31 -0
- package/docs/guides/runtime/typescript.mdx +51 -0
- package/docs/guides/runtime/vscode-debugger.mdx +48 -0
- package/docs/guides/runtime/web-debugger.mdx +103 -0
- package/docs/guides/streams/node-readable-to-arraybuffer.mdx +13 -0
- package/docs/guides/streams/node-readable-to-blob.mdx +13 -0
- package/docs/guides/streams/node-readable-to-json.mdx +14 -0
- package/docs/guides/streams/node-readable-to-string.mdx +14 -0
- package/docs/guides/streams/node-readable-to-uint8array.mdx +13 -0
- package/docs/guides/streams/to-array.mdx +16 -0
- package/docs/guides/streams/to-arraybuffer.mdx +16 -0
- package/docs/guides/streams/to-blob.mdx +16 -0
- package/docs/guides/streams/to-buffer.mdx +17 -0
- package/docs/guides/streams/to-json.mdx +16 -0
- package/docs/guides/streams/to-string.mdx +16 -0
- package/docs/guides/streams/to-typedarray.mdx +24 -0
- package/docs/guides/test/bail.mdx +24 -0
- package/docs/guides/test/coverage-threshold.mdx +67 -0
- package/docs/guides/test/coverage.mdx +49 -0
- package/docs/guides/test/happy-dom.mdx +73 -0
- package/docs/guides/test/migrate-from-jest.mdx +125 -0
- package/docs/guides/test/mock-clock.mdx +50 -0
- package/docs/guides/test/mock-functions.mdx +70 -0
- package/docs/guides/test/rerun-each.mdx +16 -0
- package/docs/guides/test/run-tests.mdx +116 -0
- package/docs/guides/test/skip-tests.mdx +43 -0
- package/docs/guides/test/snapshot.mdx +102 -0
- package/docs/guides/test/spy-on.mdx +49 -0
- package/docs/guides/test/svelte-test.mdx +113 -0
- package/docs/guides/test/testing-library.mdx +93 -0
- package/docs/guides/test/timeout.mdx +17 -0
- package/docs/guides/test/todo-tests.mdx +74 -0
- package/docs/guides/test/update-snapshots.mdx +49 -0
- package/docs/guides/test/watch-mode.mdx +24 -0
- package/docs/guides/util/base64.mdx +17 -0
- package/docs/guides/util/deep-equals.mdx +41 -0
- package/docs/guides/util/deflate.mdx +20 -0
- package/docs/guides/util/detect-bun.mdx +25 -0
- package/docs/guides/util/entrypoint.mdx +19 -0
- package/docs/guides/util/escape-html.mdx +24 -0
- package/docs/guides/util/file-url-to-path.mdx +16 -0
- package/docs/guides/util/gzip.mdx +20 -0
- package/docs/guides/util/hash-a-password.mdx +56 -0
- package/docs/guides/util/import-meta-dir.mdx +15 -0
- package/docs/guides/util/import-meta-file.mdx +15 -0
- package/docs/guides/util/import-meta-path.mdx +15 -0
- package/docs/guides/util/javascript-uuid.mdx +25 -0
- package/docs/guides/util/main.mdx +43 -0
- package/docs/guides/util/path-to-file-url.mdx +16 -0
- package/docs/guides/util/sleep.mdx +24 -0
- package/docs/guides/util/version.mdx +23 -0
- package/docs/guides/util/which-path-to-executable-bin.mdx +17 -0
- package/docs/guides/websocket/compression.mdx +33 -0
- package/docs/guides/websocket/context.mdx +74 -0
- package/docs/guides/websocket/pubsub.mdx +40 -0
- package/docs/guides/websocket/simple.mdx +35 -0
- package/docs/guides/write-file/append.mdx +54 -0
- package/docs/guides/write-file/basic.mdx +46 -0
- package/docs/guides/write-file/blob.mdx +30 -0
- package/docs/guides/write-file/cat.mdx +19 -0
- package/docs/guides/write-file/file-cp.mdx +18 -0
- package/docs/guides/write-file/filesink.mdx +54 -0
- package/docs/guides/write-file/response.mdx +19 -0
- package/docs/guides/write-file/stdout.mdx +23 -0
- package/docs/guides/write-file/stream.mdx +19 -0
- package/docs/guides/write-file/unlink.mdx +18 -0
- package/docs/index.mdx +133 -0
- package/docs/installation.mdx +365 -0
- package/docs/pm/bunx.mdx +83 -0
- package/docs/pm/catalogs.mdx +292 -0
- package/docs/pm/cli/add.mdx +179 -0
- package/docs/pm/cli/audit.mdx +60 -0
- package/docs/pm/cli/install.mdx +471 -0
- package/docs/pm/cli/link.mdx +48 -0
- package/docs/pm/cli/outdated.mdx +197 -0
- package/docs/pm/cli/patch.mdx +69 -0
- package/docs/pm/cli/pm.mdx +319 -0
- package/docs/pm/cli/publish.mdx +123 -0
- package/docs/pm/cli/remove.mdx +16 -0
- package/docs/pm/cli/update.mdx +140 -0
- package/docs/pm/cli/why.mdx +84 -0
- package/docs/pm/filter.mdx +102 -0
- package/docs/pm/global-cache.mdx +72 -0
- package/docs/pm/isolated-installs.mdx +205 -0
- package/docs/pm/lifecycle.mdx +57 -0
- package/docs/pm/lockfile.mdx +64 -0
- package/docs/pm/npmrc.mdx +111 -0
- package/docs/pm/overrides.mdx +83 -0
- package/docs/pm/scopes-registries.mdx +35 -0
- package/docs/pm/security-scanner-api.mdx +95 -0
- package/docs/pm/workspaces.mdx +109 -0
- package/docs/project/benchmarking.mdx +218 -0
- package/docs/project/bindgen.mdx +223 -0
- package/docs/project/building-windows.mdx +133 -0
- package/docs/project/contributing.mdx +343 -0
- package/docs/project/feedback.mdx +20 -0
- package/docs/project/license.mdx +78 -0
- package/docs/project/roadmap.mdx +8 -0
- package/docs/quickstart.mdx +240 -0
- package/docs/runtime/auto-install.mdx +97 -0
- package/docs/runtime/binary-data.mdx +846 -0
- package/docs/runtime/bun-apis.mdx +59 -0
- package/docs/runtime/bunfig.mdx +642 -0
- package/docs/runtime/c-compiler.mdx +204 -0
- package/docs/runtime/child-process.mdx +532 -0
- package/docs/runtime/color.mdx +267 -0
- package/docs/runtime/console.mdx +67 -0
- package/docs/runtime/cookies.mdx +454 -0
- package/docs/runtime/debugger.mdx +335 -0
- package/docs/runtime/environment-variables.mdx +214 -0
- package/docs/runtime/ffi.mdx +565 -0
- package/docs/runtime/file-io.mdx +306 -0
- package/docs/runtime/file-system-router.mdx +118 -0
- package/docs/runtime/file-types.mdx +354 -0
- package/docs/runtime/glob.mdx +181 -0
- package/docs/runtime/globals.mdx +72 -0
- package/docs/runtime/hashing.mdx +315 -0
- package/docs/runtime/html-rewriter.mdx +340 -0
- package/docs/runtime/http/cookies.mdx +79 -0
- package/docs/runtime/http/error-handling.mdx +40 -0
- package/docs/runtime/http/metrics.mdx +36 -0
- package/docs/runtime/http/routing.mdx +289 -0
- package/docs/runtime/http/server.mdx +647 -0
- package/docs/runtime/http/tls.mdx +101 -0
- package/docs/runtime/http/websockets.mdx +404 -0
- package/docs/runtime/index.mdx +223 -0
- package/docs/runtime/jsx.mdx +115 -0
- package/docs/runtime/module-resolution.mdx +342 -0
- package/docs/runtime/networking/dns.mdx +111 -0
- package/docs/runtime/networking/fetch.mdx +468 -0
- package/docs/runtime/networking/tcp.mdx +239 -0
- package/docs/runtime/networking/udp.mdx +129 -0
- package/docs/runtime/node-api.mdx +19 -0
- package/docs/runtime/nodejs-compat.mdx +468 -0
- package/docs/runtime/plugins.mdx +405 -0
- package/docs/runtime/redis.mdx +582 -0
- package/docs/runtime/s3.mdx +863 -0
- package/docs/runtime/secrets.mdx +336 -0
- package/docs/runtime/semver.mdx +57 -0
- package/docs/runtime/shell.mdx +637 -0
- package/docs/runtime/sql.mdx +1404 -0
- package/docs/runtime/sqlite.mdx +699 -0
- package/docs/runtime/streams.mdx +232 -0
- package/docs/runtime/templating/create.mdx +269 -0
- package/docs/runtime/templating/init.mdx +58 -0
- package/docs/runtime/transpiler.mdx +288 -0
- package/docs/runtime/typescript.mdx +58 -0
- package/docs/runtime/utils.mdx +922 -0
- package/docs/runtime/watch-mode.mdx +161 -0
- package/docs/runtime/web-apis.mdx +29 -0
- package/docs/runtime/workers.mdx +328 -0
- package/docs/runtime/yaml.mdx +469 -0
- package/docs/snippets/cli/add.mdx +166 -0
- package/docs/snippets/cli/build.mdx +196 -0
- package/docs/snippets/cli/feedback.mdx +17 -0
- package/docs/snippets/cli/init.mdx +84 -0
- package/docs/snippets/cli/install.mdx +173 -0
- package/docs/snippets/cli/link.mdx +163 -0
- package/docs/snippets/cli/outdated.mdx +140 -0
- package/docs/snippets/cli/patch.mdx +171 -0
- package/docs/snippets/cli/publish.mdx +198 -0
- package/docs/snippets/cli/remove.mdx +146 -0
- package/docs/snippets/cli/run.mdx +293 -0
- package/docs/snippets/cli/test.mdx +100 -0
- package/docs/snippets/cli/update.mdx +144 -0
- package/docs/snippets/product-card.mdx +32 -0
- package/docs/snippets/product-tiles.mdx +94 -0
- package/docs/test/code-coverage.mdx +409 -0
- package/docs/test/configuration.mdx +467 -0
- package/docs/test/dates-times.mdx +129 -0
- package/docs/test/discovery.mdx +90 -0
- package/docs/test/dom.mdx +226 -0
- package/docs/test/index.mdx +380 -0
- package/docs/test/lifecycle.mdx +348 -0
- package/docs/test/mocks.mdx +637 -0
- package/docs/test/reporters.mdx +117 -0
- package/docs/test/runtime-behavior.mdx +342 -0
- package/docs/test/snapshots.mdx +434 -0
- package/docs/test/writing-tests.mdx +635 -0
- package/docs/typescript.mdx +54 -0
- package/package.json +8 -6
- package/test.d.ts +2 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Convert a ReadableStream to an ArrayBuffer
|
|
3
|
+
sidebarTitle: Stream to ArrayBuffer
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const stream = new ReadableStream();
|
|
11
|
+
const buf = await Bun.readableStreamToArrayBuffer(stream);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Convert a ReadableStream to a Blob
|
|
3
|
+
sidebarTitle: Stream to Blob
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const stream = new ReadableStream();
|
|
11
|
+
const blob = await Bun.readableStreamToBlob(stream);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Convert a ReadableStream to a Buffer
|
|
3
|
+
sidebarTitle: Stream to Buffer
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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 [`Buffer`](https://nodejs.org/api/buffer.html) that points to it.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const stream = new ReadableStream();
|
|
11
|
+
const arrBuf = await Bun.readableStreamToArrayBuffer(stream);
|
|
12
|
+
const nodeBuf = Buffer.from(arrBuf);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Convert a ReadableStream to JSON
|
|
3
|
+
sidebarTitle: Stream to JSON
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const stream = new ReadableStream();
|
|
11
|
+
const json = await stream.json();
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Convert a ReadableStream to a string
|
|
3
|
+
sidebarTitle: Stream to string
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const stream = new ReadableStream();
|
|
11
|
+
const str = await Bun.readableStreamToText(stream);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Convert a ReadableStream to a Uint8Array
|
|
3
|
+
sidebarTitle: Stream to Uint8Array
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const stream = new ReadableStream();
|
|
11
|
+
const buf = await Bun.readableStreamToArrayBuffer(stream);
|
|
12
|
+
const uint8 = new Uint8Array(buf);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Additionally, there is a convenience method to convert to `Uint8Array` directly.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
const stream = new ReadableStream();
|
|
19
|
+
const uint8 = await Bun.readableStreamToBytes(stream);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Bail early with the Bun test runner
|
|
3
|
+
sidebarTitle: Bail early
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
```sh terminal icon="terminal"
|
|
10
|
+
bun test --bail
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
To bail after a certain threshold of failures, optionally specify a number after the flag.
|
|
16
|
+
|
|
17
|
+
```sh terminal icon="terminal"
|
|
18
|
+
# bail after 10 failures
|
|
19
|
+
bun test --bail=10
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
See [Docs > Test runner](https://bun.sh/docs/cli/test) for complete documentation of `bun test`.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Set a code coverage threshold with the Bun test runner
|
|
3
|
+
sidebarTitle: Coverage threshold
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Bun's test runner supports built-in code coverage reporting via the `--coverage` flag.
|
|
8
|
+
|
|
9
|
+
```sh terminal icon="terminal"
|
|
10
|
+
bun test --coverage
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```txt
|
|
14
|
+
test.test.ts:
|
|
15
|
+
✓ math > add [0.71ms]
|
|
16
|
+
✓ math > multiply [0.03ms]
|
|
17
|
+
✓ random [0.13ms]
|
|
18
|
+
-------------|---------|---------|-------------------
|
|
19
|
+
File | % Funcs | % Lines | Uncovered Line #s
|
|
20
|
+
-------------|---------|---------|-------------------
|
|
21
|
+
All files | 66.67 | 77.78 |
|
|
22
|
+
math.ts | 50.00 | 66.67 |
|
|
23
|
+
random.ts | 50.00 | 66.67 |
|
|
24
|
+
-------------|---------|---------|-------------------
|
|
25
|
+
|
|
26
|
+
3 pass
|
|
27
|
+
0 fail
|
|
28
|
+
3 expect() calls
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
```toml bunfig.toml icon="settings"
|
|
36
|
+
[test]
|
|
37
|
+
# to require 90% line-level and function-level coverage
|
|
38
|
+
coverageThreshold = 0.9
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
If your test suite does not meet this threshold, `bun test` will exit with a non-zero exit code to signal a failure.
|
|
44
|
+
|
|
45
|
+
```sh terminal icon="terminal"
|
|
46
|
+
bun test --coverage
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```txt
|
|
50
|
+
<test output>
|
|
51
|
+
$ echo $?
|
|
52
|
+
1 # this is the exit code of the previous command
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
Different thresholds can be set for line-level and function-level coverage.
|
|
58
|
+
|
|
59
|
+
```toml bunfig.toml icon="settings"
|
|
60
|
+
[test]
|
|
61
|
+
# to set different thresholds for lines and functions
|
|
62
|
+
coverageThreshold = { lines = 0.5, functions = 0.7 }
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
See [Docs > Test runner > Coverage](https://bun.sh/docs/test/coverage) for complete documentation on code coverage reporting in Bun.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Generate code coverage reports with the Bun test runner
|
|
3
|
+
sidebarTitle: Coverage reports
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Pass the `--coverage` flag to `bun test` to enable this feature. This will print a coverage report after the test run.
|
|
12
|
+
|
|
13
|
+
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.
|
|
14
|
+
|
|
15
|
+
```sh terminal icon="terminal"
|
|
16
|
+
bun test --coverage
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```txt
|
|
20
|
+
|
|
21
|
+
test.test.ts:
|
|
22
|
+
✓ math > add [0.71ms]
|
|
23
|
+
✓ math > multiply [0.03ms]
|
|
24
|
+
✓ random [0.13ms]
|
|
25
|
+
-------------|---------|---------|-------------------
|
|
26
|
+
File | % Funcs | % Lines | Uncovered Line #s
|
|
27
|
+
-------------|---------|---------|-------------------
|
|
28
|
+
All files | 66.67 | 77.78 |
|
|
29
|
+
math.ts | 50.00 | 66.67 |
|
|
30
|
+
random.ts | 50.00 | 66.67 |
|
|
31
|
+
-------------|---------|---------|-------------------
|
|
32
|
+
|
|
33
|
+
3 pass
|
|
34
|
+
0 fail
|
|
35
|
+
3 expect() calls
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
To always enable coverage reporting by default, add the following line to your `bunfig.toml`:
|
|
41
|
+
|
|
42
|
+
```toml bunfig.toml icon="settings"
|
|
43
|
+
[test]
|
|
44
|
+
coverage = true # always enable coverage
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
Refer to [Docs > Test runner > Coverage](https://bun.sh/docs/test/coverage) for complete documentation on code coverage reporting in Bun.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Write browser DOM tests with Bun and happy-dom
|
|
3
|
+
sidebarTitle: DOM tests
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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`.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
To get started, install `happy-dom`.
|
|
12
|
+
|
|
13
|
+
```sh terminal icon="terminal"
|
|
14
|
+
bun add -d @happy-dom/global-registrator
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
This module exports a "registrator" that injects the mocked browser APIs to the global scope.
|
|
20
|
+
|
|
21
|
+
```ts happydom.ts icon="/icons/typescript.svg"
|
|
22
|
+
import { GlobalRegistrator } from "@happy-dom/global-registrator";
|
|
23
|
+
|
|
24
|
+
GlobalRegistrator.register();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
The `./happydom.ts` file should contain the registration code above.
|
|
32
|
+
|
|
33
|
+
```toml bunfig.toml icon="settings"
|
|
34
|
+
[test]
|
|
35
|
+
preload = "./happydom.ts"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
Now running `bun test` inside our project will automatically execute `happydom.ts` first. We can start writing tests that use browser APIs.
|
|
41
|
+
|
|
42
|
+
```ts dom.test.ts icon="/icons/typescript.svg"
|
|
43
|
+
import { test, expect } from "bun:test";
|
|
44
|
+
|
|
45
|
+
test("set button text", () => {
|
|
46
|
+
document.body.innerHTML = `<button>My button</button>`;
|
|
47
|
+
const button = document.querySelector("button");
|
|
48
|
+
expect(button?.innerText).toEqual("My button");
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
With Happy DOM properly configured, this test runs as expected.
|
|
55
|
+
|
|
56
|
+
```sh terminal icon="terminal"
|
|
57
|
+
bun test
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```txt
|
|
61
|
+
|
|
62
|
+
dom.test.ts:
|
|
63
|
+
✓ set button text [0.82ms]
|
|
64
|
+
|
|
65
|
+
1 pass
|
|
66
|
+
0 fail
|
|
67
|
+
1 expect() calls
|
|
68
|
+
Ran 1 tests across 1 files. 1 total [125.00ms]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
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.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Migrate from Jest to Bun's test runner
|
|
3
|
+
sidebarTitle: Migrate from Jest
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
```sh terminal icon="terminal"
|
|
10
|
+
npx jest # [!code --]
|
|
11
|
+
yarn test # [!code --]
|
|
12
|
+
bun test # [!code ++]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
There's often no need for code changes.
|
|
18
|
+
|
|
19
|
+
- Bun internally re-writes imports from `@jest/globals` to use the `bun:test` equivalents.
|
|
20
|
+
- If you're relying on Jest to inject `test`, `expect`, etc. as globals, Bun does that too.
|
|
21
|
+
|
|
22
|
+
But if you'd rather switch to the `bun:test` imports, you can do that too.
|
|
23
|
+
|
|
24
|
+
```ts title="test.ts" icon="/icons/typescript.svg"
|
|
25
|
+
import { test, expect } from "@jest/globals"; // [!code --]
|
|
26
|
+
import { test, expect } from "bun:test"; // [!code ++]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
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:
|
|
32
|
+
|
|
33
|
+
Add this directive to _just one file_ in your project, such as:
|
|
34
|
+
|
|
35
|
+
- A `global.d.ts` file in your project root
|
|
36
|
+
- Your test `preload.ts` setup file (if using `preload` in bunfig.toml)
|
|
37
|
+
- Any single `.ts` file that TypeScript includes in your compilation
|
|
38
|
+
|
|
39
|
+
```ts title="global.d.ts" icon="/icons/typescript.svg"
|
|
40
|
+
/// <reference types="bun-types/test-globals" />
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
Once added, all test files in your project automatically get TypeScript support for Jest globals:
|
|
46
|
+
|
|
47
|
+
```ts math.test.ts icon="/icons/typescript.svg"
|
|
48
|
+
describe("my test suite", () => {
|
|
49
|
+
test("should work", () => {
|
|
50
|
+
expect(1 + 1).toBe(2);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
beforeAll(() => {
|
|
54
|
+
// setup code
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
// cleanup code
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
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).
|
|
66
|
+
|
|
67
|
+
Some notable missing features:
|
|
68
|
+
|
|
69
|
+
- `expect().toHaveReturned()`
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
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).
|
|
74
|
+
|
|
75
|
+
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).
|
|
76
|
+
|
|
77
|
+
```toml bunfig.toml
|
|
78
|
+
[test]
|
|
79
|
+
preload = ["./happy-dom.ts"]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
Replace `bail` in your Jest config with the `--bail` CLI flag.
|
|
85
|
+
|
|
86
|
+
```sh terminal icon="terminal"
|
|
87
|
+
bun test --bail=3
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
Replace `collectCoverage` with the `--coverage` CLI flag.
|
|
93
|
+
|
|
94
|
+
```sh terminal icon="terminal"
|
|
95
|
+
bun test --coverage
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
Replace `testTimeout` with the `--test-timeout` CLI flag.
|
|
101
|
+
|
|
102
|
+
```sh terminal icon="terminal"
|
|
103
|
+
bun test --timeout 10000
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
Many other flags become irrelevant or obsolete when using `bun test`.
|
|
109
|
+
|
|
110
|
+
- `transform` — Bun supports TypeScript & JSX. Other file types can be configured with [Plugins](https://bun.sh/docs/runtime/plugins).
|
|
111
|
+
- `extensionsToTreatAsEsm`
|
|
112
|
+
- `haste` — Bun uses it's own internal source maps
|
|
113
|
+
- `watchman`, `watchPlugins`, `watchPathIgnorePatterns` — use `--watch` to run tests in watch mode
|
|
114
|
+
- `verbose` — set `logLevel: "debug"` in [`bunfig.toml`](https://bun.sh/docs/runtime/bunfig#loglevel)
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
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.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
See also:
|
|
123
|
+
|
|
124
|
+
- [Mark a test as a todo](/guides/test/todo-tests)
|
|
125
|
+
- [Docs > Test runner > Writing tests](https://bun.sh/docs/test/writing)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Set the system time in Bun's test runner
|
|
3
|
+
sidebarTitle: Mock system time
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Bun's test runner supports setting the system time programmatically with the `setSystemTime` function.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { test, expect, setSystemTime } from "bun:test";
|
|
11
|
+
|
|
12
|
+
test("party like it's 1999", () => {
|
|
13
|
+
const date = new Date("1999-01-01T00:00:00.000Z");
|
|
14
|
+
setSystemTime(date); // it's now January 1, 1999
|
|
15
|
+
|
|
16
|
+
const now = new Date();
|
|
17
|
+
expect(now.getFullYear()).toBe(1999);
|
|
18
|
+
expect(now.getMonth()).toBe(0);
|
|
19
|
+
expect(now.getDate()).toBe(1);
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
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".
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { test, expect, beforeAll, setSystemTime } from "bun:test";
|
|
29
|
+
|
|
30
|
+
beforeAll(() => {
|
|
31
|
+
const date = new Date("1999-01-01T00:00:00.000Z");
|
|
32
|
+
setSystemTime(date); // it's now January 1, 1999
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// tests...
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
To reset the system clock to the actual time, call `setSystemTime` with no arguments.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { test, expect, beforeAll, setSystemTime } from "bun:test";
|
|
44
|
+
|
|
45
|
+
setSystemTime(); // reset to actual time
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
See [Docs > Test Runner > Date and time](https://bun.sh/docs/test/time) for complete documentation on mocking with the Bun test runner.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Mock functions in `bun test`
|
|
3
|
+
sidebarTitle: Mock functions
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Create mocks with the `mock` function from `bun:test`.
|
|
8
|
+
|
|
9
|
+
```ts test.ts icon="/icons/typescript.svg"
|
|
10
|
+
import { test, expect, mock } from "bun:test";
|
|
11
|
+
|
|
12
|
+
const random = mock(() => Math.random());
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
The mock function can accept arguments.
|
|
18
|
+
|
|
19
|
+
```ts test.ts icon="/icons/typescript.svg"
|
|
20
|
+
import { test, expect, mock } from "bun:test";
|
|
21
|
+
|
|
22
|
+
const random = mock((multiplier: number) => multiplier * Math.random());
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
The result of `mock()` is a new function that's been decorated with some additional properties.
|
|
28
|
+
|
|
29
|
+
```ts test.ts icon="/icons/typescript.svg"
|
|
30
|
+
import { mock } from "bun:test";
|
|
31
|
+
|
|
32
|
+
const random = mock((multiplier: number) => multiplier * Math.random());
|
|
33
|
+
|
|
34
|
+
random(2);
|
|
35
|
+
random(10);
|
|
36
|
+
|
|
37
|
+
random.mock.calls;
|
|
38
|
+
// [[ 2 ], [ 10 ]]
|
|
39
|
+
|
|
40
|
+
random.mock.results;
|
|
41
|
+
// [
|
|
42
|
+
// { type: "return", value: 0.6533907460954099 },
|
|
43
|
+
// { type: "return", value: 0.6452713933037312 }
|
|
44
|
+
// ]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
```ts test.ts icon="/icons/typescript.svg"
|
|
52
|
+
import { test, expect, mock } from "bun:test";
|
|
53
|
+
|
|
54
|
+
const random = mock((multiplier: number) => multiplier * Math.random());
|
|
55
|
+
|
|
56
|
+
test("random", async () => {
|
|
57
|
+
const a = random(1);
|
|
58
|
+
const b = random(2);
|
|
59
|
+
const c = random(3);
|
|
60
|
+
|
|
61
|
+
expect(random).toHaveBeenCalled();
|
|
62
|
+
expect(random).toHaveBeenCalledTimes(3);
|
|
63
|
+
expect(random.mock.args).toEqual([[1], [2], [3]]);
|
|
64
|
+
expect(random.mock.results[0]).toEqual({ type: "return", value: a });
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
See [Docs > Test Runner > Mocks](https://bun.sh/docs/test/mocks) for complete documentation on mocking with the Bun test runner.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Re-run tests multiple times with the Bun test runner
|
|
3
|
+
sidebarTitle: Re-run tests
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
```sh terminal icon="terminal"
|
|
10
|
+
# re-run each test 10 times
|
|
11
|
+
bun test --rerun-each 10
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
See [Docs > Test runner](https://bun.sh/docs/cli/test) for complete documentation of `bun test`.
|