Skip to main content
Overview
Deployment
Runtime & Debugging
Utilities
Ecosystem & Frameworks
- Astro with Bun
- Discord.js with Bun
- Docker with Bun
- Drizzle with Bun
- Gel with Bun
- Elysia with Bun
- Express with Bun
- Hono with Bun
- Mongoose with Bun
- Neon Drizzle with Bun
- Neon Serverless Postgres with Bun
- Next.js with Bun
- Nuxt with Bun
- PM2 with Bun
- Prisma ORM with Bun
- Prisma Postgres with Bun
- Qwik with Bun
- React with Bun
- Remix with Bun
- TanStack Start with Bun
- Sentry with Bun
- SolidStart with Bun
- SSR React with Bun
- StricJS with Bun
- SvelteKit with Bun
- systemd with Bun
- Vite with Bun
- Upstash with Bun
HTTP & Networking
- HTTP Server with Bun
- Simple HTTP Server with Bun
- Fetch with Bun
- Hot reload an HTTP server
- Start a cluster of HTTP servers
- Configure TLS
- Proxy HTTP requests using fetch()
- Stream file response
- Upload files via HTTP using FormData
- Fetch with unix domain sockets
- Stream with iterators
- Server-Sent Events
- Stream with Node.js
Processes & System
Package Manager
- Add a dependency
- Add a dev dependency
- Add an optional dependency
- Add a peer dependency
- Add a Git dependency
- Add a tarball dependency
- Install with alias
- Workspaces with Bun
- Override the default npm registry
- Configure a scoped registry
- Azure Artifacts with Bun
- JFrog Artifactory with Bun
- Add a trusted dependency
- Generate a yarn-compatible lockfile
- Migrate from npm to bun
- Configure git to diff Bun's lockfile
- Install Bun in GitHub Actions
Test Runner
Runtime & Debugging
Module System
File System
- Read as string
- Read to Buffer
- Read to Uint8Array
- Read to ArrayBuffer
- Read JSON file
- Get MIME type
- Check file exists
- Watch directory
- Read as stream
- Write string to file
- Write Blob
- Write Response
- Append to file
- Incremental write
- Write stream
- Write to stdout
- Write file to stdout
- Copy file
- Delete file
- Delete files
- Delete directories
Utilities
HTML Processing
Binary Data
- ArrayBuffer to string
- ArrayBuffer to Buffer
- ArrayBuffer to Blob
- ArrayBuffer to Array
- ArrayBuffer to Uint8Array
- Buffer to string
- Buffer to ArrayBuffer
- Buffer to Blob
- Buffer to Uint8Array
- Buffer to ReadableStream
- Blob to string
- Blob to ArrayBuffer
- Blob to Uint8Array
- Blob to DataView
- Blob to ReadableStream
- Uint8Array to string
- Uint8Array to ArrayBuffer
- Uint8Array to Buffer
- Uint8Array to Blob
- Uint8Array to DataView
- Uint8Array to ReadableStream
- DataView to string
Test Runner
Mock functions in `bun test`
Create mocks with the
test.ts
The mock function can accept arguments.
test.ts
The result of
test.ts
These extra properties make it possible to write
test.ts
See Docs > Test Runner > Mocks for complete documentation on mocking with the Bun test runner.
mock function from bun:test.
import { test, expect, mock } from "bun:test";
const random = mock(() => Math.random());
The mock function can accept arguments.
import { test, expect, mock } from "bun:test";
const random = mock((multiplier: number) => multiplier * Math.random());
The result of
mock() is a new function that’s been decorated with some additional properties.
import { mock } from "bun:test";
const random = mock((multiplier: number) => multiplier * Math.random());
random(2);
random(10);
random.mock.calls;
// [[ 2 ], [ 10 ]]
random.mock.results;
// [
// { type: "return", value: 0.6533907460954099 },
// { type: "return", value: 0.6452713933037312 }
// ]
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.
import { test, expect, mock } from "bun:test";
const random = mock((multiplier: number) => multiplier * Math.random());
test("random", async () => {
const a = random(1);
const b = random(2);
const c = random(3);
expect(random).toHaveBeenCalled();
expect(random).toHaveBeenCalledTimes(3);
expect(random.mock.calls).toEqual([[1], [2], [3]]);
expect(random.mock.results[0]).toEqual({ type: "return", value: a });
});
See Docs > Test Runner > Mocks for complete documentation on mocking with the Bun test runner.
Was this page helpful?
⌘I
