1b24bb2157
- Added functions for creating, updating, deleting, and listing collection entries in admin API. - Introduced seed data management for consistent test content across tests. - Updated global setup and teardown processes to ensure seeded content is created and cleaned up. - Refactored existing tests to utilize seeded content for improved reliability and maintainability.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { request } from "@playwright/test"
|
|
import { ensureSeededTestContent } from "./api/helpers/seed-data"
|
|
import { TEST_BASE_URL } from "./fixtures/test-constants"
|
|
|
|
async function globalSetup() {
|
|
const baseURL = TEST_BASE_URL
|
|
|
|
const ctx = await request.newContext({
|
|
baseURL,
|
|
ignoreHTTPSErrors: true,
|
|
extraHTTPHeaders: {
|
|
"User-Agent": "Playwright",
|
|
},
|
|
})
|
|
|
|
try {
|
|
const res = await ctx.get("/")
|
|
if (!res.ok()) {
|
|
throw new Error(`Dev environment at ${baseURL} returned ${res.status()}`)
|
|
} else {
|
|
console.log(`Playwright setup: dev environment reachable at ${baseURL}`)
|
|
}
|
|
|
|
const apiProbe = await ctx.get("/api/content?limit=1")
|
|
const contentType = apiProbe.headers()["content-type"] || ""
|
|
if (!apiProbe.ok() || contentType.includes("text/html")) {
|
|
throw new Error(
|
|
`Playwright seed setup needs a base URL with working /api access. Current base URL ${baseURL} returned ${apiProbe.status()} ${contentType || "without content-type"} for /api/content.`
|
|
)
|
|
}
|
|
|
|
const result = await ensureSeededTestContent(baseURL)
|
|
console.log(
|
|
`Playwright setup: seeded deterministic content (deleted ${result.deleted}, created ${result.created})`
|
|
)
|
|
} finally {
|
|
await ctx.dispose()
|
|
}
|
|
}
|
|
|
|
export default globalSetup
|