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

Add new config prop populateGitInfo #34329

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions packages/playwright/src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import type { Config, Fixtures, Project, ReporterDescription } from '../../types/test';
import type { Location } from '../../types/testReporter';
import type { TestRunnerPluginRegistration } from '../plugins';
import { gitCommitInfo } from '../plugins/gitCommitInfoPlugin';
Copy link
Contributor Author

@vitalets vitalets Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting linter error on this line:

Checking DEPS for html-reporter
Checking DEPS for playwright-ct-core
Disallowed import ../playwright/src/plugins/gitCommitInfoPlugin.ts in ../playwright/src/common/config.ts

How to fix it?

import { getPackageJsonPath, mergeObjects } from '../util';
import type { Matcher } from '../util';
import type { ConfigCLIOverrides } from './ipc';
Expand Down Expand Up @@ -91,6 +92,7 @@
grepInvert: takeFirst(userConfig.grepInvert, null),
maxFailures: takeFirst(configCLIOverrides.debug ? 1 : undefined, configCLIOverrides.maxFailures, userConfig.maxFailures, 0),
metadata: takeFirst(userConfig.metadata, {}),
populateGitInfo: takeFirst(userConfig.populateGitInfo, false),

Check failure on line 95 in packages/playwright/src/common/config.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Object literal may only specify known properties, and 'populateGitInfo' does not exist in type 'FullConfig<{}, {}>'.

Check failure on line 95 in packages/playwright/src/common/config.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Property 'populateGitInfo' does not exist on type 'Config<{}, {}>'.
preserveOutput: takeFirst(userConfig.preserveOutput, 'always'),
reporter: takeFirst(configCLIOverrides.reporter, resolveReporters(userConfig.reporter, configDir), [[defaultReporter]]),
reportSlowTests: takeFirst(userConfig.reportSlowTests, { max: 5, threshold: 15000 }),
Expand Down Expand Up @@ -134,6 +136,9 @@
this.webServers = [];
}

if (this.config.populateGitInfo)

Check failure on line 139 in packages/playwright/src/common/config.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Property 'populateGitInfo' does not exist on type 'FullConfig<{}, {}>'.
this.plugins.push({ factory: gitCommitInfo });

const projectConfigs = configCLIOverrides.projects || userConfig.projects || [userConfig];
this.projects = projectConfigs.map(p => new FullProjectInternal(configDir, userConfig, this, p, this.configCLIOverrides, packageJsonDir));
resolveProjectDependencies(this.projects);
Expand Down
1 change: 1 addition & 0 deletions packages/playwright/src/isomorphic/teleReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@
grepInvert: null,
maxFailures: 0,
metadata: {},
populateGitInfo: false,

Check failure on line 599 in packages/playwright/src/isomorphic/teleReceiver.ts

View workflow job for this annotation

GitHub Actions / docs & lint

Object literal may only specify known properties, and 'populateGitInfo' does not exist in type 'FullConfig<{}, {}>'.
preserveOutput: 'always',
projects: [],
reporter: [[process.env.CI ? 'dot' : 'list']],
Expand Down
22 changes: 22 additions & 0 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,23 @@ interface TestConfig<TestArgs = {}, WorkerArgs = {}> {
*/
outputDir?: string;

/**
* Whether to populate [metadata](https://playwright.dev/docs/api/class-testconfig#test-config-output-metadata) with Git info.
*
* **Usage**
*
* ```js
* // playwright.config.ts
* import { defineConfig } from '@playwright/test';
*
* export default defineConfig({
* populateGitInfo: !!process.env.CI,
* });
* ```
*
*/
populateGitInfo?: boolean;

/**
* Whether to preserve test output in the
* [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir). Defaults to
Expand Down Expand Up @@ -1796,6 +1813,11 @@ export interface FullConfig<TestArgs = {}, WorkerArgs = {}> {
*/
metadata: Metadata;

/**
* See [testConfig.populateGitInfo](https://playwright.dev/docs/api/class-testconfig#test-config-populategitinfo).
*/
populateGitInfo: boolean;

/**
* See [testConfig.preserveOutput](https://playwright.dev/docs/api/class-testconfig#test-config-preserve-output).
*/
Expand Down
25 changes: 21 additions & 4 deletions tests/playwright-test/reporter-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,14 +1144,12 @@ for (const useIntermediateMergeReport of [true, false] as const) {
});

test.describe('gitCommitInfo plugin', () => {
test('should include metadata', async ({ runInlineTest, writeFiles, showReport, page }) => {
test('should include metadata with populateGitInfo = true', async ({ runInlineTest, writeFiles, showReport, page }) => {
const files = {
'uncommitted.txt': `uncommitted file`,
'playwright.config.ts': `
import { gitCommitInfo } from 'playwright/lib/plugins';
import { test, expect } from '@playwright/test';
const plugins = [gitCommitInfo()];
export default { '@playwright/test': { plugins } };
export default { populateGitInfo: true };
`,
'example.spec.ts': `
import { test, expect } from '@playwright/test';
Expand Down Expand Up @@ -1197,6 +1195,25 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await expect.soft(page.getByTestId('metadata-error')).not.toBeVisible();
});

test('should not include metadata with populateGitInfo = false', async ({ runInlineTest, showReport, page }) => {
const result = await runInlineTest({
'uncommitted.txt': `uncommitted file`,
'playwright.config.ts': `
export default { populateGitInfo: false };
`,
'example.spec.ts': `
import { test, expect } from '@playwright/test';
test('my sample test', async ({}) => { expect(2).toBe(2); });
`,
}, { reporter: 'dot,html' }, { PLAYWRIGHT_HTML_OPEN: 'never' }, undefined);

await showReport();

expect(result.exitCode).toBe(0);
await expect.soft(page.locator('text="my sample test"')).toBeVisible();
await expect.soft(page.getByTestId('metadata-error')).not.toBeVisible();
await expect.soft(page.getByTestId('metadata-chip')).not.toBeVisible();
});

test('should use explicitly supplied metadata', async ({ runInlineTest, showReport, page }) => {
const result = await runInlineTest({
Expand Down
Loading