From ce16f32cc5c70c78917b141667d4f6deabc258ba Mon Sep 17 00:00:00 2001 From: barbmarcio Date: Fri, 19 Jul 2024 20:20:23 +0100 Subject: [PATCH] feat: adding playwright port to env file --- .env.example | 1 + .gitignore | 2 ++ CONTRIBUTING.md | 4 ++++ e2e/auctions.test.ts | 5 +++-- e2e/constants.ts | 3 +++ e2e/events.test.ts | 5 +++-- playwright.config.ts | 2 +- 7 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 .env.example create mode 100644 e2e/constants.ts diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f7baccf --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +PLAYWRIGHT_PORT= diff --git a/.gitignore b/.gitignore index aace4f7..64b0d86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.env + coverage/ dist/ node_modules/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3925749..8b5b61d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -97,6 +97,7 @@ bun run test ### E2E Tests +By default, the application is set to serve a web browser in the port `8080` for Playwright. If this port is already being used on your local machine, make sure you change the port in your `.env`.`PLAYWRIGHT_PORT`. To run the end-to-end tests, make sure you have latest bundled file before running it. Use the following commands: ```bash @@ -137,5 +138,8 @@ The SDK uses following configuration files: - `tsup.config.ts`: Configuration for the TSUP bundler. - `playwright.config.ts`: Configuration for E2E tests runner +We also have the following variables as part of the `.env` file: +- `PLAYWRIGHT_PORT`: Port used to run the local web browser to run Playwright E2E tests. + ## License This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details. diff --git a/e2e/auctions.test.ts b/e2e/auctions.test.ts index 63b963f..07cb2c7 100644 --- a/e2e/auctions.test.ts +++ b/e2e/auctions.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "@playwright/test"; 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 }) => { @@ -22,7 +23,7 @@ test.describe("Create Auction via Topsort SDK", () => { await route.fulfill({ json: mockAPIResponse }); }); - await page.goto("http://localhost:8080/e2e"); + await page.goto(playwrightConstants.url); const result = await page.evaluate(() => { const config = { apiKey: "rando-api-key", @@ -58,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("http://localhost:8080/e2e"); + await page.goto(playwrightConstants.url); const result = await page.evaluate(() => { const config = { apiKey: null, diff --git a/e2e/constants.ts b/e2e/constants.ts new file mode 100644 index 0000000..2864308 --- /dev/null +++ b/e2e/constants.ts @@ -0,0 +1,3 @@ +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 400223c..9b92682 100644 --- a/e2e/events.test.ts +++ b/e2e/events.test.ts @@ -1,5 +1,6 @@ import { expect, test } from "@playwright/test"; import { apis, baseURL } from "../src/constants/apis.constant"; +import { playwrightConstants } from "./constants"; test.describe("Report Events via Topsort SDK", () => { test("should report an successfully", async ({ page }) => { @@ -11,7 +12,7 @@ test.describe("Report Events via Topsort SDK", () => { await route.fulfill({ json: mockAPIResponse }); }); - await page.goto("http://localhost:8080/e2e"); + await page.goto(playwrightConstants.url); const result = await page.evaluate(() => { const config = { apiKey: "rando-api-key", @@ -44,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("http://localhost:8080/e2e"); + await page.goto(playwrightConstants.url); const result = await page.evaluate(() => { const config = { apiKey: null, diff --git a/playwright.config.ts b/playwright.config.ts index 352e5e8..94b2487 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -23,7 +23,7 @@ export default defineConfig({ }, ], webServer: { - command: "http-server ./ -p 8080", + command: `http-server ./ -p ${process.env.PLAYWRIGHT_PORT || 8080}`, reuseExistingServer: !process.env.CI, stdout: "ignore", stderr: "pipe",