Some checks failed
Release / release (push) Failing after 1m27s
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { test as base, expect, type Page } from '@playwright/test';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
function getBaseURL(): string {
|
|
const envFile = path.resolve(__dirname, '../../../data/test/.env');
|
|
if (fs.existsSync(envFile)) {
|
|
for (const line of fs.readFileSync(envFile, 'utf-8').split('\n')) {
|
|
if (line.startsWith('TT_BASE_URL=')) return line.slice('TT_BASE_URL='.length).trim();
|
|
}
|
|
}
|
|
return process.env.TT_BASE_URL ?? 'http://127.0.0.1:3000';
|
|
}
|
|
|
|
// Extends base test with a beforeEach that resets DB to clean seed state
|
|
export const test = base.extend<{ page: Page }>({
|
|
page: async ({ page }, use) => {
|
|
const baseURL = getBaseURL();
|
|
const res = await page.request.post(`${baseURL}/__test__/reset`);
|
|
if (!res.ok()) throw new Error(`DB reset failed: ${res.status()}`);
|
|
await use(page);
|
|
},
|
|
});
|
|
|
|
export { expect };
|