populate on setup

This commit is contained in:
Simon Knott 2025-05-23 15:42:47 +02:00
parent 4b68edbcf4
commit fc07052d57
No known key found for this signature in database
GPG Key ID: 8CEDC00028084AEC

View File

@ -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();
}
};
};