Skip to content

Commit 3f8d6e8

Browse files
committed
feat(bun-test): add @effect/bun-test package
Mirrors @effect/vitest's API (it.effect, it.scoped, it.live, it.scopedLive, it.layer, it.prop, flakyTest) but runs under Bun's built-in bun:test runner. Closes #5964.
1 parent e71ba68 commit 3f8d6e8

16 files changed

Lines changed: 1515 additions & 10 deletions

.changeset/add-effect-bun-test.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@effect/bun-test": minor
3+
---
4+
5+
Add `@effect/bun-test` package — same API surface as `@effect/vitest`
6+
(`it.effect`, `it.scoped`, `it.live`, `it.scopedLive`, `it.layer`, `it.prop`,
7+
`flakyTest`, …) but backed by Bun's native `bun:test` runner. Closes #5964.

packages/bun-test/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @effect/bun-test

packages/bun-test/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Effectful Technologies Inc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/bun-test/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# @effect/bun-test
2+
3+
A set of helpers for testing [Effect](https://effect.website) programs with
4+
Bun's native [`bun:test`](https://bun.sh/docs/cli/test) runner.
5+
6+
The API mirrors [`@effect/vitest`](https://www.npmjs.com/package/@effect/vitest)
7+
(`it.effect`, `it.scoped`, `it.live`, `it.scopedLive`, `it.layer`, `it.prop`,
8+
`flakyTest`, …) but runs under Bun's built-in test runner — useful when you
9+
already use Bun as your runtime and want to avoid pulling in Vitest.
10+
11+
## Installation
12+
13+
```sh
14+
bun add -d @effect/bun-test
15+
```
16+
17+
## Usage
18+
19+
```ts
20+
import { describe, expect, it, layer } from "@effect/bun-test"
21+
import { Context, Effect, Layer } from "effect"
22+
23+
class Foo extends Context.Tag("Foo")<Foo, "foo">() {
24+
static Live = Layer.succeed(Foo, "foo")
25+
}
26+
27+
it.effect("plain effect test", () =>
28+
Effect.sync(() => expect(1).toEqual(1))
29+
)
30+
31+
describe("with a shared layer", () => {
32+
layer(Foo.Live)((it) => {
33+
it.effect("has Foo in context", () =>
34+
Effect.gen(function* () {
35+
const foo = yield* Foo
36+
expect(foo).toEqual("foo")
37+
})
38+
)
39+
})
40+
})
41+
```
42+
43+
Run with:
44+
45+
```sh
46+
bun test
47+
```
48+
49+
## What's supported
50+
51+
| Helper | Status |
52+
| --- | --- |
53+
| `it.effect` / `it.scoped` / `it.live` / `it.scopedLive` ||
54+
| `.skip`, `.skipIf`, `.runIf`, `.only`, `.each`, `.fails` ||
55+
| `.prop` (fast-check integration) ||
56+
| `layer(...)` / nested `it.layer(...)` ||
57+
| `flakyTest` ||
58+
| `addEqualityTesters` (Effect `Equal.equals` integration) | ⚠️ no-op — see below |
59+
60+
### Differences from `@effect/vitest`
61+
62+
Bun's test runner does not expose all of Vitest's APIs. The notable gaps:
63+
64+
- **`addEqualityTesters`** is a no-op — `bun:test`'s `expect` does not yet
65+
expose `addEqualityTesters`. Use Effect's `Equal.equals` directly (or the
66+
helpers in `@effect/bun-test/utils`) when comparing values that implement the
67+
`Equal` trait.
68+
- **`TestContext`** — Vitest passes a `TestContext` to each test fn (with
69+
`signal`, `onTestFailed`, `onTestFinished`, etc.). `bun:test` doesn't, so the
70+
context passed to your Effect tests is a minimal stub. `signal` is a fresh
71+
`AbortController().signal`; `onTestFailed` / `onTestFinished` register
72+
best-effort callbacks invoked after the Effect completes.
73+
- **`scopedFixtures`** (Vitest's `it.scoped(fixtures)`) is not provided — Bun
74+
has no fixture system.
75+
76+
## License
77+
78+
MIT

packages/bun-test/bunfig.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[test]
2+
root = "./test"

packages/bun-test/docgen.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"$schema": "../../node_modules/@effect/docgen/schema.json",
3+
"srcLink": "https://github.com/Effect-TS/effect/tree/main/packages/bun-test/src/",
4+
"exclude": [
5+
"src/internal/**/*.ts"
6+
],
7+
"examplesCompilerOptions": {
8+
"noEmit": true,
9+
"strict": true,
10+
"skipLibCheck": true,
11+
"moduleResolution": "Bundler",
12+
"module": "ES2022",
13+
"target": "ES2022",
14+
"lib": [
15+
"ES2022",
16+
"DOM"
17+
],
18+
"paths": {
19+
"effect": [
20+
"../../../effect/src/index.js"
21+
],
22+
"effect/*": [
23+
"../../../effect/src/*.js"
24+
]
25+
}
26+
}
27+
}

packages/bun-test/package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "@effect/bun-test",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"license": "MIT",
6+
"description": "A set of helpers for testing Effects with Bun's bun:test runner",
7+
"homepage": "https://effect.website",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/Effect-TS/effect.git",
11+
"directory": "packages/bun-test"
12+
},
13+
"bugs": {
14+
"url": "https://github.com/Effect-TS/effect/issues"
15+
},
16+
"publishConfig": {
17+
"access": "public",
18+
"provenance": true,
19+
"directory": "dist",
20+
"linkDirectory": false
21+
},
22+
"exports": {
23+
"./package.json": "./package.json",
24+
".": "./src/index.ts",
25+
"./*": "./src/*.ts",
26+
"./internal/*": null
27+
},
28+
"scripts": {
29+
"build": "pnpm build-esm && pnpm build-annotate && pnpm build-cjs && build-utils pack-v3",
30+
"build-esm": "tsc -b tsconfig.build.json",
31+
"build-cjs": "babel build/esm --plugins @babel/transform-export-namespace-from --plugins @babel/transform-modules-commonjs --out-dir build/cjs --source-maps",
32+
"build-annotate": "babel build/esm --plugins annotate-pure-calls --out-dir build/esm --source-maps",
33+
"check": "tsc -b tsconfig.json",
34+
"test": "bun test",
35+
"coverage": "bun test --coverage"
36+
},
37+
"peerDependencies": {
38+
"effect": "workspace:^"
39+
},
40+
"devDependencies": {
41+
"@types/bun": "^1.1.0",
42+
"effect": "workspace:^"
43+
}
44+
}

0 commit comments

Comments
 (0)