Skip to content

Commit

Permalink
feat: adding bun serve and removing http-server
Browse files Browse the repository at this point in the history
  • Loading branch information
barbmarcio committed Jul 23, 2024
1 parent ee38a8d commit a74c48b
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 21 deletions.
Binary file modified bun.lockb
Binary file not shown.
8 changes: 4 additions & 4 deletions e2e/auctions.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, test } from "@playwright/test";
import { apis, baseURL } from "../src/constants/apis.constant";
import { playwrightConstants } from "./constants";
import { playwrightConstants } from "./config";

test.describe("Create Auction via Topsort SDK", () => {
test.only("should create an auction successfully", async ({ page }) => {
test("should create an auction successfully", async ({ page }) => {
const mockAPIResponse = {
results: [
{
Expand All @@ -23,7 +23,7 @@ test.describe("Create Auction via Topsort SDK", () => {
await route.fulfill({ json: mockAPIResponse });
});

await page.goto(playwrightConstants.url);
await page.goto(playwrightConstants.host);
const result = await page.evaluate(() => {
const config = {
apiKey: "rando-api-key",
Expand Down Expand Up @@ -59,7 +59,7 @@ test.describe("Create Auction via Topsort SDK", () => {

test("should fail to call with missing apiKey", async ({ page }) => {
const expectedError = { status: 401, statusText: "API Key is required.", body: {} };
await page.goto(playwrightConstants.url);
await page.goto(playwrightConstants.host);
const result = await page.evaluate(() => {
const config = {
apiKey: null,
Expand Down
3 changes: 3 additions & 0 deletions e2e/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const playwrightConstants = {
host: `http://localhost:${process.env.SERVER_PORT || 8080}/index.html`,
};
3 changes: 0 additions & 3 deletions e2e/constants.ts

This file was deleted.

6 changes: 3 additions & 3 deletions e2e/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "@playwright/test";
import { apis, baseURL } from "../src/constants/apis.constant";
import { playwrightConstants } from "./constants";
import { playwrightConstants } from "./config";

test.describe("Report Events via Topsort SDK", () => {
test("should report an successfully", async ({ page }) => {
Expand All @@ -12,7 +12,7 @@ test.describe("Report Events via Topsort SDK", () => {
await route.fulfill({ json: mockAPIResponse });
});

await page.goto(playwrightConstants.url);
await page.goto(playwrightConstants.host);
const result = await page.evaluate(() => {
const config = {
apiKey: "rando-api-key",
Expand Down Expand Up @@ -45,7 +45,7 @@ test.describe("Report Events via Topsort SDK", () => {

test("should fail to call with missing apiKey", async ({ page }) => {
const expectedError = { status: 401, statusText: "API Key is required.", body: {} };
await page.goto(playwrightConstants.url);
await page.goto(playwrightConstants.host);
const result = await page.evaluate(() => {
const config = {
apiKey: null,
Expand Down
18 changes: 10 additions & 8 deletions e2e/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import type { MatchedRoute } from "bun";
import { file } from "bun";

const PORT = process.env.SERVER_PORT || 8080;
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);
const url = new URL(req.url);
const pathname = url.pathname === "/" ? "/index.html" : url.pathname;
const filePath = `./dist${pathname}`;

try {
return new Response(file(filePath));
} catch (e) {
return new Response("Not Found", { status: 404 });
}
},
port: PORT,
});
Binary file added e2e/public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion e2e/index.html → e2e/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Topsort SDK Test Application</title>
<script src="../dist/index.global.js"></script>
<script src="./index.global.js"></script>
</head>
<body>
<h1>Test Topsort.js Integration</h1>
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"CHANGELOG.md",
"LICENSE",
"README.md",
"dist/index.global.js",
"dist/index.d.mts",
"dist/index.d.ts",
"dist/index.js",
Expand All @@ -43,7 +42,6 @@
"@biomejs/biome": "1.8.3",
"@playwright/test": "^1.45.2",
"@types/bun": "1.1.6",
"http-server": "^14.1.1",
"lefthook": "1.7.2",
"msw": "2.3.1",
"tsup": "8.1.0",
Expand Down
1 change: 1 addition & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export default defineConfig({
options.keepNames = true;
options.globalName = "Topsort";
},
onSuccess: "cp -r ./e2e/public/* dist",
});

0 comments on commit a74c48b

Please sign in to comment.