From fc07052d57794d8c1940ac49bde8c6c43fcd2f4d Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 23 May 2025 15:42:47 +0200 Subject: [PATCH] populate on setup --- .../src/plugins/gitCommitInfoPlugin.ts | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/packages/playwright/src/plugins/gitCommitInfoPlugin.ts b/packages/playwright/src/plugins/gitCommitInfoPlugin.ts index b9a2b6330c..c35832d3a0 100644 --- a/packages/playwright/src/plugins/gitCommitInfoPlugin.ts +++ b/packages/playwright/src/plugins/gitCommitInfoPlugin.ts @@ -44,41 +44,46 @@ const gitCommitInfoPlugin = (fullConfig: FullConfigInternal): TestRunnerPlugin = let config: FullConfig; const configDir = fullConfig.configDir; + async function updateMetdata() { + const metadata = config.metadata as MetadataWithCommitInfo; + + const ci = await ciInfo(); + + if (!metadata.ci && ci) { + debug('ci info', ci); + metadata.ci = ci; + } + + if (fullConfig.captureGitInfo?.commit || (fullConfig.captureGitInfo?.commit === undefined && ci)) { + const git = await gitCommitInfo(configDir).catch(e => print('failed to get git commit info', e)); + if (git) { + debug('commit info', git); + metadata.gitCommit = git; + } + } + + if (fullConfig.captureGitInfo?.diff || (fullConfig.captureGitInfo?.diff === undefined && ci)) { + const diffResult = await gitDiff(configDir, ci).catch(e => print('failed to get git diff', e)); + if (diffResult) { + debug(`diff length ${diffResult.length}`); + metadata.gitDiff = diffResult; + } + } + } + + let testRun = 0; return { name: 'playwright:git-commit-info', setup: async (cfg: FullConfig) => { config = cfg; + await updateMetdata(); }, begin: async () => { - if (!config) - throw new Error('Configuration is missing'); - - const metadata = config.metadata as MetadataWithCommitInfo; - - const ci = await ciInfo(); - - if (!metadata.ci && ci) { - debug('ci info', ci); - metadata.ci = ci; - } - - if (fullConfig.captureGitInfo?.commit || (fullConfig.captureGitInfo?.commit === undefined && ci)) { - const git = await gitCommitInfo(configDir).catch(e => print('failed to get git commit info', e)); - if (git) { - debug('commit info', git); - metadata.gitCommit = git; - } - } - - if (fullConfig.captureGitInfo?.diff || (fullConfig.captureGitInfo?.diff === undefined && ci)) { - const diffResult = await gitDiff(configDir, ci).catch(e => print('failed to get git diff', e)); - if (diffResult) { - debug(`diff length ${diffResult.length}`); - metadata.gitDiff = diffResult; - } - } + testRun++; + if (testRun > 1) + await updateMetdata(); } }; };