Reference files in Playwright more reliably (#32935)

Without assuming the cwd
This commit is contained in:
Michael Telatynski
2026-03-26 11:30:54 +00:00
committed by GitHub
parent 5a074e637a
commit cd429874db
14 changed files with 93 additions and 57 deletions
@@ -6,9 +6,9 @@ Please see LICENSE files in the repository root for full details.
*/
import { type Page } from "@playwright/test";
import fs from "node:fs";
import { test, expect } from "../../element-web-test";
import { getSampleFilePath, readSampleFileSync } from "../../sample-files";
const screenshotOptions = (page: Page) => ({
// Hide the jump to bottom button in the timeline to avoid flakiness
@@ -26,7 +26,7 @@ const screenshotOptions = (page: Page) => ({
`,
});
const IMAGE_FILE = fs.readFileSync("playwright/sample-files/element.png");
const IMAGE_FILE = readSampleFileSync("element.png", null);
test.describe("Custom Component API", () => {
test.use({
@@ -36,7 +36,7 @@ test.describe("Custom Component API", () => {
},
page: async ({ page }, use) => {
await page.route("/modules/custom-component-module.js", async (route) => {
await route.fulfill({ path: "playwright/sample-files/custom-component-module.js" });
await route.fulfill({ path: getSampleFilePath("custom-component-module.js") });
});
await use(page);
},