From 2a7ec73ad0ee2e987c1d4e6cd79782ec6a4d48b5 Mon Sep 17 00:00:00 2001 From: vitalets Date: Thu, 16 Jan 2025 11:01:54 +0400 Subject: [PATCH] use markdown-first way and inverse deps --- docs/src/test-api/class-fullconfig.md | 6 ++++++ docs/src/test-api/class-testconfig.md | 16 ++++++++++++++++ packages/playwright/src/common/config.ts | 4 ---- .../src/plugins/gitCommitInfoPlugin.ts | 6 ++++++ packages/playwright/src/runner/runner.ts | 3 +++ packages/playwright/types/test.d.ts | 5 +++-- 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/src/test-api/class-fullconfig.md b/docs/src/test-api/class-fullconfig.md index 923c9fa858..edf7c3a3da 100644 --- a/docs/src/test-api/class-fullconfig.md +++ b/docs/src/test-api/class-fullconfig.md @@ -64,6 +64,12 @@ 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 5a67ea36d4..59fa3f50b6 100644 --- a/docs/src/test-api/class-testconfig.md +++ b/docs/src/test-api/class-testconfig.md @@ -321,6 +321,22 @@ This path will serve as the base directory for each test file snapshot directory ## property: TestConfig.snapshotPathTemplate = %%-test-config-snapshot-path-template-%% * since: v1.28 +## property: TestConfig.populateGitInfo +* since: v1.50 +- type: ?<[boolean]> + +Whether to populate [`property: TestConfig.metadata`] with Git info. + +**Usage** + +```js title="playwright.config.ts" +import { defineConfig } from '@playwright/test'; + +export default defineConfig({ + populateGitInfo: !!process.env.CI, +}); +``` + ## property: TestConfig.preserveOutput * since: v1.10 - type: ?<[PreserveOutput]<"always"|"never"|"failures-only">> diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index 9f909e8e20..2e79cac61f 100644 --- a/packages/playwright/src/common/config.ts +++ b/packages/playwright/src/common/config.ts @@ -20,7 +20,6 @@ import os from 'os'; 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'; import { getPackageJsonPath, mergeObjects } from '../util'; import type { Matcher } from '../util'; import type { ConfigCLIOverrides } from './ipc'; @@ -136,9 +135,6 @@ export class FullConfigInternal { this.webServers = []; } - if (this.config.populateGitInfo) - 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); diff --git a/packages/playwright/src/plugins/gitCommitInfoPlugin.ts b/packages/playwright/src/plugins/gitCommitInfoPlugin.ts index 4c55a3eab3..9422bcb4d8 100644 --- a/packages/playwright/src/plugins/gitCommitInfoPlugin.ts +++ b/packages/playwright/src/plugins/gitCommitInfoPlugin.ts @@ -17,9 +17,15 @@ import { createGuid, spawnAsync } from 'playwright-core/lib/utils'; import type { TestRunnerPlugin } from './'; import type { FullConfig } from '../../types/testReporter'; +import type { FullConfigInternal } from '../common/config'; const GIT_OPERATIONS_TIMEOUT_MS = 1500; +export const addGitCommitInfoPlugin = (fullConfig: FullConfigInternal) => { + if (fullConfig.config.populateGitInfo) + fullConfig.plugins.push({ factory: gitCommitInfo }); +}; + export const gitCommitInfo = (options?: GitCommitInfoPluginOptions): TestRunnerPlugin => { return { name: 'playwright:git-commit-info', diff --git a/packages/playwright/src/runner/runner.ts b/packages/playwright/src/runner/runner.ts index a1e73657c9..51eb15e299 100644 --- a/packages/playwright/src/runner/runner.ts +++ b/packages/playwright/src/runner/runner.ts @@ -17,6 +17,7 @@ import type { FullResult, TestError } from '../../types/testReporter'; import { webServerPluginsForConfig } from '../plugins/webServerPlugin'; +import { addGitCommitInfoPlugin } from '../plugins/gitCommitInfoPlugin'; import { collectFilesForProject, filterProjects } from './projectUtils'; import { createErrorCollectingReporter, createReporters } from './reporters'; import { TestRun, createApplyRebaselinesTask, createClearCacheTask, createGlobalSetupTasks, createLoadTask, createPluginSetupTasks, createReportBeginTask, createRunTestsTasks, createStartDevServerTask, runTasks } from './tasks'; @@ -70,6 +71,8 @@ export class Runner { const config = this._config; const listOnly = config.cliListOnly; + addGitCommitInfoPlugin(config); + // Legacy webServer support. webServerPluginsForConfig(config).forEach(p => config.plugins.push({ factory: p })); diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 3d047edde4..8e1ca2f447 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -1294,7 +1294,8 @@ interface TestConfig { outputDir?: string; /** - * Whether to populate [metadata](https://playwright.dev/docs/api/class-testconfig#test-config-output-metadata) with Git info. + * Whether to populate [testConfig.metadata](https://playwright.dev/docs/api/class-testconfig#test-config-metadata) + * with Git info. * * **Usage** * @@ -1814,7 +1815,7 @@ export interface FullConfig { metadata: Metadata; /** - * See [testConfig.populateGitInfo](https://playwright.dev/docs/api/class-testconfig#test-config-populategitinfo). + * See [testConfig.populateGitInfo](https://playwright.dev/docs/api/class-testconfig#test-config-populate-git-info). */ populateGitInfo: boolean;