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): do only match JS/TS files when collecting (#7014)

Max Schmitt05382c997bde
diff --git a/src/test/runner.ts b/src/test/runner.ts
index 609fee2fc8..96b74772df 100644
--- a/src/test/runner.ts
+++ b/src/test/runner.ts
@@ -143,7 +143,8 @@ export class Runner {
const allFiles = await collectFiles(project.config.testDir);
const testMatch = createMatcher(project.config.testMatch);
const testIgnore = createMatcher(project.config.testIgnore);
- const testFiles = allFiles.filter(file => !testIgnore(file) && testMatch(file) && testFileFilter(file));
+ const testFileExtension = (file: string) => ['.js', '.ts'].includes(path.extname(file));
+ const testFiles = allFiles.filter(file => !testIgnore(file) && testMatch(file) && testFileFilter(file) && testFileExtension(file));
files.set(project, testFiles);
testFiles.forEach(file => allTestFiles.add(file));
}
diff --git a/tests/playwright-test/test-ignore.spec.ts b/tests/playwright-test/test-ignore.spec.ts
index e39b1a9f3f..6762264825 100644
--- a/tests/playwright-test/test-ignore.spec.ts
+++ b/tests/playwright-test/test-ignore.spec.ts
@@ -259,4 +259,25 @@ test('should ignore node_modules even with custom testIgnore', async ({ runInlin
});
expect(result.passed).toBe(1);
expect(result.exitCode).toBe(0);
-});
\ No newline at end of file
+});
+
+test('should only match files with JS/TS file extensions', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'playwright.config.ts': `
+ module.exports = { testMatch: /foobar/ };
+ `,
+ 'foobar.test.ts': `
+ const { test } = pwt;
+ test('pass', ({}) => {});
+ `,
+ 'foobar.test.js': `
+ const { test } = pwt;
+ test('pass', ({}) => {});
+ `,
+ 'foobar.test.ts-snapshots/compares-page-screenshot-chromium-linux-test-chromium.png': `
+ <S0MeTh1ngN0nPArsAble!
+ `
+ });
+ expect(result.exitCode).toBe(0);
+ expect(result.passed).toBe(2);
+});