diff --git a/tests/fixtures.ts b/tests/fixtures.ts index 2c5e3abf3..e9d5d83a2 100644 --- a/tests/fixtures.ts +++ b/tests/fixtures.ts @@ -2,18 +2,49 @@ import { test as base } from '@playwright/test'; import { DockerComposeEnvironment, type StartedDockerComposeEnvironment } from 'testcontainers'; interface MyFixtures { - environment: StartedDockerComposeEnvironment; + // environment: DockerComposeEnvironment; + // containers: StartedDockerComposeEnvironment; + + sut: SystemUnderTest; } -export const test = base.extend, MyFixtures>({ - environment: [ - async ({}, use, workerInfo) => { - const environment = await new DockerComposeEnvironment('.', 'docker-compose.yml').up(); - await use(environment); - await environment.down(); - }, - { scope: 'worker' }, - ], +export class SystemUnderTest { + private readonly _environment = new DockerComposeEnvironment('.', 'docker-compose.yml'); + private _containers?: StartedDockerComposeEnvironment; + + public async setUp(): Promise { + this._containers = await this._environment.up(); + } + + public async tearDown(): Promise { + await this._containers?.down(); + } + + public get appUrl(): string { + const container = this._containers?.getContainer('web-1'); + return `https://${container?.getHost()}:${container?.getFirstMappedPort()}`; + } +} + +const sut = new SystemUnderTest(); + +// export const test = base.extend, MyFixtures>({ +// sut: [ +// async ({}, use, workerInfo) => { +// // const environment = new DockerComposeEnvironment('.', 'docker-compose.yml'); + +// // const containers = await environment.up(); +// await use(sut); +// // await containers.down(); +// }, +// { scope: 'worker' }, +// ], +// }); + +export const test = base.extend({ + sut: async ({}, use) => { + await use(sut); + }, }); export { expect } from '@playwright/test'; diff --git a/tests/playwright.config.ts b/tests/playwright.config.ts index 7e0c51708..15c1de490 100644 --- a/tests/playwright.config.ts +++ b/tests/playwright.config.ts @@ -42,15 +42,15 @@ export default defineConfig({ use: { ...devices['Desktop Chrome'] }, }, - // { - // name: 'firefox', - // use: { ...devices['Desktop Firefox'] }, - // }, + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, - // { - // name: 'webkit', - // use: { ...devices['Desktop Safari'] }, - // }, + { + name: 'webkit', + use: { ...devices['Desktop Safari'] }, + }, /* Test against mobile viewports. */ // { diff --git a/tests/scenarios/main.spec.ts b/tests/scenarios/main.spec.ts index 769fcfe8d..b0a1a47fe 100644 --- a/tests/scenarios/main.spec.ts +++ b/tests/scenarios/main.spec.ts @@ -1,11 +1,16 @@ import { expect } from '@playwright/test'; import { test } from '../fixtures'; -test('should display sign in page', async ({ page, environment }) => { - const container = environment.getContainer('web-1'); - const url = `https://${container.getHost()}:${container.getFirstMappedPort()}`; +test.beforeAll(async ({ sut }) => { + await sut.setUp(); +}); + +test.afterAll(async ({ sut }) => { + await sut.tearDown(); +}); - await page.goto(url); +test('should display sign in page', async ({ page, sut }) => { + await page.goto(sut.appUrl); await expect(page.getByRole('button', { name: /sign in with google/i })).toBeVisible(); });