/** * Global setup — runs once before all test projects (chromium, firefox, webkit). * * Steps: * 1. Log in as admin via the DocAdenice API. * 2. Persist the auth state to .auth/admin.json so all projects reuse it. * 3. Seed Baserow (workspace + database + table + views + rows). * 4. Write the seed IDs to .auth/baserow-seed.json so individual tests can read them. */ import { test as setup } from "@playwright/test"; import * as path from "path"; import * as fs from "fs"; import { adminCredentials, loginViaApi, saveAuthState, } from "../fixtures/auth"; import { seedBaserow } from "../fixtures/baserow"; const AUTH_DIR = path.resolve(__dirname, "../.auth"); const ADMIN_AUTH_FILE = path.join(AUTH_DIR, "admin.json"); const BASEROW_SEED_FILE = path.join(AUTH_DIR, "baserow-seed.json"); setup("authenticate admin + seed baserow", async ({ request }) => { // Ensure .auth directory exists. if (!fs.existsSync(AUTH_DIR)) { fs.mkdirSync(AUTH_DIR, { recursive: true }); } // Step 1: Login. const adminToken = await loginViaApi(request, adminCredentials); // Step 2: Persist auth state. await saveAuthState(adminToken, ADMIN_AUTH_FILE); console.log("[setup] Admin auth state saved."); // Step 3: Seed Baserow. const seed = await seedBaserow(request); console.log( `[setup] Baserow seeded: table=${seed.tableId} gridView=${seed.gridViewId} rows=${seed.rowIds.length}`, ); // Step 4: Persist seed for tests. fs.writeFileSync(BASEROW_SEED_FILE, JSON.stringify(seed, null, 2)); console.log("[setup] Baserow seed written to", BASEROW_SEED_FILE); });