-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
650 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @since 0.41.3 | ||
*/ | ||
import type * as Etag from "@effect/platform/Etag" | ||
import type * as HttpClient from "@effect/platform/HttpClient" | ||
import type * as HttpPlatform from "@effect/platform/HttpPlatform" | ||
import type * as HttpServer from "@effect/platform/HttpServer" | ||
import type * as HttpServerError from "@effect/platform/HttpServerError" | ||
import type * as Layer from "effect/Layer" | ||
import type * as BunContext from "./BunContext.js" | ||
import * as internal from "./internal/bunHttpTest.js" | ||
|
||
/** | ||
* @since 0.41.3 | ||
* @category layers | ||
*/ | ||
export const layer: Layer.Layer< | ||
| HttpClient.HttpClient.Default | ||
| HttpServer.HttpServer | ||
| HttpPlatform.HttpPlatform | ||
| Etag.Generator | ||
| BunContext.BunContext, | ||
HttpServerError.ServeError | ||
> = internal.layer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as HttpClient from "@effect/platform/HttpClient" | ||
import * as HttpTest from "@effect/platform/HttpTest" | ||
import * as Layer from "effect/Layer" | ||
import * as BunHttpServer from "../BunHttpServer.js" | ||
|
||
/** @internal */ | ||
export const layer = HttpTest.clientLayer.pipe( | ||
Layer.provide(Layer.succeed(HttpClient.HttpClient, HttpClient.fetch)), | ||
Layer.provideMerge(BunHttpServer.layer({ port: 0 })) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { HttpClientRequest, HttpRouter, HttpServerResponse, HttpTest } from "@effect/platform" | ||
import { BunHttpTest } from "@effect/platform-bun" | ||
import { expect, it } from "bun:test" | ||
import { Effect } from "effect" | ||
|
||
it("BunHttpTest", () => | ||
Effect.gen(function*(_) { | ||
const router = HttpRouter.empty.pipe( | ||
HttpRouter.get("/", HttpServerResponse.text("Hello, World!")) | ||
) | ||
const client = yield* HttpTest.serve(router) | ||
|
||
const response1 = yield* client(HttpClientRequest.get("/")) | ||
expect(response1.status).toEqual(200) | ||
expect(yield* response1.text).toEqual("Hello, World!") | ||
|
||
const response2 = yield* client(HttpClientRequest.get("/non-existing")) | ||
expect(response2.status).toEqual(404) | ||
}).pipe(Effect.provide(BunHttpTest.layer), Effect.scoped, Effect.runPromise)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.