effect-bun-testing 3.0.0
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/LICENSE +21 -0
- package/README.md +497 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/internal.d.ts +88 -0
- package/dist/internal/internal.d.ts.map +1 -0
- package/dist/internal/internal.js +161 -0
- package/dist/internal/internal.js.map +1 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +150 -0
- package/dist/utils.js.map +1 -0
- package/package.json +59 -0
- package/src/index.ts +114 -0
- package/src/internal/internal.ts +432 -0
- package/src/utils.ts +199 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Duration, Effect, Layer, Scope } from "effect";
|
|
2
|
+
import { test as bunTest } from "bun:test";
|
|
3
|
+
import * as fc from "fast-check";
|
|
4
|
+
/** A test body that returns an Effect. */
|
|
5
|
+
export interface TestFunction<A, E, R> {
|
|
6
|
+
(): Effect.Effect<A, E, R>;
|
|
7
|
+
}
|
|
8
|
+
/** Registers a named test whose body returns an Effect. */
|
|
9
|
+
export interface Test<R> {
|
|
10
|
+
<A, E>(name: string, self: TestFunction<A, E, R>, timeout?: number): void;
|
|
11
|
+
}
|
|
12
|
+
/** Full tester with modifiers (skip, only, each, etc.). */
|
|
13
|
+
export interface Tester<R> extends Test<R> {
|
|
14
|
+
readonly skip: Test<R>;
|
|
15
|
+
readonly only: Test<R>;
|
|
16
|
+
readonly skipIf: (condition: unknown) => Test<R>;
|
|
17
|
+
readonly if: (condition: unknown) => Test<R>;
|
|
18
|
+
/** Alias for `if` (vitest compat). */
|
|
19
|
+
readonly runIf: (condition: unknown) => Test<R>;
|
|
20
|
+
readonly each: <T>(cases: ReadonlyArray<T>) => <A, E>(name: string, self: (args: T) => Effect.Effect<A, E, R>, timeout?: number) => void;
|
|
21
|
+
readonly failing: Test<R>;
|
|
22
|
+
/** Alias for `failing` (vitest compat). */
|
|
23
|
+
readonly fails: Test<R>;
|
|
24
|
+
readonly prop: PropEffect<R>;
|
|
25
|
+
}
|
|
26
|
+
/** Property-based test that returns an Effect. */
|
|
27
|
+
export interface PropEffect<R> {
|
|
28
|
+
<const Arbs extends ReadonlyArray<fc.Arbitrary<any>>>(name: string, arbitraries: Arbs, self: (...args: {
|
|
29
|
+
[K in keyof Arbs]: Arbs[K] extends fc.Arbitrary<infer T> ? T : never;
|
|
30
|
+
}) => Effect.Effect<any, any, R>, timeout?: number | {
|
|
31
|
+
readonly fastCheck?: fc.Parameters<any>;
|
|
32
|
+
}): void;
|
|
33
|
+
}
|
|
34
|
+
/** Property-based test that returns void / Promise<void>. */
|
|
35
|
+
export interface Prop {
|
|
36
|
+
<const Arbs extends ReadonlyArray<fc.Arbitrary<any>>>(name: string, arbitraries: Arbs, self: (...args: {
|
|
37
|
+
[K in keyof Arbs]: Arbs[K] extends fc.Arbitrary<infer T> ? T : never;
|
|
38
|
+
}) => void | Promise<void>, timeout?: number | {
|
|
39
|
+
readonly fastCheck?: fc.Parameters<any>;
|
|
40
|
+
}): void;
|
|
41
|
+
}
|
|
42
|
+
export type TestServices = never;
|
|
43
|
+
/** Full method set exposed on `it` and returned from `makeMethods`. */
|
|
44
|
+
export interface Methods {
|
|
45
|
+
readonly effect: Tester<never>;
|
|
46
|
+
readonly scoped: Tester<Scope.Scope>;
|
|
47
|
+
readonly live: Tester<never>;
|
|
48
|
+
readonly scopedLive: Tester<Scope.Scope>;
|
|
49
|
+
readonly flakyTest: typeof flakyTest;
|
|
50
|
+
readonly layer: typeof layer;
|
|
51
|
+
readonly prop: Prop;
|
|
52
|
+
}
|
|
53
|
+
/** Method set available inside a `layer()` callback. */
|
|
54
|
+
export interface MethodsNonLive<R, ExcludeTestServices extends boolean = false> {
|
|
55
|
+
readonly effect: Tester<R>;
|
|
56
|
+
readonly scoped: Tester<R | Scope.Scope>;
|
|
57
|
+
readonly flakyTest: typeof flakyTest;
|
|
58
|
+
readonly layer: <R2, E2>(layer_: Layer.Layer<R2, E2>, options?: LayerOptions) => LayerFn<R2, ExcludeTestServices>;
|
|
59
|
+
readonly prop: Prop;
|
|
60
|
+
}
|
|
61
|
+
export interface LayerOptions {
|
|
62
|
+
readonly memoMap?: Layer.MemoMap;
|
|
63
|
+
readonly timeout?: Duration.DurationInput;
|
|
64
|
+
readonly excludeTestServices?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export type LayerFn<R, ExcludeTestServices extends boolean = false> = {
|
|
67
|
+
(f: (it: MethodsNonLive<R, ExcludeTestServices>) => void): void;
|
|
68
|
+
(name: string, f: (it: MethodsNonLive<R, ExcludeTestServices>) => void): void;
|
|
69
|
+
};
|
|
70
|
+
export declare const makeTester: <R>(mapEffect: (self: Effect.Effect<any, any, R>) => Effect.Effect<any, any, never>, testFn?: typeof bunTest) => Tester<R>;
|
|
71
|
+
/** Run effects with test services (TestClock, TestConsole, etc.). Not auto-scoped. */
|
|
72
|
+
export declare const effect: Tester<never>;
|
|
73
|
+
/** Run effects with test services, auto-scoped. */
|
|
74
|
+
export declare const scoped: Tester<Scope.Scope>;
|
|
75
|
+
/** Run effects live (no test services), not auto-scoped. */
|
|
76
|
+
export declare const live: Tester<never>;
|
|
77
|
+
/** Run effects live (no test services), auto-scoped. */
|
|
78
|
+
export declare const scopedLive: Tester<Scope.Scope>;
|
|
79
|
+
export declare const flakyTest: <A, E, R>(self: Effect.Effect<A, E, R>, timeout?: Duration.DurationInput) => Effect.Effect<A, never, R>;
|
|
80
|
+
export declare const prop: Prop;
|
|
81
|
+
export declare const layer: <R, E, const ExcludeTestServices extends boolean = false>(layer_: Layer.Layer<R, E>, options?: {
|
|
82
|
+
readonly memoMap?: Layer.MemoMap;
|
|
83
|
+
readonly timeout?: Duration.DurationInput;
|
|
84
|
+
readonly excludeTestServices?: ExcludeTestServices;
|
|
85
|
+
}) => LayerFn<R, ExcludeTestServices>;
|
|
86
|
+
export declare const makeMethods: () => Methods;
|
|
87
|
+
export declare const addEqualityTesters: () => void;
|
|
88
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,MAAM,EAEN,KAAK,EAGL,KAAK,EACN,MAAM,QAAQ,CAAA;AAGf,OAAO,EAIL,IAAI,IAAI,OAAO,EAEhB,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAOhC,0CAA0C;AAC1C,MAAM,WAAW,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACnC,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;CAC3B;AAED,2DAA2D;AAC3D,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC,EAAE,CAAC,EACH,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC3B,OAAO,CAAC,EAAE,MAAM,GACf,IAAI,CAAA;CACR;AAED,2DAA2D;AAC3D,MAAM,WAAW,MAAM,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,CAAA;IAChD,QAAQ,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,CAAA;IAC5C,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,CAAC,SA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DAA4D;AAC5D,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,KAAK,CAA+B,CAAA;AAE9D,wDAAwD;AACxD,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAuC,CAAA;AAMlF,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAC/B,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,UAAS,QAAQ,CAAC,aAAoC,KACrD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAWlB,CAAA;AAMV,eAAO,MAAM,IAAI,EAAE,IAiBlB,CAAA;AAMD,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,mBAAmB,SAAS,OAAO,GAAG,KAAK,EAC3E,QAAQ,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EACzB,UAAU;IACR,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAA;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAA;IACzC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,mBAAmB,CAAA;CACnD,KACA,OAAO,CAAC,CAAC,EAAE,mBAAmB,CA+EhC,CAAA;AAMD,eAAO,MAAM,WAAW,QAAO,OAQ7B,CAAA;AAMF,eAAO,MAAM,kBAAkB,QAAO,IAuBrC,CAAA"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Cause, Duration, Effect, Exit, Layer, pipe, Schedule, Scope } from "effect";
|
|
2
|
+
import * as TestContext from "effect/TestContext";
|
|
3
|
+
import * as Logger from "effect/Logger";
|
|
4
|
+
import { describe, beforeAll, afterAll, test as bunTest, expect } from "bun:test";
|
|
5
|
+
import * as fc from "fast-check";
|
|
6
|
+
import * as Equal from "effect/Equal";
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Test Environment
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
const TestEnv = TestContext.TestContext.pipe(Layer.provide(Logger.remove(Logger.defaultLogger)));
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// runPromise — Bun-adapted Effect runner (no signal, no onTestFinished)
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
const runPromise = (effect) => Effect.gen(function* () {
|
|
15
|
+
const exit = yield* Effect.exit(effect);
|
|
16
|
+
if (Exit.isSuccess(exit)) {
|
|
17
|
+
return exit.value;
|
|
18
|
+
}
|
|
19
|
+
if (Cause.isInterruptedOnly(exit.cause)) {
|
|
20
|
+
throw new Error("All fibers interrupted without errors.");
|
|
21
|
+
}
|
|
22
|
+
const errors = Cause.prettyErrors(exit.cause);
|
|
23
|
+
for (let i = 1; i < errors.length; i++) {
|
|
24
|
+
yield* Effect.logError(errors[i]);
|
|
25
|
+
}
|
|
26
|
+
throw errors[0];
|
|
27
|
+
}).pipe(Effect.runPromise);
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// makeTester — creates a Tester<R> that maps each test body through mapEffect
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
export const makeTester = (mapEffect, testFn = bunTest) => {
|
|
32
|
+
const run = (self) => runPromise(pipe(Effect.suspend(self), mapEffect, Effect.asVoid));
|
|
33
|
+
const f = (name, self, timeout) => testFn(name, () => run(self), timeout);
|
|
34
|
+
const skip = (name, self, timeout) => testFn.skip(name, () => run(self), timeout);
|
|
35
|
+
const only = (name, self, timeout) => testFn.only(name, () => run(self), timeout);
|
|
36
|
+
const skipIf = (condition) => (name, self, timeout) => testFn.skipIf(condition)(name, () => run(self), timeout);
|
|
37
|
+
const ifCond = (condition) => (name, self, timeout) => testFn.if(condition)(name, () => run(self), timeout);
|
|
38
|
+
const each = (cases) => (name, self, timeout) => testFn.each(cases)(name, (args) => runPromise(pipe(Effect.suspend(() => self(args)), mapEffect, Effect.asVoid)), timeout);
|
|
39
|
+
const failing = (name, self, timeout) => testFn.failing(name, () => run(self), timeout);
|
|
40
|
+
const propFn = (name, arbitraries, self, timeout) => {
|
|
41
|
+
const fcOptions = typeof timeout === "object" ? timeout?.fastCheck : undefined;
|
|
42
|
+
const timeoutMs = typeof timeout === "number" ? timeout : undefined;
|
|
43
|
+
testFn(name, async () => {
|
|
44
|
+
await fc.assert(fc.asyncProperty(...arbitraries, (...args) => runPromise(pipe(Effect.suspend(() => self(...args)), mapEffect, Effect.asVoid))), fcOptions);
|
|
45
|
+
}, timeoutMs);
|
|
46
|
+
};
|
|
47
|
+
return Object.assign(f, {
|
|
48
|
+
skip,
|
|
49
|
+
only,
|
|
50
|
+
skipIf,
|
|
51
|
+
if: ifCond,
|
|
52
|
+
runIf: ifCond,
|
|
53
|
+
each,
|
|
54
|
+
failing,
|
|
55
|
+
fails: failing,
|
|
56
|
+
prop: propFn
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// Preconfigured testers
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
/** Run effects with test services (TestClock, TestConsole, etc.). Not auto-scoped. */
|
|
63
|
+
export const effect = makeTester((e) => Effect.provide(e, TestEnv));
|
|
64
|
+
/** Run effects with test services, auto-scoped. */
|
|
65
|
+
export const scoped = makeTester((e) => e.pipe(Effect.scoped, Effect.provide(TestEnv)));
|
|
66
|
+
/** Run effects live (no test services), not auto-scoped. */
|
|
67
|
+
export const live = makeTester((e) => e);
|
|
68
|
+
/** Run effects live (no test services), auto-scoped. */
|
|
69
|
+
export const scopedLive = makeTester((e) => Effect.scoped(e));
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// flakyTest — retry an effect up to 10 times within a timeout
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
export const flakyTest = (self, timeout = Duration.seconds(30)) => pipe(Effect.catchAllDefect(self, (defect) => Effect.fail(defect)), Effect.retry(pipe(Schedule.recurs(10), Schedule.compose(Schedule.elapsed), Schedule.whileOutput(Duration.lessThanOrEqualTo(timeout)))), Effect.orDie);
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// prop — non-Effect property-based test
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
export const prop = (name, arbitraries, self, timeout) => {
|
|
78
|
+
const fcOptions = typeof timeout === "object" ? timeout?.fastCheck : undefined;
|
|
79
|
+
const timeoutMs = typeof timeout === "number" ? timeout : undefined;
|
|
80
|
+
bunTest(name, async () => {
|
|
81
|
+
await fc.assert(fc.asyncProperty(...arbitraries, (...args) => self(...args)), fcOptions);
|
|
82
|
+
}, timeoutMs);
|
|
83
|
+
};
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// layer — shared Layer across tests with beforeAll/afterAll lifecycle
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
export const layer = (layer_, options) => {
|
|
88
|
+
return ((...args) => {
|
|
89
|
+
const excludeTestServices = options?.excludeTestServices ?? false;
|
|
90
|
+
const withTestEnv = excludeTestServices
|
|
91
|
+
? layer_
|
|
92
|
+
: Layer.provideMerge(layer_, TestEnv);
|
|
93
|
+
const memoMap = options?.memoMap ?? Effect.runSync(Layer.makeMemoMap);
|
|
94
|
+
const scope = Effect.runSync(Scope.make());
|
|
95
|
+
const timeout = options?.timeout
|
|
96
|
+
? Duration.toMillis(options.timeout)
|
|
97
|
+
: undefined;
|
|
98
|
+
const runtimeEffect = pipe(Layer.toRuntimeWithMemoMap(withTestEnv, memoMap), Scope.extend(scope), Effect.orDie, Effect.cached, Effect.runSync);
|
|
99
|
+
const effectTester = makeTester((e) => Effect.flatMap(runtimeEffect, (runtime) => Effect.provide(e, runtime)));
|
|
100
|
+
const scopedTester = makeTester((e) => Effect.flatMap(runtimeEffect, (runtime) => e.pipe(Effect.scoped, Effect.provide(runtime))));
|
|
101
|
+
const makeIt = () => ({
|
|
102
|
+
effect: effectTester,
|
|
103
|
+
scoped: scopedTester,
|
|
104
|
+
flakyTest,
|
|
105
|
+
prop,
|
|
106
|
+
layer: (nestedLayer, nestedOptions) => layer(Layer.provideMerge(nestedLayer, withTestEnv), {
|
|
107
|
+
...nestedOptions,
|
|
108
|
+
memoMap,
|
|
109
|
+
excludeTestServices: true
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
if (args.length === 1) {
|
|
113
|
+
beforeAll(() => runPromise(Effect.asVoid(runtimeEffect)), timeout);
|
|
114
|
+
afterAll(() => runPromise(Scope.close(scope, Exit.void)), timeout);
|
|
115
|
+
return args[0](makeIt());
|
|
116
|
+
}
|
|
117
|
+
return describe(args[0], () => {
|
|
118
|
+
beforeAll(() => runPromise(Effect.asVoid(runtimeEffect)), timeout);
|
|
119
|
+
afterAll(() => runPromise(Scope.close(scope, Exit.void)), timeout);
|
|
120
|
+
return args[1](makeIt());
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// makeMethods — compose the full `Methods` object
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
export const makeMethods = () => ({
|
|
128
|
+
effect,
|
|
129
|
+
scoped,
|
|
130
|
+
live,
|
|
131
|
+
scopedLive,
|
|
132
|
+
flakyTest,
|
|
133
|
+
layer,
|
|
134
|
+
prop
|
|
135
|
+
});
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// addEqualityTesters — register Effect Equal-aware matchers via expect.extend
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
export const addEqualityTesters = () => {
|
|
140
|
+
expect.extend({
|
|
141
|
+
toEqualEffect(received, expected) {
|
|
142
|
+
if (!Equal.isEqual(received) || !Equal.isEqual(expected)) {
|
|
143
|
+
const pass = Object.is(received, expected);
|
|
144
|
+
return {
|
|
145
|
+
pass,
|
|
146
|
+
message: () => pass
|
|
147
|
+
? `Expected values to not be equal`
|
|
148
|
+
: `Expected values to be equal`
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const pass = Equal.equals(received, expected);
|
|
152
|
+
return {
|
|
153
|
+
pass,
|
|
154
|
+
message: () => pass
|
|
155
|
+
? `Expected Effect values to not be equal (via Equal.equals)`
|
|
156
|
+
: `Expected Effect values to be equal (via Equal.equals), but they differ`
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,KAAK,EACN,MAAM,QAAQ,CAAA;AACf,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAA;AACjD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,IAAI,IAAI,OAAO,EACf,MAAM,EACP,MAAM,UAAU,CAAA;AACjB,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAChC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAqGrC,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,MAAM,OAAO,GAAqB,WAAW,CAAC,WAAW,CAAC,IAAI,CAC5D,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CACnD,CAAA;AAED,8EAA8E;AAC9E,yEAAyE;AACzE,8EAA8E;AAE9E,MAAM,UAAU,GAAG,CAAO,MAAkC,EAAc,EAAE,CAC1E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,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;oBAC7D,CAAC,CAAC,wEAAwE;aAC/E,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Option, Either, Exit, Cause } from "effect";
|
|
2
|
+
export declare function fail(message: string): never;
|
|
3
|
+
export declare function deepStrictEqual<A>(actual: A, expected: A, message?: string): void;
|
|
4
|
+
export declare function strictEqual<A>(actual: A, expected: A, message?: string): void;
|
|
5
|
+
export declare function notDeepStrictEqual<A>(actual: A, expected: A, message?: string): void;
|
|
6
|
+
/** Compare using Effect's `Equal.equals` for structural equality. */
|
|
7
|
+
export declare function assertEquals<A>(actual: A, expected: A, message?: string): void;
|
|
8
|
+
export declare function doesNotThrow(thunk: () => void, message?: string): void;
|
|
9
|
+
export declare function assertTrue(self: unknown, message?: string): asserts self;
|
|
10
|
+
export declare function assertFalse(self: boolean, message?: string): void;
|
|
11
|
+
export declare function assertInstanceOf<C extends abstract new (...args: any[]) => any>(value: unknown, constructor: C, message?: string): asserts value is InstanceType<C>;
|
|
12
|
+
export declare function assertInclude(actual: string | undefined, expected: string): void;
|
|
13
|
+
export declare function assertMatch(actual: string, regexp: RegExp): void;
|
|
14
|
+
export declare function throws(thunk: () => void, error?: Error | ((u: unknown) => void)): void;
|
|
15
|
+
export declare function throwsAsync(thunk: () => Promise<void>, error?: Error | ((u: unknown) => void)): Promise<void>;
|
|
16
|
+
export declare function assertNone<A>(option: Option.Option<A>): asserts option is Option.None<never>;
|
|
17
|
+
export declare function assertSome<A>(option: Option.Option<A>, expected: A): asserts option is Option.Some<A>;
|
|
18
|
+
export declare function assertRight<A, E>(either: Either.Either<A, E>, expected: A): asserts either is Either.Right<E, A>;
|
|
19
|
+
export declare function assertLeft<A, E>(either: Either.Either<A, E>, expected: E): asserts either is Either.Left<E, A>;
|
|
20
|
+
export declare function assertExitSuccess<A, E>(exit: Exit.Exit<A, E>, expected: A): asserts exit is Exit.Success<A, never>;
|
|
21
|
+
export declare function assertExitFailure<A, E>(exit: Exit.Exit<A, E>, expected: Cause.Cause<E>): asserts exit is Exit.Failure<never, E>;
|
|
22
|
+
/** @deprecated Use assertExitSuccess. Alias. */
|
|
23
|
+
export declare const assertSuccess: typeof assertExitSuccess;
|
|
24
|
+
/** @deprecated Use assertExitFailure. Alias. */
|
|
25
|
+
export declare const assertFailure: typeof assertExitFailure;
|
|
26
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAMpD,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAE3C;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAKjF;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAE7E;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAEpF;AAED,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAO9E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAMtE;AAMD,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,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AAC,CAAC,CAAC,CAKlC;AAMD,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3B,QAAQ,EAAE,CAAC,GACV,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAKtC;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAC3B,QAAQ,EAAE,CAAC,GACV,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAKrC;AAMD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EACpC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EACrB,QAAQ,EAAE,CAAC,GACV,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAKxC;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EACpC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EACrB,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAKxC;AAED,gDAAgD;AAChD,eAAO,MAAM,aAAa,0BAAoB,CAAA;AAC9C,gDAAgD;AAChD,eAAO,MAAM,aAAa,0BAAoB,CAAA"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { expect } from "bun:test";
|
|
2
|
+
import * as Equal from "effect/Equal";
|
|
3
|
+
import { Option, Either, Exit } from "effect";
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Primitive assertions
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
export function fail(message) {
|
|
8
|
+
throw new Error(message);
|
|
9
|
+
}
|
|
10
|
+
export function deepStrictEqual(actual, expected, message) {
|
|
11
|
+
expect(actual).toStrictEqual(expected);
|
|
12
|
+
if (message) {
|
|
13
|
+
// Message is informational — the assertion above throws on failure
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function strictEqual(actual, expected, message) {
|
|
17
|
+
expect(actual).toBe(expected);
|
|
18
|
+
}
|
|
19
|
+
export function notDeepStrictEqual(actual, expected, message) {
|
|
20
|
+
expect(actual).not.toStrictEqual(expected);
|
|
21
|
+
}
|
|
22
|
+
/** Compare using Effect's `Equal.equals` for structural equality. */
|
|
23
|
+
export function assertEquals(actual, expected, message) {
|
|
24
|
+
if (!Equal.equals(actual, expected)) {
|
|
25
|
+
const msg = message ?? `Expected values to be equal (via Equal.equals)`;
|
|
26
|
+
throw new Error(`${msg}\n actual: ${JSON.stringify(actual)}\n expected: ${JSON.stringify(expected)}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function doesNotThrow(thunk, message) {
|
|
30
|
+
try {
|
|
31
|
+
thunk();
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new Error(message ?? `Expected function not to throw, but it threw: ${e}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// Boolean assertions
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
export function assertTrue(self, message) {
|
|
41
|
+
expect(self).toBeTruthy();
|
|
42
|
+
}
|
|
43
|
+
export function assertFalse(self, message) {
|
|
44
|
+
expect(self).toBeFalsy();
|
|
45
|
+
}
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Type assertions
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
export function assertInstanceOf(value, constructor, message) {
|
|
50
|
+
expect(value).toBeInstanceOf(constructor);
|
|
51
|
+
}
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// String assertions
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
export function assertInclude(actual, expected) {
|
|
56
|
+
expect(actual).toBeDefined();
|
|
57
|
+
expect(actual).toInclude(expected);
|
|
58
|
+
}
|
|
59
|
+
export function assertMatch(actual, regexp) {
|
|
60
|
+
expect(actual).toMatch(regexp);
|
|
61
|
+
}
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
// Throw assertions
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
export function throws(thunk, error) {
|
|
66
|
+
if (typeof error === "function") {
|
|
67
|
+
try {
|
|
68
|
+
thunk();
|
|
69
|
+
throw new Error("Expected function to throw");
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
error(e);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else if (error) {
|
|
76
|
+
expect(thunk).toThrow(error.message);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
expect(thunk).toThrow();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export async function throwsAsync(thunk, error) {
|
|
83
|
+
if (typeof error === "function") {
|
|
84
|
+
try {
|
|
85
|
+
await thunk();
|
|
86
|
+
throw new Error("Expected async function to throw");
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
error(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
try {
|
|
94
|
+
await thunk();
|
|
95
|
+
throw new Error("Expected async function to throw");
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
if (error && e instanceof Error) {
|
|
99
|
+
expect(e.message).toInclude(error.message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Option assertions
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
export function assertNone(option) {
|
|
108
|
+
expect(Option.isNone(option)).toBe(true);
|
|
109
|
+
}
|
|
110
|
+
export function assertSome(option, expected) {
|
|
111
|
+
expect(Option.isSome(option)).toBe(true);
|
|
112
|
+
if (Option.isSome(option)) {
|
|
113
|
+
assertEquals(option.value, expected);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// Either assertions
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
export function assertRight(either, expected) {
|
|
120
|
+
expect(Either.isRight(either)).toBe(true);
|
|
121
|
+
if (Either.isRight(either)) {
|
|
122
|
+
assertEquals(either.right, expected);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export function assertLeft(either, expected) {
|
|
126
|
+
expect(Either.isLeft(either)).toBe(true);
|
|
127
|
+
if (Either.isLeft(either)) {
|
|
128
|
+
assertEquals(either.left, expected);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// Exit assertions
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
export function assertExitSuccess(exit, expected) {
|
|
135
|
+
expect(Exit.isSuccess(exit)).toBe(true);
|
|
136
|
+
if (Exit.isSuccess(exit)) {
|
|
137
|
+
assertEquals(exit.value, expected);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function assertExitFailure(exit, expected) {
|
|
141
|
+
expect(Exit.isFailure(exit)).toBe(true);
|
|
142
|
+
if (Exit.isFailure(exit)) {
|
|
143
|
+
assertEquals(exit.cause, expected);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** @deprecated Use assertExitSuccess. Alias. */
|
|
147
|
+
export const assertSuccess = assertExitSuccess;
|
|
148
|
+
/** @deprecated Use assertExitFailure. Alias. */
|
|
149
|
+
export const assertFailure = assertExitFailure;
|
|
150
|
+
//# sourceMappingURL=utils.js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,CAAA;IACpC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAAqB,EACrB,QAAwB;IAExB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvC,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,YAAY,CAAC,IAAI,CAAC,KAAY,EAAE,QAAe,CAAC,CAAA;IAClD,CAAC;AACH,CAAC;AAED,gDAAgD;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAA;AAC9C,gDAAgD;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "effect-bun-testing",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Effect test helpers for Bun's built-in test runner",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"bun": "./src/index.ts",
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"./utils": {
|
|
17
|
+
"bun": "./src/utils.ts",
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./dist/utils.d.ts",
|
|
20
|
+
"default": "./dist/utils.js"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"src",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"effect": "^3.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@changesets/changelog-github": "^0.5.2",
|
|
34
|
+
"@changesets/cli": "^2.29.8",
|
|
35
|
+
"@types/bun": "^1.2.0",
|
|
36
|
+
"effect": "3.19.19",
|
|
37
|
+
"fast-check": "^3.23.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "bun test",
|
|
41
|
+
"typecheck": "bun x tsc --noEmit",
|
|
42
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
43
|
+
"prepublishOnly": "bun run build",
|
|
44
|
+
"changeset": "changeset",
|
|
45
|
+
"version": "changeset version",
|
|
46
|
+
"release": "bun run build && changeset publish"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"effect",
|
|
50
|
+
"bun",
|
|
51
|
+
"test",
|
|
52
|
+
"testing"
|
|
53
|
+
],
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "https://github.com/jmenga/effect-bun-testing"
|
|
57
|
+
},
|
|
58
|
+
"license": "MIT"
|
|
59
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effect test helpers for Bun's built-in test runner.
|
|
3
|
+
*
|
|
4
|
+
* Ports the `@effect/vitest` API to `bun:test`, including `it.effect`,
|
|
5
|
+
* `it.scoped`, `it.live`, `layer()`, `flakyTest`, property-based testing,
|
|
6
|
+
* and assertion utilities.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { it } from "effect-bun-test"
|
|
11
|
+
* import { Effect } from "effect"
|
|
12
|
+
*
|
|
13
|
+
* it.effect("adds numbers", () =>
|
|
14
|
+
* Effect.gen(function*() {
|
|
15
|
+
* const result = 1 + 1
|
|
16
|
+
* expect(result).toBe(2)
|
|
17
|
+
* })
|
|
18
|
+
* )
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
// Re-export bun:test for convenience (parallel to @effect/vitest re-exporting vitest)
|
|
25
|
+
export {
|
|
26
|
+
describe,
|
|
27
|
+
expect,
|
|
28
|
+
beforeAll,
|
|
29
|
+
afterAll,
|
|
30
|
+
beforeEach,
|
|
31
|
+
afterEach,
|
|
32
|
+
test,
|
|
33
|
+
mock,
|
|
34
|
+
spyOn,
|
|
35
|
+
jest,
|
|
36
|
+
vi,
|
|
37
|
+
setSystemTime
|
|
38
|
+
} from "bun:test"
|
|
39
|
+
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// Core exports from internal
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
export {
|
|
44
|
+
effect,
|
|
45
|
+
scoped,
|
|
46
|
+
live,
|
|
47
|
+
scopedLive,
|
|
48
|
+
makeTester,
|
|
49
|
+
flakyTest,
|
|
50
|
+
prop,
|
|
51
|
+
layer,
|
|
52
|
+
makeMethods,
|
|
53
|
+
addEqualityTesters
|
|
54
|
+
} from "./internal/internal.js"
|
|
55
|
+
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// Type exports
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
export type {
|
|
60
|
+
TestFunction,
|
|
61
|
+
Test,
|
|
62
|
+
Tester,
|
|
63
|
+
PropEffect,
|
|
64
|
+
Prop,
|
|
65
|
+
TestServices,
|
|
66
|
+
Methods,
|
|
67
|
+
MethodsNonLive,
|
|
68
|
+
LayerOptions,
|
|
69
|
+
LayerFn
|
|
70
|
+
} from "./internal/internal.js"
|
|
71
|
+
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// Composed `it` — the primary import for most users
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
import { test as bunTest } from "bun:test"
|
|
76
|
+
import {
|
|
77
|
+
effect,
|
|
78
|
+
scoped,
|
|
79
|
+
live,
|
|
80
|
+
scopedLive,
|
|
81
|
+
flakyTest,
|
|
82
|
+
layer,
|
|
83
|
+
prop
|
|
84
|
+
} from "./internal/internal.js"
|
|
85
|
+
import type { Methods } from "./internal/internal.js"
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Drop-in replacement for bun:test's `it` / `test`, augmented with Effect
|
|
89
|
+
* methods.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { it } from "effect-bun-test"
|
|
94
|
+
*
|
|
95
|
+
* it.effect("runs an Effect test", () =>
|
|
96
|
+
* Effect.succeed(42).pipe(Effect.map((n) => expect(n).toBe(42)))
|
|
97
|
+
* )
|
|
98
|
+
*
|
|
99
|
+
* it.scoped("runs with scope", () =>
|
|
100
|
+
* Effect.gen(function*() {
|
|
101
|
+
* yield* Effect.addFinalizer(() => Effect.void)
|
|
102
|
+
* })
|
|
103
|
+
* )
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export const it: typeof bunTest & Methods = Object.assign(bunTest, {
|
|
107
|
+
effect,
|
|
108
|
+
scoped,
|
|
109
|
+
live,
|
|
110
|
+
scopedLive,
|
|
111
|
+
flakyTest,
|
|
112
|
+
layer,
|
|
113
|
+
prop
|
|
114
|
+
} satisfies Methods)
|