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
5 changes: 5 additions & 0 deletions .changeset/add-effect-bun-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/bun-test": patch
---

Add the `@effect/bun-test` package: the `@effect/vitest` API (`it.effect`, `it.live`, `layer`, `it.prop`, `flakyTest`, `utils`) on Bun's native `bun:test` runner. Wrapper-managed timeouts abort the synthesized test context's `AbortSignal`, so Effect fibers are interrupted and their finalizers run on timeout.
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"packages/*/benchmark/",
"packages/ai",
"packages/atom",
"packages/bun-test/",
"packages/effect/test/cluster/",
"packages/opentelemetry/",
"packages/platform/browser/",
Expand Down
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.
59 changes: 59 additions & 0 deletions packages/bun-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# @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.live`, `layer`, `it.prop`, `flakyTest`, …) so Effect test
suites move between the two runners without rewrites.

## Installation

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

## Usage

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

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

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

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

Run with:

```sh
bun test
```

## Timeouts interrupt fibers

Bun's own test timeout fails the test but cannot stop the Effect running
behind it, so finalizers would never run. The wrapper owns the timeout
instead: when it fires, the test context's `AbortSignal` aborts, the Effect
fiber is interrupted, and its finalizers run — Bun keeps a slightly larger
timeout as a backstop.

## Differences from `@effect/vitest`

- **`addEqualityTesters`** is a no-op — `bun:test`'s `expect` does not expose
`addEqualityTesters`. Compare `Equal` values with `Equal.equals` or the
helpers in `@effect/bun-test/utils`.
- **`TestContext`** — Bun doesn't pass a context object to test functions, so
the wrapper synthesises one (`signal`, `onTestFinished`, `onTestFailed`).
- **`assert`** — Vitest re-exports chai's `assert`; this package ships a small
compatible subset built on `node:assert`.
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"
60 changes: 60 additions & 0 deletions packages/bun-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@effect/bun-test",
"version": "4.0.0-rc.112",
"type": "module",
"license": "MIT",
"description": "A set of helpers for testing Effects with Bun's native 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"
},
"sideEffects": [],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts",
"./*": "./src/*.ts",
"./internal/*": null,
"./index": null,
"./*/index": null
},
"files": [
"src/**/*.ts",
"dist/**/*.js",
"dist/**/*.js.map",
"dist/**/*.d.ts",
"dist/**/*.d.ts.map",
"AGENTS.md",
"CLAUDE.md",
"ai-docs/**/*"
],
"publishConfig": {
"access": "public",
"provenance": true,
"exports": {
"./package.json": "./package.json",
".": "./dist/index.js",
"./*": "./dist/*.js",
"./internal/*": null,
"./index": null,
"./*/index": null
}
},
"scripts": {
"build": "tsc -b tsconfig.json && pnpm babel",
"babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
"check": "tsc -b tsconfig.json",
"test": "bun test"
},
"peerDependencies": {
"effect": "workspace:^"
},
"devDependencies": {
"@types/bun": "^1.3.4",
"effect": "workspace:^"
}
}
Loading