From 42fa35a545384c40620d72dd646057cd397f448d Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 12 Feb 2025 09:58:50 +0100 Subject: [PATCH] feat(runner): enable gitCommitInfo by default on GH Actions --- packages/playwright/src/common/config.ts | 3 +- tests/playwright-test/reporter-html.spec.ts | 36 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index b0bc394873..59d1973578 100644 --- a/packages/playwright/src/common/config.ts +++ b/packages/playwright/src/common/config.ts @@ -78,7 +78,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.populateGitInfo = takeFirst(userConfig.populateGitInfo, defaultPopulateGitInfo); 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); @@ -301,6 +301,7 @@ function resolveScript(id: string | undefined, rootDir: string): string | undefi export const defaultGrep = /.*/; export const defaultReporter = process.env.CI ? 'dot' : 'list'; +const defaultPopulateGitInfo = process.env.GITHUB_ACTIONS === 'true'; const configInternalSymbol = Symbol('configInternalSymbol'); diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts index acfd4cd187..d30d7f3e9d 100644 --- a/tests/playwright-test/reporter-html.spec.ts +++ b/tests/playwright-test/reporter-html.spec.ts @@ -1242,6 +1242,42 @@ for (const useIntermediateMergeReport of [true, false] as const) { `); }); + test('should include metadata on GH Actions', async ({ runInlineTest, writeFiles, showReport, page }) => { + const files = { + 'example.spec.ts': ` + import { test, expect } from '@playwright/test'; + test('sample', async ({}) => { expect(2).toBe(2); }); + `, + }; + const baseDir = await writeFiles(files); + + const execGit = async (args: string[]) => { + const { code, stdout, stderr } = await spawnAsync('git', args, { stdio: 'pipe', cwd: baseDir }); + if (!!code) + throw new Error(`Non-zero exit of:\n$ git ${args.join(' ')}\nConsole:\nstdout:\n${stdout}\n\nstderr:\n${stderr}\n\n`); + return; + }; + + await execGit(['init']); + await execGit(['config', '--local', 'user.email', 'shakespeare@example.local']); + await execGit(['config', '--local', 'user.name', 'William']); + await execGit(['add', '*']); + await execGit(['commit', '-m', 'chore(html): make this test look nice']); + + const result = await runInlineTest(files, { reporter: 'dot,html' }, { + GITHUB_ACTIONS: 'true', + PLAYWRIGHT_HTML_OPEN: 'never', + }); + + await showReport(); + + expect(result.exitCode).toBe(0); + await page.getByRole('button', { name: 'Metadata' }).click(); + await expect(page.locator('.metadata-view')).toMatchAriaSnapshot(` + - text: /make this test look nice/ + `); + }); + test('should not include git metadata with populateGitInfo = false', async ({ runInlineTest, showReport, page }) => { const result = await runInlineTest({ 'playwright.config.ts': `