Skip to content

Commit 9d4b5c6

Browse files
authored
chore: introduce @effect/vitest (#494)
1 parent 951bbc2 commit 9d4b5c6

13 files changed

+680
-532
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@effect/dtslint": "^0.0.5",
3232
"@effect/eslint-plugin": "^0.1.2",
3333
"@effect/language-service": "^0.1.0",
34+
"@effect/vitest": "^0.1.0",
3435
"@types/node": "^20.11.30",
3536
"@types/swagger-ui-dist": "^3.30.4",
3637
"@typescript-eslint/eslint-plugin": "^7.3.1",

packages/effect-http-node/test/client.test.ts

+25-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { HttpServer } from "@effect/platform"
22
import { Schema } from "@effect/schema"
3+
import * as it from "@effect/vitest"
34
import { Cause, Duration, Effect, Exit, Fiber, pipe } from "effect"
45
import { Api, ClientError, ExampleServer, RouterBuilder } from "effect-http"
56
import { NodeTesting } from "effect-http-node"
67
import { expect, test, vi } from "vitest"
78
import { exampleApiEmptyResponse, exampleApiGetQueryParameter } from "./examples.js"
89
import { runTestEffect } from "./utils.js"
910

10-
test("quickstart example e2e", () =>
11+
it.scoped(
12+
"quickstart example e2e",
1113
Effect.gen(function*(_) {
1214
const api = pipe(
1315
Api.make(),
@@ -31,7 +33,8 @@ test("quickstart example e2e", () =>
3133
)
3234

3335
expect(response).toEqual({ name: "milan:12" })
34-
}).pipe(runTestEffect))
36+
})
37+
)
3538

3639
test.each(["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"] as const)(
3740
"Dummy call - %s",
@@ -63,7 +66,8 @@ test.each(["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"] as const)(
6366
}).pipe(runTestEffect)
6467
)
6568

66-
test("All input types", () =>
69+
it.scoped(
70+
"All input types",
6771
Effect.gen(function*(_) {
6872
const responseSchema = Schema.struct({
6973
value: Schema.string,
@@ -113,9 +117,11 @@ test("All input types", () =>
113117
anotherValue: 1,
114118
helloWorld: "helloWorld"
115119
})
116-
}).pipe(runTestEffect))
120+
})
121+
)
117122

118-
test("missing headers", () =>
123+
it.scoped(
124+
"missing headers",
119125
Effect.gen(function*(_) {
120126
const api = pipe(
121127
Api.make(),
@@ -153,9 +159,11 @@ test("missing headers", () =>
153159
"Failed to encode headers. value must be an object, received undefined"
154160
)
155161
)
156-
}).pipe(runTestEffect))
162+
})
163+
)
157164

158-
test("supports interruption", () =>
165+
it.scoped(
166+
"supports interruption",
159167
Effect.gen(function*(_) {
160168
const api = pipe(
161169
Api.make(),
@@ -184,9 +192,11 @@ test("supports interruption", () =>
184192
expect(Exit.isFailure(result)).toEqual(true)
185193
expect(generateName).not.toHaveBeenCalled()
186194
expect(Cause.isInterruptedOnly(cause)).toEqual(true)
187-
}).pipe(runTestEffect))
195+
})
196+
)
188197

189-
test("validation error", () =>
198+
it.scoped(
199+
"validation error",
190200
Effect.gen(function*(_) {
191201
const app = ExampleServer.make(exampleApiGetQueryParameter).pipe(
192202
RouterBuilder.build
@@ -205,9 +215,11 @@ test("validation error", () =>
205215
"Failed to encode query parameters. country must be a string matching the pattern ^[A-Z]{2}$, received \"abc\""
206216
)
207217
)
208-
}).pipe(runTestEffect))
218+
})
219+
)
209220

