Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(config): respectGitIgnore option (#30972)
Yury Semikhatskya106428114a7
diff --git a/docs/src/test-api/class-testconfig.md b/docs/src/test-api/class-testconfig.mdindex 7d24845a54..fc21a4d9d9 100644--- a/docs/src/test-api/class-testconfig.md+++ b/docs/src/test-api/class-testconfig.md@@ -439,6 +439,12 @@ export default defineConfig({Test files that took more than `threshold` milliseconds are considered slow, and the slowest ones are reported, no more than `max` number of them. Passing zero as `max` reports all test files that exceed the threshold.+## property: TestConfig.respectGitIgnore+* since: v1.45+- type: ?<[boolean]>++Whether to skip entries from `.gitignore` when searching for test files. By default, if neither [`property: TestConfig.testDir`] nor [`property: TestProject.testDir`] are explicitely specified, Playwright will ignore any test files matching `.gitignore` entries. This option allows to override that behavior.+## property: TestConfig.retries* since: v1.10- type: ?<[int]>diff --git a/docs/src/test-api/class-testproject.md b/docs/src/test-api/class-testproject.mdindex 7477a3a88d..562dc76e09 100644--- a/docs/src/test-api/class-testproject.md+++ b/docs/src/test-api/class-testproject.md@@ -223,6 +223,12 @@ The number of times to repeat each test, useful for debugging flaky tests.Use [`property: TestConfig.repeatEach`] to change this option for all projects.+## property: TestProject.respectGitIgnore+* since: v1.45+- type: ?<[boolean]>++Whether to skip entries from `.gitignore` when searching for test files. By default, if neither [`property: TestConfig.testDir`] nor [`property: TestProject.testDir`] are explicitely specified, Playwright will ignore any test files matching `.gitignore` entries. This option allows to override that behavior.+## property: TestProject.retries* since: v1.10- type: ?<[int]>diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.tsindex aadfb00754..015dbc1e71 100644--- a/packages/playwright/src/common/config.ts+++ b/packages/playwright/src/common/config.ts@@ -196,7 +196,7 @@ export class FullProjectInternal {const stylePaths = Array.isArray(this.expect.toHaveScreenshot.stylePath) ? this.expect.toHaveScreenshot.stylePath : [this.expect.toHaveScreenshot.stylePath];this.expect.toHaveScreenshot.stylePath = stylePaths.map(stylePath => path.resolve(configDir, stylePath));}- this.respectGitIgnore = !projectConfig.testDir && !config.testDir;+ this.respectGitIgnore = takeFirst(projectConfig.respectGitIgnore, config.respectGitIgnore, !projectConfig.testDir && !config.testDir);this.ignoreSnapshots = takeFirst(configCLIOverrides.ignoreSnapshots, projectConfig.ignoreSnapshots, config.ignoreSnapshots, false);}}diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.tsindex 404d255577..1570d0046b 100644--- a/packages/playwright/types/test.d.ts+++ b/packages/playwright/types/test.d.ts@@ -363,6 +363,15 @@ interface TestProject<TestArgs = {}, WorkerArgs = {}> {*/repeatEach?: number;+ /**+ * Whether to skip entries from `.gitignore` when searching for test files. By default, if neither+ * [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir) nor+ * [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir) are explicitely+ * specified, Playwright will ignore any test files matching `.gitignore` entries. This option allows to override that+ * behavior.+ */+ respectGitIgnore?: boolean;+/*** The maximum number of retry attempts given to failed tests. Learn more about* [test retries](https://playwright.dev/docs/test-retries#retries).@@ -1360,6 +1369,15 @@ interface TestConfig<TestArgs = {}, WorkerArgs = {}> {threshold: number;};+ /**+ * Whether to skip entries from `.gitignore` when searching for test files. By default, if neither+ * [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir) nor+ * [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir) are explicitely+ * specified, Playwright will ignore any test files matching `.gitignore` entries. This option allows to override that+ * behavior.+ */+ respectGitIgnore?: boolean;+/*** The maximum number of retry attempts given to failed tests. By default failing tests are not retried. Learn more* about [test retries](https://playwright.dev/docs/test-retries#retries).diff --git a/tests/playwright-test/gitignore.spec.ts b/tests/playwright-test/gitignore.spec.tsindex 588cb9e07f..2141d7878c 100644--- a/tests/playwright-test/gitignore.spec.ts+++ b/tests/playwright-test/gitignore.spec.ts@@ -157,3 +157,40 @@ test('should ignore .gitignore inside project testDir', async ({ runInlineTest }expect(result.passed).toBe(2);});+test('global config respectGitIgnore', {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30553' }+}, async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'tests/.gitignore': `+ *.js+ `,+ 'playwright.config.js': `+ module.exports = { respectGitIgnore: false, projects: [{ }] };+ `,+ 'tests/a.spec.js': `+ import { test, expect } from '@playwright/test';+ test('pass', ({}) => {});+ `,+ });+ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+});++test('project config respectGitIgnore', {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30553' }+}, async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'tests/.gitignore': `+ *.js+ `,+ 'playwright.config.js': `+ module.exports = { projects: [{ respectGitIgnore: false }] };+ `,+ 'tests/a.spec.js': `+ import { test, expect } from '@playwright/test';+ test('pass', ({}) => {});+ `,+ });+ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+});