Skip to content

Commit

Permalink
feat: adding playwright port to env file
Browse files Browse the repository at this point in the history
  • Loading branch information
barbmarcio committed Jul 19, 2024
1 parent c5d63eb commit ce16f32
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PLAYWRIGHT_PORT=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.env

coverage/
dist/
node_modules/
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
5 changes: 3 additions & 2 deletions e2e/auctions.test.ts
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions e2e/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const playwrightConstants = {
url: `http://localhost:${process.env.PLAYWRIGHT_PORT || 8080}/e2e`,
}
5 changes: 3 additions & 2 deletions e2e/events.test.ts
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ce16f32

Please sign in to comment.