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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/add-effect-bun-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@effect/bun-test": minor
---

Add `@effect/bun-test` package — same API surface as `@effect/vitest`
(`it.effect`, `it.scoped`, `it.live`, `it.scopedLive`, `it.layer`, `it.prop`,
`flakyTest`, …) but backed by Bun's native `bun:test` runner. Closes #5964.
1 change: 1 addition & 0 deletions packages/bun-test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @effect/bun-test
21 changes: 21 additions & 0 deletions packages/bun-test/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Effectful Technologies Inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
78 changes: 78 additions & 0 deletions packages/bun-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# @effect/bun-test

A set of helpers for testing [Effect](https://effect.website) programs with
Bun's native [`bun:test`](https://bun.sh/docs/cli/test) runner.

The API mirrors [`@effect/vitest`](https://www.npmjs.com/package/@effect/vitest)
(`it.effect`, `it.scoped`, `it.live`, `it.scopedLive`, `it.layer`, `it.prop`,
`flakyTest`, …) but runs under Bun's built-in test runner — useful when you
already use Bun as your runtime and want to avoid pulling in Vitest.

## Installation

```sh
bun add -d @effect/bun-test
```

## Usage

```ts
import { describe, expect, it, layer } from "@effect/bun-test"
import { Context, Effect, Layer } from "effect"

class Foo extends Context.Tag("Foo")<Foo, "foo">() {
static Live = Layer.succeed(Foo, "foo")
}

it.effect("plain effect test", () =>
Effect.sync(() => expect(1).toEqual(1))
)

describe("with a shared layer", () => {
layer(Foo.Live)((it) => {
it.effect("has Foo in context", () =>
Effect.gen(function* () {
const foo = yield* Foo
expect(foo).toEqual("foo")
})
)
})
})
```

Run with:

```sh
bun test
```

## What's supported

| Helper | Status |
| --- | --- |
| `it.effect` / `it.scoped` / `it.live` / `it.scopedLive` | ✅ |
| `.skip`, `.skipIf`, `.runIf`, `.only`, `.each`, `.fails` | ✅ |
| `.prop` (fast-check integration) | ✅ |
| `layer(...)` / nested `it.layer(...)` | ✅ |
| `flakyTest` | ✅ |
| `addEqualityTesters` (Effect `Equal.equals` integration) | ⚠️ no-op — see below |

### Differences from `@effect/vitest`

Bun's test runner does not expose all of Vitest's APIs. The notable gaps:

- **`addEqualityTesters`** is a no-op — `bun:test`'s `expect` does not yet
expose `addEqualityTesters`. Use Effect's `Equal.equals` directly (or the
helpers in `@effect/bun-test/utils`) when comparing values that implement the
`Equal` trait.
- **`TestContext`** — Vitest passes a `TestContext` to each test fn (with
`signal`, `onTestFailed`, `onTestFinished`, etc.). `bun:test` doesn't, so the
context passed to your Effect tests is a minimal stub. `signal` is a fresh
`AbortController().signal`; `onTestFailed` / `onTestFinished` register
best-effort callbacks invoked after the Effect completes.
- **`scopedFixtures`** (Vitest's `it.scoped(fixtures)`) is not provided — Bun
has no fixture system.

## License

MIT
2 changes: 2 additions & 0 deletions packages/bun-test/bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
root = "./test"
27 changes: 27 additions & 0 deletions packages/bun-test/docgen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "../../node_modules/@effect/docgen/schema.json",
"srcLink": "https://github.com/Effect-TS/effect/tree/main/packages/bun-test/src/",
"exclude": [
"src/internal/**/*.ts"
],
"examplesCompilerOptions": {
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"moduleResolution": "Bundler",
"module": "ES2022",
"target": "ES2022",
"lib": [
"ES2022",
"DOM"
],
"paths": {
"effect": [
"../../../effect/src/index.js"
],
"effect/*": [
"../../../effect/src/*.js"
]
}
}
}
44 changes: 44 additions & 0 deletions packages/bun-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@effect/bun-test",
"version": "0.0.0",
"type": "module",
"license": "MIT",
"description": "A set of helpers for testing Effects with Bun's bun:test runner",
"homepage": "https://effect.website",
"repository": {
"type": "git",
"url": "https://github.com/Effect-TS/effect.git",
"directory": "packages/bun-test"
},
"bugs": {
"url": "https://github.com/Effect-TS/effect/issues"
},
"publishConfig": {
"access": "public",
"provenance": true,
"directory": "dist",
"linkDirectory": false
},
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts",
"./*": "./src/*.ts",
"./internal/*": null
},
"scripts": {
"build": "pnpm build-esm && pnpm build-annotate && pnpm build-cjs && build-utils pack-v3",
"build-esm": "tsc -b tsconfig.build.json",
"build-cjs": "babel build/esm --plugins @babel/transform-export-namespace-from --plugins @babel/transform-modules-commonjs --out-dir build/cjs --source-maps",
"build-annotate": "babel build/esm --plugins annotate-pure-calls --out-dir build/esm --source-maps",
"check": "tsc -b tsconfig.json",
"test": "bun test",
"coverage": "bun test --coverage"
},
"peerDependencies": {
"effect": "workspace:^"
},
"devDependencies": {
"@types/bun": "^1.1.0",
"effect": "workspace:^"
}
}
Loading
Loading