@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 79 lines 2.65 KB
Raw
1 import { assert, beforeEach, describe, makeMethods, test } from "@effect/vitest"
2 import { Effect, Layer, Schema } from "effect"
3
4 describe("makeMethods fixtures", () => {
5 const it = makeMethods(test.extend("value", () => 1))
6
7 it.effect("it.effect", ({ value }) => Effect.sync(() => assert.strictEqual(value, 1)))
8
9 it.effect.each(["a"])("it.effect.each", (text, { value }) =>
10 Effect.sync(() => {
11 assert.strictEqual(text, "a")
12 assert.strictEqual(value, 1)
13 }))
14
15 it.layer(Layer.empty)((it) => {
16 it.effect("anonymous layer it.effect", ({ value }) => Effect.sync(() => assert.strictEqual(value, 1)))
17 })
18
19 it.layer(Layer.empty)("outer layer", (it) => {
20 it.layer(Layer.empty)("nested layer", (it) => {
21 it.effect("nested it.effect", ({ value }) => Effect.sync(() => assert.strictEqual(value, 1)))
22 })
23 })
24 })
25
26 describe("Effect hook fixtures", () => {
27 const it = makeMethods(test.extend("value", () => 1))
28 let hookValue: number | undefined
29
30 beforeEach<{ value: number }>(({ value }) => Effect.sync(() => (hookValue = value)))
31
32 it.effect("beforeEach can destructure fixtures", () => Effect.sync(() => assert.strictEqual(hookValue, 1)))
33 })
34
35 describe("makeMethods registers through the given test API", { concurrent: false }, () => {
36 const setups: Array<string> = []
37 const it = makeMethods(test.extend("setup", { auto: true }, ({ task }) => {
38 setups.push(task.name)
39 }))
40
41 it.effect.fails("fails", () => Effect.fail("expected"))
42
43 it.prop("prop", [Schema.Boolean], () => true)
44
45 it.effect.prop("effect.prop", [Schema.Boolean], () => Effect.succeed(true))
46 it.live.prop("live.prop", [Schema.Boolean], () => Effect.succeed(true))
47 it.effect.skipIf(false)("skipIf", () => Effect.void)
48 it.effect.runIf(true)("runIf", () => Effect.void)
49
50 it.layer(Layer.empty)("outer", (it) => {
51 it.layer(Layer.empty)("inner", (it) => {
52 it.prop("nested prop", [Schema.Boolean], () => true)
53 })
54 })
55
56 test("runs auto fixtures", () => {
57 assert.deepStrictEqual(setups, ["fails", "prop", "effect.prop", "live.prop", "skipIf", "runIf", "nested prop"])
58 })
59 })
60
61 describe("makeMethods fixture lifecycle", { concurrent: false }, () => {
62 const events: Array<string> = []
63 const it = makeMethods(test.extend("resource", ({ task: _ }, { onCleanup }) => {
64 events.push("setup")
65 onCleanup(() => {
66 events.push("teardown")
67 })
68 }))
69
70 it.effect("uses the fixture", ({ resource: _ }) =>
71 Effect.acquireRelease(
72 Effect.sync(() => events.push("acquire")),
73 () => Effect.sync(() => events.push("release"))
74 ))
75
76 test("wraps the test's scope", () => {
77 assert.deepStrictEqual(events, ["setup", "acquire", "release", "teardown"])
78 })
79 })