From 05382c997bdee0820331fd1a8284c6ceb6c7ff6f Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 10 Jun 2021 07:41:57 -0700 Subject: [PATCH] fix(test-runner): do only match JS/TS files when collecting (#7014) --- src/test/runner.ts | 3 ++- tests/playwright-test/test-ignore.spec.ts | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) 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': ` +