diff --git a/docs/src/test-api/class-fullconfig.md b/docs/src/test-api/class-fullconfig.md index edf7c3a3da..923c9fa858 100644 --- a/docs/src/test-api/class-fullconfig.md +++ b/docs/src/test-api/class-fullconfig.md @@ -64,12 +64,6 @@ See [`property: TestConfig.maxFailures`]. See [`property: TestConfig.metadata`]. -## property: FullConfig.populateGitInfo -* since: v1.50 -- type: <[boolean]> - -See [`property: TestConfig.populateGitInfo`]. - ## property: FullConfig.preserveOutput * since: v1.10 - type: <[PreserveOutput]<"always"|"never"|"failures-only">> diff --git a/docs/src/test-api/class-testconfig.md b/docs/src/test-api/class-testconfig.md index 59fa3f50b6..bfcf5a260f 100644 --- a/docs/src/test-api/class-testconfig.md +++ b/docs/src/test-api/class-testconfig.md @@ -322,10 +322,10 @@ This path will serve as the base directory for each test file snapshot directory * since: v1.28 ## property: TestConfig.populateGitInfo -* since: v1.50 +* since: v1.51 - type: ?<[boolean]> -Whether to populate [`property: TestConfig.metadata`] with Git info. +Whether to populate [`property: TestConfig.metadata`] with Git info. The metadata will automatically appear in the HTML report and is available in Reporter API. **Usage** diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index 2e79cac61f..2248dfb79d 100644 --- a/packages/playwright/src/common/config.ts +++ b/packages/playwright/src/common/config.ts @@ -46,6 +46,7 @@ export class FullConfigInternal { readonly plugins: TestRunnerPluginRegistration[]; readonly projects: FullProjectInternal[] = []; readonly singleTSConfigPath?: string; + readonly populateGitInfo: boolean; cliArgs: string[] = []; cliGrep: string | undefined; cliGrepInvert: string | undefined; @@ -75,6 +76,7 @@ export class FullConfigInternal { const privateConfiguration = (userConfig as any)['@playwright/test']; this.plugins = (privateConfiguration?.plugins || []).map((p: any) => ({ factory: p })); this.singleTSConfigPath = pathResolve(configDir, userConfig.tsconfig); + this.populateGitInfo = takeFirst(userConfig.populateGitInfo, false); this.globalSetups = (Array.isArray(userConfig.globalSetup) ? userConfig.globalSetup : [userConfig.globalSetup]).map(s => resolveScript(s, configDir)).filter(script => script !== undefined); this.globalTeardowns = (Array.isArray(userConfig.globalTeardown) ? userConfig.globalTeardown : [userConfig.globalTeardown]).map(s => resolveScript(s, configDir)).filter(script => script !== undefined); @@ -91,7 +93,6 @@ export class FullConfigInternal { 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), preserveOutput: takeFirst(userConfig.preserveOutput, 'always'), reporter: takeFirst(configCLIOverrides.reporter, resolveReporters(userConfig.reporter, configDir), [[defaultReporter]]), reportSlowTests: takeFirst(userConfig.reportSlowTests, { max: 5, threshold: 15000 }), diff --git a/packages/playwright/src/isomorphic/teleReceiver.ts b/packages/playwright/src/isomorphic/teleReceiver.ts index 7079017bc6..1d41b793cd 100644 --- a/packages/playwright/src/isomorphic/teleReceiver.ts +++ b/packages/playwright/src/isomorphic/teleReceiver.ts @@ -596,7 +596,6 @@ export const baseFullConfig: reporterTypes.FullConfig = { grepInvert: null, maxFailures: 0, metadata: {}, - populateGitInfo: false, preserveOutput: 'always', projects: [], reporter: [[process.env.CI ? 'dot' : 'list']], diff --git a/packages/playwright/src/plugins/gitCommitInfoPlugin.ts b/packages/playwright/src/plugins/gitCommitInfoPlugin.ts index 9422bcb4d8..2244d80a9c 100644 --- a/packages/playwright/src/plugins/gitCommitInfoPlugin.ts +++ b/packages/playwright/src/plugins/gitCommitInfoPlugin.ts @@ -22,7 +22,7 @@ import type { FullConfigInternal } from '../common/config'; const GIT_OPERATIONS_TIMEOUT_MS = 1500; export const addGitCommitInfoPlugin = (fullConfig: FullConfigInternal) => { - if (fullConfig.config.populateGitInfo) + if (fullConfig.populateGitInfo) fullConfig.plugins.push({ factory: gitCommitInfo }); }; diff --git a/packages/playwright/src/runner/testServer.ts b/packages/playwright/src/runner/testServer.ts index e3a61329e2..e4ff3a7a2f 100644 --- a/packages/playwright/src/runner/testServer.ts +++ b/packages/playwright/src/runner/testServer.ts @@ -39,6 +39,7 @@ import { baseFullConfig } from '../isomorphic/teleReceiver'; import { InternalReporter } from '../reporters/internalReporter'; import type { ReporterV2 } from '../reporters/reporterV2'; import { internalScreen } from '../reporters/base'; +import { addGitCommitInfoPlugin } from '../plugins/gitCommitInfoPlugin'; const originalStdoutWrite = process.stdout.write; const originalStderrWrite = process.stderr.write; @@ -406,6 +407,7 @@ export class TestServerDispatcher implements TestServerInterface { // Preserve plugin instances between setup and build. if (!this._plugins) { webServerPluginsForConfig(config).forEach(p => config.plugins.push({ factory: p })); + addGitCommitInfoPlugin(config); this._plugins = config.plugins || []; } else { config.plugins.splice(0, config.plugins.length, ...this._plugins); diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index ce5b78959a..4310bc3ad9 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -1295,7 +1295,7 @@ interface TestConfig { /** * Whether to populate [testConfig.metadata](https://playwright.dev/docs/api/class-testconfig#test-config-metadata) - * with Git info. + * with Git info. The metadata will automatically appear in the HTML report and is available in Reporter API. * * **Usage** * @@ -1814,11 +1814,6 @@ export interface FullConfig { */ metadata: Metadata; - /** - * See [testConfig.populateGitInfo](https://playwright.dev/docs/api/class-testconfig#test-config-populate-git-info). - */ - populateGitInfo: boolean; - /** * See [testConfig.preserveOutput](https://playwright.dev/docs/api/class-testconfig#test-config-preserve-output). */ diff --git a/tests/playwright-test/ui-mode-metadata.spec.ts b/tests/playwright-test/ui-mode-metadata.spec.ts new file mode 100644 index 0000000000..5466d4f007 --- /dev/null +++ b/tests/playwright-test/ui-mode-metadata.spec.ts @@ -0,0 +1,35 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { test } from './ui-mode-fixtures'; + +test.only('should display git info metadata', async ({ runUITest }) => { + const { page } = await runUITest({ + 'playwright.config.ts': ` + import { defineConfig } from '@playwright/test'; + export default defineConfig({ + populateGitInfo: true, + }); + `, + 'a.test.js': ` + import { test, expect } from '@playwright/test'; + test('should work', async ({}) => {}); + ` + }); + await page.getByTitle('Run all').click(); + + // todo: what to check? +});