210-
test("no-content client non-2xx response", () =>
221+
it.scoped(
222+
"no-content client non-2xx response",
211223
Effect.gen(function*(_) {
212224
const app = HttpServer.router.empty.pipe(
213225
HttpServer.router.post("/test", HttpServer.response.text("validation error", { status: 400 }))
@@ -225,4 +237,5 @@ test("no-content client non-2xx response", () =>
225237
expect(result.status).toEqual(400)
226238
}
227239
expect(result.message).toEqual("validation error")
228-
}).pipe(runTestEffect))
240+
})
241+
)
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
1-
import { Effect, pipe } from "effect"
1+
import * as it from "@effect/vitest"
2+
import { Effect } from "effect"
23
import { ExampleServer, RouterBuilder } from "effect-http"
34
import { NodeTesting } from "effect-http-node"
4-
import { expect, test } from "vitest"
5+
import { expect } from "vitest"
56
import { exampleApiFullResponse, exampleApiGet } from "./examples.js"
6-
import { runTestEffect } from "./utils.js"
7-
8-
test("example server", async () => {
9-
const app = ExampleServer.make(exampleApiGet)
10-
11-
await pipe(
12-
NodeTesting.make(RouterBuilder.build(app), exampleApiGet),
13-
Effect.flatMap((client) => client.getValue({})),
14-
Effect.map((response) => {
15-
expect(typeof response).toEqual("number")
16-
}),
17-
runTestEffect
18-
)
19-
})
20-
21-
test("handle", async () => {
22-
const app = RouterBuilder.make(exampleApiFullResponse).pipe(
23-
RouterBuilder.handle("another", () => Effect.succeed(69)),
24-
ExampleServer.handle("hello")
25-
)
26-
27-
const response = await pipe(
28-
NodeTesting.make(RouterBuilder.build(app), exampleApiFullResponse),
29-
Effect.flatMap((client) => client.hello({})),
30-
runTestEffect
31-
)
32-
33-
expect(response.status).toEqual(200)
34-
expect(typeof response.body).toEqual("number")
35-
expect(typeof response.headers["my-header"]).toEqual("string")
36-
})
37-
38-
test("handleRemaining", async () => {
39-
const app = RouterBuilder.make(exampleApiFullResponse).pipe(
40-
RouterBuilder.handle("another", () => Effect.succeed(69)),
41-
ExampleServer.handleRemaining
42-
)
43-
44-
const response = await pipe(
45-
NodeTesting.make(RouterBuilder.build(app), exampleApiFullResponse),
46-
Effect.flatMap((client) => client.hello({})),
47-
runTestEffect
48-
)
49-
50-
expect(response.status).toEqual(200)
51-
expect(typeof response.body).toEqual("number")
52-
expect(typeof response.headers["my-header"]).toEqual("string")
53-
})
7+
8+
it.scoped(
9+
"example server",
10+
Effect.gen(function*(_) {
11+
const app = ExampleServer.make(exampleApiGet)
12+
13+
const response = yield* _(
14+
NodeTesting.make(RouterBuilder.build(app), exampleApiGet),
15+
Effect.flatMap((client) => client.getValue({}))
16+
)
17+
18+
expect(typeof response).toEqual("number")
19+
})
20+
)
21+
22+
it.scoped(
23+
"handle",
24+
Effect.gen(function*(_) {
25+
const app = RouterBuilder.make(exampleApiFullResponse).pipe(
26+
RouterBuilder.handle("another", () => Effect.succeed(69)),
27+
ExampleServer.handle("hello")
28+
)
29+
30+
const response = yield* _(
31+
NodeTesting.make(RouterBuilder.build(app), exampleApiFullResponse),
32+
Effect.flatMap((client) => client.hello({}))
33+
)
34+
35+
expect(response.status).toEqual(200)
36+
expect(typeof response.body).toEqual("number")
37+
expect(typeof response.headers["my-header"]).toEqual("string")
38+
})
39+
)
40+
41+
it.scoped(
42+
"handleRemaining",
43+
Effect.gen(function*(_) {
44+
const app = RouterBuilder.make(exampleApiFullResponse).pipe(
45+
RouterBuilder.handle("another", () => Effect.succeed(69)),
46+
ExampleServer.handleRemaining
47+
)
48+
49+
const response = yield* _(
50+
NodeTesting.make(RouterBuilder.build(app), exampleApiFullResponse),
51+
Effect.flatMap((client) => client.hello({}))
52+
)
53+
54+
expect(response.status).toEqual(200)
55+
expect(typeof response.body).toEqual("number")
56+
expect(typeof response.headers["my-header"]).toEqual("string")
57+
})
58+
)

0 commit comments

Comments
 (0)