Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
fix test parallelization issue
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Aug 10, 2024
1 parent a420635 commit 11a4a69
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
32 changes: 19 additions & 13 deletions api/tests/fixtures/start-server.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
import { createFetchHandlerFromDir } from "winterspec/adapters/node"
import {
createFetchHandlerFromDir,
createWinterSpecBundleFromDir,
} from "winterspec/adapters/node"
import { Request as EdgeRuntimeRequest } from "@edge-runtime/primitives"
import type { Middleware } from "winterspec/middleware"
import { join } from "node:path"
import { ZodLevelDatabase } from "api/db/zod-level-db"
import os from "node:os"
import { Middleware } from "winterspec"

export const startServer = async ({ port }: { port: number }) => {
const db = new ZodLevelDatabase(os.tmpdir() + "/devdb")

const serverFetch = await createFetchHandlerFromDir(
const winterspecBundle = await createWinterSpecBundleFromDir(
join(import.meta.dir, "../../routes"),
{
middleware: [
async (req, ctx, next) => {
;(ctx as any).db = db
)

const middleware: Middleware[] = [
async (req: any, ctx: any, next: any) => {
;(ctx as any).db = db

return next(req, ctx)
},
],
return next(req, ctx)
},
)
]

return Bun.serve({
const server = Bun.serve({
fetch: (bunReq) => {
const req = new EdgeRuntimeRequest(bunReq.url, {
headers: bunReq.headers,
method: bunReq.method,
body: bunReq.body,
})
return serverFetch(req as any)
return winterspecBundle.makeRequest(req as any, {
middleware,
})
},
port,
})

return server
}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"semver": "^7.6.0",
"ts-morph": "^22.0.0",
"tsup": "^8.0.2",
"winterspec": "^0.0.85",
"winterspec": "0.0.86",
"zod": "^3.22.4"
},
"peerDependencies": {
Expand Down

0 comments on commit 11a4a69

Please sign in to comment.