Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(test-runner): match file paths containing spaces on Windows (#40783)

Yury Semikhatsky8c6a7e74f784
diff --git a/packages/playwright/src/util.ts b/packages/playwright/src/util.ts
index 7941dd731f..ce7da5ef8b 100644
--- a/packages/playwright/src/util.ts
+++ b/packages/playwright/src/util.ts
@@ -16,7 +16,6 @@
import fs from 'fs';
import path from 'path';
-import url from 'url';
import util from 'util';
import debug from 'debug';
@@ -114,12 +113,12 @@ export function createFileMatcher(patterns: string | RegExp | (string | RegExp)[
return true;
}
// Windows might still receive unix style paths from Cygwin or Git Bash.
- // Check against the file url as well.
+ // Check against the forward-slash form as well.
if (path.sep === '\\') {
- const fileURL = url.pathToFileURL(filePath).href;
+ const unixPath = filePath.split(path.sep).join('/');
for (const re of reList) {
re.lastIndex = 0;
- if (re.test(fileURL))
+ if (re.test(unixPath))
return true;
}
}
diff --git a/tests/playwright-test/command-line-filter.spec.ts b/tests/playwright-test/command-line-filter.spec.ts
index e33cb8b318..7d9ee14294 100644
--- a/tests/playwright-test/command-line-filter.spec.ts
+++ b/tests/playwright-test/command-line-filter.spec.ts
@@ -172,6 +172,23 @@ test('should focus a single nested test spec', async ({ runInlineTest }) => {
expect(result.report.suites[1].suites[0].suites[0].specs[0].title).toEqual('pass2');
});
+test('should accept unix file path containing a space', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'dir with space/a.spec.ts': `
+ import { test, expect } from '@playwright/test';
+ test('passes', () => { expect(1).toBe(1); });
+ `,
+ 'dir with space/b.spec.ts': `
+ import { test, expect } from '@playwright/test';
+ test('not picked', () => { expect(1).toBe(2); });
+ `,
+ }, undefined, undefined, { additionalArgs: ['dir with space/a.spec.ts'] });
+ expect(result.exitCode).toBe(0);
+ expect(result.passed).toBe(1);
+ expect(result.report.suites).toHaveLength(1);
+ expect(result.report.suites[0].specs[0].title).toBe('passes');
+});
+
test('should focus a single test suite', async ({ runInlineTest }) => {
const result = await runInlineTest({
'foo.test.ts': `