From ec537bd7caf3dfdf4eb11759d672216fc98c277a Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Wed, 18 Dec 2024 20:04:13 -1000 Subject: [PATCH] test: add teardown --- playwright.config.ts | 8 ++++++++ tests/global.teardown.ts | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/global.teardown.ts diff --git a/playwright.config.ts b/playwright.config.ts index 5aed4a1..c9ae9a8 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -28,6 +28,7 @@ export default defineConfig({ { name: "Setup", testMatch: "*.setup.*", + teardown: "Teardown", use: { storageState: STORAGE_STATE, }, @@ -50,6 +51,13 @@ export default defineConfig({ storageState: STORAGE_STATE, }, }, + { + name: "Teardown", + testMatch: "*.teardown.*", + use: { + storageState: STORAGE_STATE, + }, + }, ], webServer: [ { diff --git a/tests/global.teardown.ts b/tests/global.teardown.ts new file mode 100644 index 0000000..8f25b35 --- /dev/null +++ b/tests/global.teardown.ts @@ -0,0 +1,12 @@ +import { STORAGE_STATE } from "../playwright.config"; +import { test as teardown } from "./test"; + +teardown("delete repo", async ({ page, prismic }) => { + const cookies = await page.context().cookies(); + const repoName = cookies.find((c) => c.name === "repository-name")?.value; + if (!repoName) return; + const repo = prismic.getRepo(repoName); + await repo.delete(); + await page.context().clearCookies({ name: "repository-name" }); + await page.context().storageState({ path: STORAGE_STATE }); +});