Skip to content

Commit 28c68fb

Browse files
committed
test(playwright): fix base path issue in project-bootstrap test
1 parent 9c88dd4 commit 28c68fb

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

playwright.config.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
import { defineConfig } from "@playwright/test";
22
import path from "node:path";
33

4-
const { BASE_URL, BASE_PATH = "" } = process.env;
5-
64
require("dotenv").config({ path: path.resolve(process.cwd(), ".env.test.local") });
75

6+
const baseURL = new URL(process.env.BASE_URL as string);
7+
baseURL.pathname = process.env.BASE_PATH ?? "/";
8+
89
export default defineConfig({
910
projects: [
1011
{ name: "setup", testMatch: "**/*.setup.ts" },
1112
{
1213
name: "browser",
1314
dependencies: ["setup"],
14-
use: { storageState: "storageState.json" },
15+
use: {
16+
storageState: "storageState.json",
17+
baseURL: baseURL.href,
18+
screenshot: "on",
19+
trace: "on-first-retry",
20+
},
1521
retries: 3,
1622
timeout: 60000,
1723
testMatch: "**/*.browser.ts",
1824
},
1925
{ name: "node", testMatch: "**/*.node.ts" },
2026
],
2127
use: {
22-
baseURL: BASE_URL + BASE_PATH,
28+
baseURL: baseURL.href,
2329
screenshot: "on",
2430
trace: "on-first-retry", // record traces on first retry of each test
2531
},
2632
webServer: {
2733
command: `pnpm start`,
28-
port: 3000,
34+
url: baseURL.href,
2935
timeout: 200 * 1000,
3036
env: {
3137
NODE_ENV: "test",

tests/project-bootstrap.browser.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import type {
77

88
import { expect, test } from "@playwright/test";
99

10+
const baseURL = new URL(process.env.BASE_URL as string);
11+
baseURL.pathname = process.env.BASE_PATH ?? "/";
12+
1013
test("Project bootstrap works", async ({ page, baseURL }) => {
1114
// Display any logs to terminal (for debug)
1215
page.on("console", async (msg) => {
@@ -20,20 +23,23 @@ test("Project bootstrap works", async ({ page, baseURL }) => {
2023
expect(baseURL).toBeDefined();
2124

2225
const url = new URL(baseURL as string);
23-
url.pathname = "/api/as-api/organisation/default";
26+
const basePath = url.pathname;
27+
28+
url.pathname = basePath + "/api/as-api/organisation/default";
29+
2430
const defaultOrg: OrganisationGetDefaultResponse = await (
25-
await page.request.get(url.href)
31+
await page.request.get(new URL(url).href)
2632
).json();
2733

2834
// Ensure default unit and associated projects and products doesn't exist
29-
url.pathname = `/api/as-api/organisation/${defaultOrg.id}/unit`;
35+
url.pathname = basePath + `/api/as-api/organisation/${defaultOrg.id}/unit`;
3036
const units = ((await (await page.request.get(url.href)).json()) as OrganisationUnitsGetResponse)
3137
.units;
3238

3339
const personalUnit = units.find((unit) => unit.name === process.env.PW_USERNAME);
3440

3541
if (personalUnit) {
36-
url.pathname = "/api/as-api/product";
42+
url.pathname = basePath + "/api/as-api/product";
3743
const products = ((await (await page.request.get(url.href)).json()) as ProductsGetResponse)
3844
.products;
3945

@@ -44,14 +50,14 @@ test("Project bootstrap works", async ({ page, baseURL }) => {
4450
product.product.type === "DATA_MANAGER_PROJECT_TIER_SUBSCRIPTION",
4551
);
4652
const productPromises = productsToDelete.map(async (product) => {
47-
url.pathname = `/api/dm-api/project/${product.claim?.id}`;
53+
url.pathname = basePath + `/api/dm-api/project/${product.claim?.id}`;
4854
page.request.delete(url.href);
49-
url.pathname = `/api/as-api/product/${product.product.id}`;
55+
url.pathname = basePath + `/api/as-api/product/${product.product.id}`;
5056
page.request.delete(url.href);
5157
});
5258
await Promise.allSettled(productPromises);
5359

54-
url.pathname = "/api/as-api/unit";
60+
url.pathname = basePath + "/api/as-api/unit";
5561
const res = await page.request.delete(url.href);
5662

5763
const response = await res.json();

0 commit comments

Comments
 (0)