Skip to content

Commit

Permalink
feat: initial revision for bun serve
Browse files Browse the repository at this point in the history
  • Loading branch information
barbmarcio committed Jul 23, 2024
1 parent ce16f32 commit a6b795a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PLAYWRIGHT_PORT=
SERVER_PORT=
2 changes: 1 addition & 1 deletion e2e/auctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
2 changes: 1 addition & 1 deletion e2e/constants.ts
Original file line number Diff line number Diff line change
@@ -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`,
}
17 changes: 17 additions & 0 deletions e2e/index.ts
Original file line number Diff line number Diff line change
@@ -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}`);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"allowJs": true,
"types": ["node"]
},
"include": ["src/*.ts", "src/**/*.ts"],
"include": ["src/*.ts", "src/**/*.ts", "e2e/server.ts"],
"exclude": ["node_modules"]
}

0 comments on commit a6b795a

Please sign in to comment.