|
1 | 1 | # effect-http-node |
2 | 2 |
|
| 3 | +## 0.15.3 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- [#606](https://github.com/sukovanej/effect-http/pull/606) [`af1fcad`](https://github.com/sukovanej/effect-http/commit/af1fcadebb6f57b7b7c2767998f344fcd7845895) Thanks [@sukovanej](https://github.com/sukovanej)! - Add `NodeTesting.handler`. It accepts a `Handler.Handler<A, E, R>` and produces an instance |
| 8 | + of `HttpClient.HttpClient.Default`. It start the server with the handler in a background |
| 9 | + and the produced client has base URL pointing to the server. It behaves exactly like the |
| 10 | + `NodeTesting.makeRaw`, but it works with handlers instead of `HttpApp.HttpApp` instances. |
| 11 | + |
| 12 | + It provides a convenient way to test handlers in isolation. |
| 13 | + |
| 14 | + ```ts |
| 15 | + import { HttpClientRequest } from "@effect/platform"; |
| 16 | + import { Schema } from "@effect/schema"; |
| 17 | + import { expect, it } from "@effect/vitest"; |
| 18 | + import { Effect } from "effect"; |
| 19 | + import { Api, Handler } from "effect-http"; |
| 20 | + import { NodeTesting } from "effect-http-node"; |
| 21 | + |
| 22 | + const myEndpoint = Api.get("myEndpoint", "/my-endpoint").pipe( |
| 23 | + Api.setResponseBody(Schema.Struct({ hello: Schema.String })), |
| 24 | + ); |
| 25 | + |
| 26 | + const myHandler = Handler.make(myEndpoint, () => |
| 27 | + Effect.succeed({ hello: "world" }), |
| 28 | + ); |
| 29 | + |
| 30 | + it.scoped("myHandler", () => |
| 31 | + Effect.gen(function* () { |
| 32 | + const client = yield* NodeTesting.handler(myHandler); |
| 33 | + const response = yield* client(HttpClientRequest.get("/my-endpoint")); |
| 34 | + |
| 35 | + expect(response.status).toEqual(200); |
| 36 | + expect(yield* response.json).toEqual({ hello: "world" }); |
| 37 | + }), |
| 38 | + ); |
| 39 | + ``` |
| 40 | + |
| 41 | +- Updated dependencies [[`6b388fa`](https://github.com/sukovanej/effect-http/commit/6b388faae43d121e5a58c739c2a9d78a108c656b)]: |
| 42 | + |
| 43 | + |
3 | 44 | ## 0.15.2 |
4 | 45 |
|
5 | 46 | ### Patch Changes |
|
0 commit comments