From bf661535a637d2c7fbf55d0ff0e247ebd272355e Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 17 Apr 2023 12:57:33 -0700 Subject: [PATCH] fix(testMatch): do not count `test.ts` and `spec.ts` as test files by default (#22440) --- docs/src/test-api/class-testconfig.md | 2 +- docs/src/test-api/class-testproject.md | 2 +- packages/playwright-test/src/common/config.ts | 2 +- packages/playwright-test/types/test.d.ts | 15 +++++++++------ tests/playwright-test/loader.spec.ts | 17 +++++++---------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/src/test-api/class-testconfig.md b/docs/src/test-api/class-testconfig.md index 558a361c56..7d2b035733 100644 --- a/docs/src/test-api/class-testconfig.md +++ b/docs/src/test-api/class-testconfig.md @@ -517,7 +517,7 @@ export default defineConfig({ Only the files matching one of these patterns are executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns. -By default, Playwright looks for files matching the following glob pattern: `**/?(*.)@(spec|test).?(m)[jt]s?(x)`. This means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example `login-screen.spec.ts`. +By default, Playwright looks for files matching the following glob pattern: `**/*.@(spec|test).?(m)[jt]s?(x)`. This means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example `login-screen.wrong-credentials.spec.ts`. **Usage** diff --git a/docs/src/test-api/class-testproject.md b/docs/src/test-api/class-testproject.md index 5104510983..36d77b21e7 100644 --- a/docs/src/test-api/class-testproject.md +++ b/docs/src/test-api/class-testproject.md @@ -263,7 +263,7 @@ Use [`property: TestConfig.testIgnore`] to change this option for all projects. Only the files matching one of these patterns are executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns. -By default, Playwright looks for files matching the following glob pattern: `**/?(*.)@(spec|test).?(m)[jt]s?(x)`. This means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example `login-screen.spec.ts`. +By default, Playwright looks for files matching the following glob pattern: `**/*.@(spec|test).?(m)[jt]s?(x)`. This means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example `login-screen.wrong-credentials.spec.ts`. Use [`property: TestConfig.testMatch`] to change this option for all projects. diff --git a/packages/playwright-test/src/common/config.ts b/packages/playwright-test/src/common/config.ts index feb7050a6d..3571c37afe 100644 --- a/packages/playwright-test/src/common/config.ts +++ b/packages/playwright-test/src/common/config.ts @@ -170,7 +170,7 @@ export class FullProjectInternal { testDir, snapshotDir: takeFirst(pathResolve(configDir, projectConfig.snapshotDir), pathResolve(configDir, config.snapshotDir), testDir), testIgnore: takeFirst(projectConfig.testIgnore, config.testIgnore, []), - testMatch: takeFirst(projectConfig.testMatch, config.testMatch, '**/?(*.)@(spec|test).?(m)[jt]s?(x)'), + testMatch: takeFirst(projectConfig.testMatch, config.testMatch, '**/*.@(spec|test).?(m)[jt]s?(x)'), timeout: takeFirst(configCLIOverrides.timeout, projectConfig.timeout, config.timeout, defaultTimeout), use: mergeObjects(config.use, projectConfig.use, configCLIOverrides.use), dependencies: projectConfig.dependencies || [], diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts index 96b5142fec..6ae6e00619 100644 --- a/packages/playwright-test/types/test.d.ts +++ b/packages/playwright-test/types/test.d.ts @@ -347,8 +347,9 @@ export interface FullProject { * Only the files matching one of these patterns are executed as test files. Matching is performed against the * absolute file path. Strings are treated as glob patterns. * - * By default, Playwright looks for files matching the following glob pattern: `**\/?(*.)@(spec|test).?(m)[jt]s?(x)`. - * This means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example `login-screen.spec.ts`. + * By default, Playwright looks for files matching the following glob pattern: `**\/*.@(spec|test).?(m)[jt]s?(x)`. This + * means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example + * `login-screen.wrong-credentials.spec.ts`. * * Use [testConfig.testMatch](https://playwright.dev/docs/api/class-testconfig#test-config-test-match) to change this * option for all projects. @@ -1191,8 +1192,9 @@ interface TestConfig { * Only the files matching one of these patterns are executed as test files. Matching is performed against the * absolute file path. Strings are treated as glob patterns. * - * By default, Playwright looks for files matching the following glob pattern: `**\/?(*.)@(spec|test).?(m)[jt]s?(x)`. - * This means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example `login-screen.spec.ts`. + * By default, Playwright looks for files matching the following glob pattern: `**\/*.@(spec|test).?(m)[jt]s?(x)`. This + * means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example + * `login-screen.wrong-credentials.spec.ts`. * * **Usage** * @@ -5875,8 +5877,9 @@ interface TestProject { * Only the files matching one of these patterns are executed as test files. Matching is performed against the * absolute file path. Strings are treated as glob patterns. * - * By default, Playwright looks for files matching the following glob pattern: `**\/?(*.)@(spec|test).?(m)[jt]s?(x)`. - * This means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example `login-screen.spec.ts`. + * By default, Playwright looks for files matching the following glob pattern: `**\/*.@(spec|test).?(m)[jt]s?(x)`. This + * means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example + * `login-screen.wrong-credentials.spec.ts`. * * Use [testConfig.testMatch](https://playwright.dev/docs/api/class-testconfig#test-config-test-match) to change this * option for all projects. diff --git a/tests/playwright-test/loader.spec.ts b/tests/playwright-test/loader.spec.ts index 0129f7202f..9a39ddd616 100644 --- a/tests/playwright-test/loader.spec.ts +++ b/tests/playwright-test/loader.spec.ts @@ -153,14 +153,6 @@ test('should match tests well', async ({ runInlineTest }) => { import { test, expect } from '@playwright/test'; test('works', () => {}); `, - 'test.ts': ` - import { test, expect } from '@playwright/test'; - test('works', () => {}); - `, - 'spec.ts': ` - import { test, expect } from '@playwright/test'; - test('works', () => {}); - `, 'strange.....spec.ts': ` import { test, expect } from '@playwright/test'; test('works', () => {}); @@ -184,7 +176,7 @@ test('should match tests well', async ({ runInlineTest }) => { }); expect(result.exitCode).toBe(0); - expect(result.passed).toBe(5); + expect(result.passed).toBe(3); }); test('should load an mjs file', async ({ runInlineTest }) => { @@ -690,14 +682,19 @@ test('should support dynamic import', async ({ runInlineTest, nodeVersion }) => expect(result.exitCode).toBe(0); }); -test('should allow test.extend.ts file', async ({ runInlineTest }) => { +test('should allow test.extend.ts and test.ts files', async ({ runInlineTest }) => { const result = await runInlineTest({ 'test.extend.ts': ` export { test, expect } from '@playwright/test'; `, + 'test.ts': ` + export const helper = 42; + `, 'a.test.ts': ` import { test, expect } from './test.extend'; + import { helper } from './test'; test('pass1', async () => { + expect(helper).toBe(42); }); `, });