Skip to content

Commit fef97c6

Browse files
imgrantwebpro
authored andcommittedJul 8, 2023
test: add a test scenario for git.getLatestTagFromAllRefs
1 parent 8611ef0 commit fef97c6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

‎test/git.js

+28
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,31 @@ test.serial('should not roll back with risky config', async t => {
322322
await gitClient.beforeRelease();
323323
t.is('rollbackOnce' in gitClient, false);
324324
});
325+
326+
test.serial('should return latest tag from default branch (not parent commit)', async t => {
327+
const gitClient = factory(Git, {
328+
options: { git: { getLatestTagFromAllRefs: true } }
329+
});
330+
sh.exec('git init');
331+
gitAdd('main', 'file', 'Add file in main');
332+
const defaultBranchName = await gitClient.getBranchName();
333+
const developBranchName = 'develop';
334+
const featureBranchPrefix = 'feature';
335+
await gitClient.tag({ name: '1.0.0' });
336+
sh.exec(`git branch ${developBranchName} ${defaultBranchName}`);
337+
sh.exec(`git checkout -b ${featureBranchPrefix}/first ${developBranchName}`);
338+
gitAdd('feature/1', 'file', 'Update file in feature branch (1)');
339+
sh.exec(`git checkout ${developBranchName}`);
340+
sh.exec(`git merge --no-ff ${featureBranchPrefix}/first`);
341+
await gitClient.tag({ name: '1.1.0-rc.1' });
342+
sh.exec(`git checkout ${defaultBranchName}`);
343+
sh.exec(`git merge --no-ff ${developBranchName}`);
344+
await gitClient.tag({ name: '1.1.0' });
345+
sh.exec(`git checkout -b ${featureBranchPrefix}/second ${developBranchName}`);
346+
gitAdd('feature/2', 'file', 'Update file again, in feature branch (2)');
347+
sh.exec(`git checkout ${developBranchName}`);
348+
sh.exec(`git merge --no-ff ${featureBranchPrefix}/second`);
349+
{
350+
t.is(await gitClient.getLatestTagName(), '1.1.0');
351+
}
352+
});

0 commit comments

Comments
 (0)
Please sign in to comment.