Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions tools/playwright/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tools/playwright/tests/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});