import { statSync } from 'node:fs'; import { expect, Locator, Page, test as base } from '@playwright/test'; export const test = base.extend<{ admin: void }>({ admin: [ async ({ page }, use) => { const signed = await page.request.post('/api/auth/login', { form: { username: 'admin@isssteleon.mx', password: 'solo-para-pruebas' }, }); expect(signed.status()).toBe(204); await use(); }, { auto: true }, ], }); export function watch(page: Page): string[] { const problems: string[] = []; page.on('console', (m) => m.type() === 'error' && problems.push(`console: ${m.text()}`)); page.on('response', (r) => r.status() >= 400 && problems.push(`${r.status()} ${r.url()}`)); page.on('pageerror', (e) => problems.push(`page: ${e.message}`)); return problems; } export async function downloaded( page: Page, button: Locator, kind: 'pdf' | 'xlsx', ): Promise { const [file] = await Promise.all([page.waitForEvent('download'), button.click()]); const name = file.suggestedFilename(); expect(name).toMatch(new RegExp(`^tea-[a-z]+-\\d{4}-\\d{2}-\\d{2}\\.${kind}$`)); expect(name).not.toMatch(/N-?\d{4}/); expect(statSync(await file.path()).size).toBeGreaterThan(0); return name; }