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/bun.lockb b/bun.lockb index 70f493a..500b13a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/e2e/auctions.test.ts b/e2e/auctions.test.ts index 07cb2c7..4c55b7d 100644 --- a/e2e/auctions.test.ts +++ b/e2e/auctions.test.ts @@ -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("Create Auction via Topsort SDK", () => { test("should create an auction successfully", async ({ page }) => { @@ -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", @@ -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, diff --git a/e2e/config.ts b/e2e/config.ts new file mode 100644 index 0000000..008e530 --- /dev/null +++ b/e2e/config.ts @@ -0,0 +1,3 @@ +export const playwrightConstants = { + host: `http://localhost:${process.env.SERVER_PORT || 8080}/index.html`, +}; diff --git a/e2e/constants.ts b/e2e/constants.ts deleted file mode 100644 index 2864308..0000000 --- a/e2e/constants.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const playwrightConstants = { - url: `http://localhost:${process.env.PLAYWRIGHT_PORT || 8080}/e2e`, -} \ No newline at end of file diff --git a/e2e/events.test.ts b/e2e/events.test.ts index 9b92682..57408e5 100644 --- a/e2e/events.test.ts +++ b/e2e/events.test.ts @@ -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 }) => { @@ -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", @@ -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, diff --git a/e2e/index.html b/e2e/public/index.html similarity index 93% rename from e2e/index.html rename to e2e/public/index.html index 9b1cedd..0165b8e 100644 --- a/e2e/index.html +++ b/e2e/public/index.html @@ -4,7 +4,7 @@ Topsort SDK Test Application - +

Test Topsort.js Integration

diff --git a/e2e/server.ts b/e2e/server.ts new file mode 100644 index 0000000..d9a8a45 --- /dev/null +++ b/e2e/server.ts @@ -0,0 +1,22 @@ +import { file } from "bun"; + +const PORT = process.env.SERVER_PORT || 8080; + +Bun.serve({ + fetch(req) { + const url = new URL(req.url); + const pathname = url.pathname === "/" ? "/index.html" : url.pathname; + const filePath = `./dist${pathname}`; + + try { + if (filePath.endsWith(".ico")) { + return new Response("", { status: 204 }); + } + + return new Response(file(filePath)); + } catch (e) { + return new Response("Not Found", { status: 404 }); + } + }, + port: PORT, +}); diff --git a/package.json b/package.json index 926bd26..214358f 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "CHANGELOG.md", "LICENSE", "README.md", - "dist/index.global.js", "dist/index.d.mts", "dist/index.d.ts", "dist/index.js", @@ -36,13 +35,13 @@ "test:e2e": "playwright test", "format": "biome check", "format:fix": "biome check --write", - "prepare": "lefthook install" + "prepare": "lefthook install", + "serve:e2e": "bun run ./e2e/server.ts" }, "devDependencies": { "@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", diff --git a/playwright.config.ts b/playwright.config.ts index 94b2487..b7af23b 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:e2e", 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"] } diff --git a/tsup.config.ts b/tsup.config.ts index a51cc34..49225ea 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -10,4 +10,5 @@ export default defineConfig({ options.keepNames = true; options.globalName = "Topsort"; }, + onSuccess: "cp -r ./e2e/public/* dist", });