More data in backend fixture

This commit is contained in:
Kuba Orlik 2025-08-05 16:21:18 +02:00
parent eb4fc98903
commit 36dbe94113
4 changed files with 22 additions and 20 deletions

View File

@ -1,7 +1,7 @@
import { test, expect } from "./backend-fixture.js"; import { test, expect } from "./backend-fixture.js";
test.beforeEach(async ({ page, backendUrl }) => { test.beforeEach(async ({ page, backend }) => {
await page.goto(backendUrl); await page.goto(backend.url);
await page.getByRole("link", { name: "Go to Admin" }).click(); await page.getByRole("link", { name: "Go to Admin" }).click();
await page.getByPlaceholder("text").click(); await page.getByPlaceholder("text").click();
await page.getByPlaceholder("text").fill("admin"); await page.getByPlaceholder("text").fill("admin");
@ -21,7 +21,7 @@ test("Basic flow of adding a navbar link", async ({ page }) => {
await expect(page).toHaveScreenshot(); await expect(page).toHaveScreenshot();
}); });
test("Basic flow of creating a page", async ({ page, backendUrl }) => { test("Basic flow of creating a page", async ({ page, backend }) => {
await page.getByRole("link", { name: "Edit Pages" }).click(); await page.getByRole("link", { name: "Edit Pages" }).click();
await page.getByRole("link", { name: "Create" }).click(); await page.getByRole("link", { name: "Create" }).click();
await page.getByLabel("url").click(); await page.getByLabel("url").click();
@ -30,6 +30,6 @@ test("Basic flow of creating a page", async ({ page, backendUrl }) => {
await page.getByLabel("heading").fill("My Heading"); await page.getByLabel("heading").fill("My Heading");
await page.getByLabel("description").fill("My Description"); await page.getByLabel("description").fill("My Description");
await page.getByRole("button", { name: "Wyślij" }).click(); await page.getByRole("button", { name: "Wyślij" }).click();
await page.goto(`${backendUrl}/my-page/`); await page.goto(`${backend.url}/my-page/`);
await expect(page).toHaveScreenshot(); await expect(page).toHaveScreenshot();
}); });

View File

@ -10,7 +10,7 @@ import { MongoClient } from "mongodb";
import { MONGO_PORT, MONGO_HOST } from "../src/back/config.js"; import { MONGO_PORT, MONGO_HOST } from "../src/back/config.js";
type TestFixtures = { type TestFixtures = {
backendUrl: string; backend: { url: string; env: Record<string, string> };
setMarkdownValue: (field_name: string, value: string) => Promise<void>; setMarkdownValue: (field_name: string, value: string) => Promise<void>;
}; };
@ -81,7 +81,7 @@ async function dropMongoDB(mongo_db_name: string) {
} }
export const test = base.extend<TestFixtures>({ export const test = base.extend<TestFixtures>({
backendUrl: async ({}, use, { file, titlePath }) => { backend: async ({}, use, { file, titlePath }) => {
const port = await getPort(); const port = await getPort();
const mongo_db_name = `test-app-${uuid()}`; const mongo_db_name = `test-app-${uuid()}`;
const killswitch_port = await getPort(); const killswitch_port = await getPort();
@ -93,6 +93,16 @@ export const test = base.extend<TestFixtures>({
await fs.mkdir(coverage_temp_dir, { await fs.mkdir(coverage_temp_dir, {
recursive: true, recursive: true,
}); });
const env = {
...process.env,
SEALIOUS_PORT: `${port}`,
SEALIOUS_MONGO_DB_NAME: mongo_db_name,
...(process.env.TESTS_RUN_IN_DOCKER
? { MEILISEARCH_HOST: `http://meilisearch:7700` }
: {}),
SEALIOUS_KILLSWITCH_PORT: `${killswitch_port}`,
};
const backendProcess = spawn( const backendProcess = spawn(
c8, c8,
[ [
@ -107,15 +117,7 @@ export const test = base.extend<TestFixtures>({
"dist/back/index.js", "dist/back/index.js",
], ],
{ {
env: { env,
...process.env,
SEALIOUS_PORT: `${port}`,
SEALIOUS_MONGO_DB_NAME: mongo_db_name,
...(process.env.TESTS_RUN_IN_DOCKER
? { MEILISEARCH_HOST: `http://meilisearch:7700` }
: {}),
SEALIOUS_KILLSWITCH_PORT: `${killswitch_port}`,
},
stdio: "inherit", stdio: "inherit",
} }
); );
@ -141,7 +143,7 @@ export const test = base.extend<TestFixtures>({
}); });
await waitForHttpPort({ port, timeout: 10000 }); await waitForHttpPort({ port, timeout: 10000 });
await use(`http://${app_host}:${port}`); await use({ url: `http://${app_host}:${port}`, env });
triggerKillswitch(killswitch_port); triggerKillswitch(killswitch_port);
await onEndPromise; await onEndPromise;
}, },

View File

@ -1,7 +1,7 @@
import { test, expect } from "./backend-fixture"; import { test, expect } from "./backend-fixture";
test("test", async ({ page, backendUrl }) => { test("test", async ({ page, backend }) => {
await page.goto(`${backendUrl}/dev/simple-crud-test/`); await page.goto(`${backend.url}/dev/simple-crud-test/`);
await expect(page).toHaveScreenshot(); await expect(page).toHaveScreenshot();
await page.getByRole("link", { name: "Create" }).click(); await page.getByRole("link", { name: "Create" }).click();
await expect(page).toHaveScreenshot(); await expect(page).toHaveScreenshot();

View File

@ -1,8 +1,8 @@
import { test, expect } from "./backend-fixture.js"; import { test, expect } from "./backend-fixture.js";
import { setTimeout as sleep } from "node:timers/promises"; import { setTimeout as sleep } from "node:timers/promises";
test("Tekst component", async ({ page, backendUrl, setMarkdownValue }) => { test("Tekst component", async ({ page, backend, setMarkdownValue }) => {
await page.goto(`${backendUrl}/components`); await page.goto(`${backend.url}/components`);
await page.waitForFunction(() => typeof (window as any).CodeMirror !== "undefined"); await page.waitForFunction(() => typeof (window as any).CodeMirror !== "undefined");
await sleep(5000); await sleep(5000);
await page.locator('select[name="component"]').selectOption("tekst"); await page.locator('select[name="component"]').selectOption("tekst");