Skip to content

Commit

Permalink
Extend test for getLatestTagFromAllRefs to assert default behavior too
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jul 8, 2023
1 parent fef97c6 commit 930e80a
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions test/git.js
Expand Up @@ -324,29 +324,35 @@ test.serial('should not roll back with risky config', async t => {
});

test.serial('should return latest tag from default branch (not parent commit)', async t => {
const gitClient = factory(Git, {
options: { git: { getLatestTagFromAllRefs: true } }
});
sh.exec('git init');
gitAdd('main', 'file', 'Add file in main');
const defaultBranchName = await gitClient.getBranchName();
const developBranchName = 'develop';
const featureBranchPrefix = 'feature';
await gitClient.tag({ name: '1.0.0' });
sh.exec(`git branch ${developBranchName} ${defaultBranchName}`);
sh.exec(`git checkout -b ${featureBranchPrefix}/first ${developBranchName}`);
gitAdd('feature/1', 'file', 'Update file in feature branch (1)');
sh.exec(`git checkout ${developBranchName}`);
sh.exec(`git merge --no-ff ${featureBranchPrefix}/first`);
await gitClient.tag({ name: '1.1.0-rc.1' });
sh.exec(`git checkout ${defaultBranchName}`);
sh.exec(`git merge --no-ff ${developBranchName}`);
await gitClient.tag({ name: '1.1.0' });
sh.exec(`git checkout -b ${featureBranchPrefix}/second ${developBranchName}`);
gitAdd('feature/2', 'file', 'Update file again, in feature branch (2)');
sh.exec(`git checkout ${developBranchName}`);
sh.exec(`git merge --no-ff ${featureBranchPrefix}/second`);

{
const options = { git: { getLatestTagFromAllRefs: true } };
const gitClient = factory(Git, { options });
gitAdd('main', 'file', 'Add file in main');
const defaultBranchName = await gitClient.getBranchName();
const developBranchName = 'develop';
const featureBranchPrefix = 'feature';
await gitClient.tag({ name: '1.0.0' });
sh.exec(`git branch ${developBranchName} ${defaultBranchName}`);
sh.exec(`git checkout -b ${featureBranchPrefix}/first ${developBranchName}`);
gitAdd('feature/1', 'file', 'Update file in feature branch (1)');
sh.exec(`git checkout ${developBranchName}`);
sh.exec(`git merge --no-ff ${featureBranchPrefix}/first`);
await gitClient.tag({ name: '1.1.0-rc.1' });
sh.exec(`git checkout ${defaultBranchName}`);
sh.exec(`git merge --no-ff ${developBranchName}`);
await gitClient.tag({ name: '1.1.0' });
sh.exec(`git checkout -b ${featureBranchPrefix}/second ${developBranchName}`);
gitAdd('feature/2', 'file', 'Update file again, in feature branch (2)');
sh.exec(`git checkout ${developBranchName}`);
sh.exec(`git merge --no-ff ${featureBranchPrefix}/second`);
t.is(await gitClient.getLatestTagName(), '1.1.0');
}

{
const options = { git: { getLatestTagFromAllRefs: false } };
const gitClient = factory(Git, { options });
t.is(await gitClient.getLatestTagName(), '1.1.0-rc.1');
}
});

0 comments on commit 930e80a

Please sign in to comment.