Add new config prop populateGitInfo, see #34094
This commit is contained in:
parent
275f334b58
commit
9cd33a752d
|
|
@ -20,6 +20,7 @@ import os from 'os';
|
||||||
import type { Config, Fixtures, Project, ReporterDescription } from '../../types/test';
|
import type { Config, Fixtures, Project, ReporterDescription } from '../../types/test';
|
||||||
import type { Location } from '../../types/testReporter';
|
import type { Location } from '../../types/testReporter';
|
||||||
import type { TestRunnerPluginRegistration } from '../plugins';
|
import type { TestRunnerPluginRegistration } from '../plugins';
|
||||||
|
import { gitCommitInfo } from '../plugins/gitCommitInfoPlugin';
|
||||||
import { getPackageJsonPath, mergeObjects } from '../util';
|
import { getPackageJsonPath, mergeObjects } from '../util';
|
||||||
import type { Matcher } from '../util';
|
import type { Matcher } from '../util';
|
||||||
import type { ConfigCLIOverrides } from './ipc';
|
import type { ConfigCLIOverrides } from './ipc';
|
||||||
|
|
@ -91,6 +92,7 @@ export class FullConfigInternal {
|
||||||
grepInvert: takeFirst(userConfig.grepInvert, null),
|
grepInvert: takeFirst(userConfig.grepInvert, null),
|
||||||
maxFailures: takeFirst(configCLIOverrides.debug ? 1 : undefined, configCLIOverrides.maxFailures, userConfig.maxFailures, 0),
|
maxFailures: takeFirst(configCLIOverrides.debug ? 1 : undefined, configCLIOverrides.maxFailures, userConfig.maxFailures, 0),
|
||||||
metadata: takeFirst(userConfig.metadata, {}),
|
metadata: takeFirst(userConfig.metadata, {}),
|
||||||
|
populateGitInfo: takeFirst(userConfig.populateGitInfo, false),
|
||||||
preserveOutput: takeFirst(userConfig.preserveOutput, 'always'),
|
preserveOutput: takeFirst(userConfig.preserveOutput, 'always'),
|
||||||
reporter: takeFirst(configCLIOverrides.reporter, resolveReporters(userConfig.reporter, configDir), [[defaultReporter]]),
|
reporter: takeFirst(configCLIOverrides.reporter, resolveReporters(userConfig.reporter, configDir), [[defaultReporter]]),
|
||||||
reportSlowTests: takeFirst(userConfig.reportSlowTests, { max: 5, threshold: 15000 }),
|
reportSlowTests: takeFirst(userConfig.reportSlowTests, { max: 5, threshold: 15000 }),
|
||||||
|
|
@ -134,6 +136,9 @@ export class FullConfigInternal {
|
||||||
this.webServers = [];
|
this.webServers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.config.populateGitInfo)
|
||||||
|
this.plugins.push({ factory: gitCommitInfo });
|
||||||
|
|
||||||
const projectConfigs = configCLIOverrides.projects || userConfig.projects || [userConfig];
|
const projectConfigs = configCLIOverrides.projects || userConfig.projects || [userConfig];
|
||||||
this.projects = projectConfigs.map(p => new FullProjectInternal(configDir, userConfig, this, p, this.configCLIOverrides, packageJsonDir));
|
this.projects = projectConfigs.map(p => new FullProjectInternal(configDir, userConfig, this, p, this.configCLIOverrides, packageJsonDir));
|
||||||
resolveProjectDependencies(this.projects);
|
resolveProjectDependencies(this.projects);
|
||||||
|
|
|
||||||
|
|
@ -596,6 +596,7 @@ export const baseFullConfig: reporterTypes.FullConfig = {
|
||||||
grepInvert: null,
|
grepInvert: null,
|
||||||
maxFailures: 0,
|
maxFailures: 0,
|
||||||
metadata: {},
|
metadata: {},
|
||||||
|
populateGitInfo: false,
|
||||||
preserveOutput: 'always',
|
preserveOutput: 'always',
|
||||||
projects: [],
|
projects: [],
|
||||||
reporter: [[process.env.CI ? 'dot' : 'list']],
|
reporter: [[process.env.CI ? 'dot' : 'list']],
|
||||||
|
|
|
||||||
22
packages/playwright/types/test.d.ts
vendored
22
packages/playwright/types/test.d.ts
vendored
|
|
@ -1293,6 +1293,23 @@ interface TestConfig<TestArgs = {}, WorkerArgs = {}> {
|
||||||
*/
|
*/
|
||||||
outputDir?: string;
|
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
|
* Whether to preserve test output in the
|
||||||
* [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir). Defaults to
|
* [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir). Defaults to
|
||||||
|
|
@ -1796,6 +1813,11 @@ export interface FullConfig<TestArgs = {}, WorkerArgs = {}> {
|
||||||
*/
|
*/
|
||||||
metadata: Metadata;
|
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).
|
* See [testConfig.preserveOutput](https://playwright.dev/docs/api/class-testconfig#test-config-preserve-output).
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1144,14 +1144,12 @@ for (const useIntermediateMergeReport of [true, false] as const) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test.describe('gitCommitInfo plugin', () => {
|
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 = {
|
const files = {
|
||||||
'uncommitted.txt': `uncommitted file`,
|
'uncommitted.txt': `uncommitted file`,
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
import { gitCommitInfo } from 'playwright/lib/plugins';
|
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
const plugins = [gitCommitInfo()];
|
export default { populateGitInfo: true };
|
||||||
export default { '@playwright/test': { plugins } };
|
|
||||||
`,
|
`,
|
||||||
'example.spec.ts': `
|
'example.spec.ts': `
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
@ -1197,6 +1195,25 @@ for (const useIntermediateMergeReport of [true, false] as const) {
|
||||||
await expect.soft(page.getByTestId('metadata-error')).not.toBeVisible();
|
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 }) => {
|
test('should use explicitly supplied metadata', async ({ runInlineTest, showReport, page }) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue