fix(e2e): use ESM imports instead of require() for fs module
The project uses ESM ("type": "module"), so require("fs") was failing.
Switch to import { fs } from "fs" at the top of the file.
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { test as base, Page, Browser, BrowserContext } from "@playwright/test";
|
import { test as base, Page, Browser, BrowserContext } from "@playwright/test";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
const STAFF_STORAGE = path.join(process.cwd(), ".auth/staff.json");
|
const STAFF_STORAGE = path.join(process.cwd(), ".auth/staff.json");
|
||||||
const CLIENT_STORAGE = path.join(process.cwd(), ".auth/client.json");
|
const CLIENT_STORAGE = path.join(process.cwd(), ".auth/client.json");
|
||||||
@@ -65,14 +66,14 @@ async function getStorageState(browser: Browser, userType: UserType): Promise<st
|
|||||||
const filePath = userType === "staff" ? STAFF_STORAGE : CLIENT_STORAGE;
|
const filePath = userType === "staff" ? STAFF_STORAGE : CLIENT_STORAGE;
|
||||||
const dir = path.dirname(filePath);
|
const dir = path.dirname(filePath);
|
||||||
|
|
||||||
if (!require("fs").existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
const state =
|
const state =
|
||||||
userType === "staff"
|
userType === "staff"
|
||||||
? await authenticateStaff(browser)
|
? await authenticateStaff(browser)
|
||||||
: await authenticateClient(browser);
|
: await authenticateClient(browser);
|
||||||
|
|
||||||
require("fs").mkdirSync(dir, { recursive: true });
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
require("fs").writeFileSync(filePath, state);
|
fs.writeFileSync(filePath, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
return filePath;
|
return filePath;
|
||||||
|
|||||||
Reference in New Issue
Block a user