From a6b795ae3690ad97b396950964d6a44eeb768ebd Mon Sep 17 00:00:00 2001 From: barbmarcio Date: Tue, 23 Jul 2024 10:01:48 +0100 Subject: [PATCH] feat: initial revision for bun serve --- .env.example | 2 +- e2e/auctions.test.ts | 2 +- e2e/constants.ts | 2 +- e2e/index.ts | 17 +++++++++++++++++ package.json | 3 ++- playwright.config.ts | 4 ++-- tsconfig.json | 2 +- 7 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 e2e/index.ts diff --git a/.env.example b/.env.example index f7baccf..9b47526 100644 --- a/.env.example +++ b/.env.example @@ -1 +1 @@ -PLAYWRIGHT_PORT= +SERVER_PORT= diff --git a/e2e/auctions.test.ts b/e2e/auctions.test.ts index 07cb2c7..6affa87 100644 --- a/e2e/auctions.test.ts +++ b/e2e/auctions.test.ts @@ -3,7 +3,7 @@ import { apis, baseURL } from "../src/constants/apis.constant"; import { playwrightConstants } from "./constants"; test.describe("Create Auction via Topsort SDK", () => { - test("should create an auction successfully", async ({ page }) => { + test.only("should create an auction successfully", async ({ page }) => { const mockAPIResponse = { results: [ { diff --git a/e2e/constants.ts b/e2e/constants.ts index 2864308..8493b92 100644 --- a/e2e/constants.ts +++ b/e2e/constants.ts @@ -1,3 +1,3 @@ export const playwrightConstants = { - url: `http://localhost:${process.env.PLAYWRIGHT_PORT || 8080}/e2e`, + url: `http://localhost:${process.env.SERVER_PORT || 8080}/e2e`, } \ No newline at end of file diff --git a/e2e/index.ts b/e2e/index.ts new file mode 100644 index 0000000..aa0118c --- /dev/null +++ b/e2e/index.ts @@ -0,0 +1,17 @@ +import type { MatchedRoute } from "bun"; + +const router = new Bun.FileSystemRouter({ + style: "nextjs", + dir: "./dist/", +}); + +Bun.serve({ + fetch(req) { + const match = router.match(req) as MatchedRoute + const page = require(match.filePath); + return new (page)(req, match.query, match.params); + }, + port: process.env.SERVER_PORT || 8080, +}) + +console.log(`Server running at http://localhost:${process.env.SERVER_PORT || 8080}`); \ No newline at end of file diff --git a/package.json b/package.json index 926bd26..78c80a1 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "test:e2e": "playwright test", "format": "biome check", "format:fix": "biome check --write", - "prepare": "lefthook install" + "prepare": "lefthook install", + "serve": "bun run ./e2e/index.ts" }, "devDependencies": { "@biomejs/biome": "1.8.3", diff --git a/playwright.config.ts b/playwright.config.ts index 94b2487..fc60b09 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -3,7 +3,7 @@ import { defineConfig, devices } from "@playwright/test"; export default defineConfig({ testDir: "./e2e", timeout: 30000, - retries: 1, + retries: 0, reporter: [["list"], ["json", { outputFile: "test-results.json" }]], use: { trace: "on-first-retry", @@ -23,7 +23,7 @@ export default defineConfig({ }, ], webServer: { - command: `http-server ./ -p ${process.env.PLAYWRIGHT_PORT || 8080}`, + command: "bun run serve", reuseExistingServer: !process.env.CI, stdout: "ignore", stderr: "pipe", diff --git a/tsconfig.json b/tsconfig.json index 4eb4110..531c5f2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,6 @@ "allowJs": true, "types": ["node"] }, - "include": ["src/*.ts", "src/**/*.ts"], + "include": ["src/*.ts", "src/**/*.ts", "e2e/server.ts"], "exclude": ["node_modules"] }