diff --git a/tools/playwright/src/utils.ts b/tools/playwright/src/utils.ts index 66f2b12..20cf5c3 100644 --- a/tools/playwright/src/utils.ts +++ b/tools/playwright/src/utils.ts @@ -6,16 +6,20 @@ /** * Normalizes a file path by removing webpack:// prefixes and similar bundler artifacts. * Handles cases where webpack:/ appears in the middle of the path. + * Supports both forward slashes (Unix) and backslashes (Windows). * Examples: * webpack:/@scope/package/src/file.ts -> @scope/package/src/file.ts * prefix/webpack:/@scope/package/src/file.ts -> @scope/package/src/file.ts + * D:\path\webpack:\@scope\package\file.ts -> @scope/package/file.ts * /absolute/path/to/file.ts -> /absolute/path/to/file.ts */ export function normalizeFilePath(filePath: string): string { - // Find webpack:/ or webpack:// anywhere in the path and extract everything after it - const webpackMatch = filePath.match(/webpack:\/\/?(.+)/); + // Find webpack:/ or webpack:// or webpack:\ anywhere in the path and extract everything after it + // Handles both Unix (/) and Windows (\) path separators + const webpackMatch = filePath.match(/webpack:[/\\]{1,2}(.+)/); if (webpackMatch) { - return webpackMatch[1]; + // Normalize backslashes to forward slashes for consistency + return webpackMatch[1].replace(/\\/g, "/"); } // Remove any leading ./ from regular paths diff --git a/tools/playwright/tests/utils.spec.ts b/tools/playwright/tests/utils.spec.ts index 398645a..cd710c2 100644 --- a/tools/playwright/tests/utils.spec.ts +++ b/tools/playwright/tests/utils.spec.ts @@ -56,4 +56,24 @@ test.describe("normalizeFilePath", () => { test("should handle empty string", () => { expect(normalizeFilePath("")).toBe(""); }); + + test("should handle Windows path with webpack:\\ (backslash)", () => { + const input = + "D:\\a\\_work\\1\\a\\project\\tests\\webpack:\\package\\tests\\file.spec.ts"; + const expected = "package/tests/file.spec.ts"; + expect(normalizeFilePath(input)).toBe(expected); + }); + + test("should normalize backslashes to forward slashes in webpack paths", () => { + const input = "webpack:\\package\\src\\nested\\file.spec.ts"; + const expected = "package/src/nested/file.spec.ts"; + expect(normalizeFilePath(input)).toBe(expected); + }); + + test("should handle Windows CI path with webpack in the middle", () => { + const input = + "D:\\build\\agent\\project\\tests\\webpack:\\lib\\tests\\feature.spec.ts"; + const expected = "lib/tests/feature.spec.ts"; + expect(normalizeFilePath(input)).toBe(expected); + }); });