61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
/**
|
|
* 게시판 모듈 Playwright E2E 설정.
|
|
*
|
|
* 코어/이커머스 config 와 동일한 base URL 해석 우선순위. 모듈 디렉토리 기준 6단계 상위가 코어 루트.
|
|
*
|
|
* 실행 예시:
|
|
* PowerShell — $env:PLAYWRIGHT_BASE_URL='https://g7.dev'; npx playwright test --config modules/_bundled/sirsoft-board/tests/Playwright/playwright.config.ts
|
|
* Bash — PLAYWRIGHT_BASE_URL=https://g7.dev npx playwright test --config modules/_bundled/sirsoft-board/tests/Playwright/playwright.config.ts
|
|
*/
|
|
import { defineConfig, devices } from '@playwright/test';
|
|
import { readFileSync, existsSync } from 'node:fs';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
function readEnvFile(filePath: string, key: string): string | null {
|
|
if (!existsSync(filePath)) return null;
|
|
const content = readFileSync(filePath, { encoding: 'utf-8' });
|
|
const pattern = new RegExp(`^${key}=(.*)$`, 'm');
|
|
const match = content.match(pattern);
|
|
if (!match) return null;
|
|
let value = match[1].trim();
|
|
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
value = value.slice(1, -1);
|
|
}
|
|
return value || null;
|
|
}
|
|
|
|
function resolveBaseUrl(): string {
|
|
if (process.env.PLAYWRIGHT_BASE_URL) {
|
|
return process.env.PLAYWRIGHT_BASE_URL;
|
|
}
|
|
const coreRoot = process.env.G7_ROOT || resolve(__dirname, '../../../../../');
|
|
const appUrl = readEnvFile(resolve(coreRoot, '.env'), 'APP_URL');
|
|
if (appUrl && !/^https?:\/\/localhost(:\d+)?\/?$/i.test(appUrl)) {
|
|
return appUrl;
|
|
}
|
|
throw new Error(
|
|
'게시판 모듈 E2E base URL 미설정. PLAYWRIGHT_BASE_URL 환경변수를 지정하거나 코어 .env 의 APP_URL 을 활성 호스트로 설정하세요.'
|
|
);
|
|
}
|
|
|
|
export default defineConfig({
|
|
testDir: './specs',
|
|
fullyParallel: true,
|
|
forbidOnly: !!process.env.CI,
|
|
retries: process.env.CI ? 2 : 0,
|
|
workers: process.env.CI ? 1 : undefined,
|
|
reporter: [
|
|
['html', { outputFolder: 'playwright-report', open: 'never' }],
|
|
['list'],
|
|
],
|
|
use: {
|
|
baseURL: resolveBaseUrl(),
|
|
trace: 'retain-on-failure',
|
|
screenshot: 'only-on-failure',
|
|
ignoreHTTPSErrors: true,
|
|
},
|
|
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
|
|
}); |