From 2da83796d23fe0e85ef344c6300f50e63fa378e4 Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Wed, 18 Dec 2024 16:01:59 -1000 Subject: [PATCH] test: create storage state file on start --- playwright.config.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/playwright.config.ts b/playwright.config.ts index 0c7a188..347fe04 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -2,12 +2,15 @@ import { defineConfig, devices } from "@playwright/test"; import dotenv from "dotenv"; import assert from "node:assert"; import { fileURLToPath } from "node:url"; +import { existsSync, writeFileSync } from "node:fs"; dotenv.config({ path: ".env.test.local" }); export const STORAGE_STATE = fileURLToPath( new URL("./tests/.storage-state.json", import.meta.url), ); +if (!existsSync(STORAGE_STATE)) + writeFileSync(STORAGE_STATE, JSON.stringify({})); // https://playwright.dev/docs/test-configuration export default defineConfig({ @@ -20,12 +23,14 @@ export default defineConfig({ reporter: "html", use: { trace: "on-first-retry", - storageState: STORAGE_STATE, }, projects: [ { name: "Setup", testMatch: "*.setup.*", + use: { + storageState: STORAGE_STATE, + }, }, { name: "App Router", @@ -33,6 +38,7 @@ export default defineConfig({ use: { ...devices["Desktop Chrome"], baseURL: "http://localhost:4321", + storageState: STORAGE_STATE, }, }, { @@ -41,6 +47,7 @@ export default defineConfig({ use: { ...devices["Desktop Chrome"], baseURL: "http://localhost:4322", + storageState: STORAGE_STATE, }, }, ],