Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): respectGitIgnore option #30972

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/src/test-api/class-testconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,14 @@ 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 it is true, i.e. if
yury-s marked this conversation as resolved.
Show resolved Hide resolved
yury-s marked this conversation as resolved.
Show resolved Hide resolved
neither [`property: TestConfig.retries`] nor [`property: TestProject.retries`] 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]>
Expand Down
8 changes: 8 additions & 0 deletions docs/src/test-api/class-testproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ 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 it is true, i.e. if
neither [`property: TestConfig.retries`] nor [`property: TestProject.retries`] 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]>
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright/src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,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 = projectConfig.respectGitIgnore ?? config.respectGitIgnore ?? (!projectConfig.testDir && !config.testDir);
yury-s marked this conversation as resolved.
Show resolved Hide resolved
this.ignoreSnapshots = takeFirst(configCLIOverrides.ignoreSnapshots, projectConfig.ignoreSnapshots, config.ignoreSnapshots, false);
}
}
Expand Down
18 changes: 18 additions & 0 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ interface TestProject<TestArgs = {}, WorkerArgs = {}> {
*/
repeatEach?: number;

/**
* Whether to skip entries from `.gitignore` when searching for test files. By default it is true, i.e. if neither
* [testConfig.retries](https://playwright.dev/docs/api/class-testconfig#test-config-retries) nor
* [testProject.retries](https://playwright.dev/docs/api/class-testproject#test-project-retries) 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).
Expand Down Expand Up @@ -1360,6 +1369,15 @@ interface TestConfig<TestArgs = {}, WorkerArgs = {}> {
threshold: number;
};

/**
* Whether to skip entries from `.gitignore` when searching for test files. By default it is true, i.e. if neither
* [testConfig.retries](https://playwright.dev/docs/api/class-testconfig#test-config-retries) nor
* [testProject.retries](https://playwright.dev/docs/api/class-testproject#test-project-retries) 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).
Expand Down
37 changes: 37 additions & 0 deletions tests/playwright-test/gitignore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Loading