1import { assert, describe, makeMethods, test } from "@effect/vitest"
2import { Effect, Layer, Schema } from "effect"
3
4describe("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
26describe("makeMethods registers through the given test API", { concurrent: false }, () => {
27 const setups: Array<string> = []
28 const it = makeMethods(test.extend("setup", { auto: true }, ({ task }) => {
29 setups.push(task.name)
30 }))
31
32 it.effect.fails("fails", () => Effect.fail("expected"))
33
34 it.prop("prop", [Schema.Boolean], () => true)
35
36 it.effect.prop("effect.prop", [Schema.Boolean], () => Effect.succeed(true))
37 it.live.prop("live.prop", [Schema.Boolean], () => Effect.succeed(true))
38 it.effect.skipIf(false)("skipIf", () => Effect.void)
39 it.effect.runIf(true)("runIf", () => Effect.void)
40
41 it.layer(Layer.empty)("outer", (it) => {
42 it.layer(Layer.empty)("inner", (it) => {
43 it.prop("nested prop", [Schema.Boolean], () => true)
44 })
45 })
46
47 test("runs auto fixtures", () => {
48 assert.deepStrictEqual(setups, ["fails", "prop", "effect.prop", "live.prop", "skipIf", "runIf", "nested prop"])
49 })
50})
51
52describe("makeMethods fixture lifecycle", { concurrent: false }, () => {
53 const events: Array<string> = []
54 const it = makeMethods(test.extend("resource", ({ task: _ }, { onCleanup }) => {
55 events.push("setup")
56 onCleanup(() => {
57 events.push("teardown")
58 })
59 }))
60
61 it.effect("uses the fixture", ({ resource: _ }) =>
62 Effect.acquireRelease(
63 Effect.sync(() => events.push("acquire")),
64 () => Effect.sync(() => events.push("release"))
65 ))
66
67 test("wraps the test's scope", () => {
68 assert.deepStrictEqual(events, ["setup", "acquire", "release", "teardown"])
69 })
70})