Skip to content

Commit

Permalink
Add tests for branchName in tag name
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Aug 9, 2022
1 parent ae9ccb9 commit a6f6eff
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions test/git.js
Expand Up @@ -294,8 +294,8 @@ test.serial('should roll back when cancelled', async t => {
await gitClient.tag();
await gitClient.rollbackOnce();

t.is(exec.args[10][0], 'git tag --delete v1.2.4');
t.is(exec.args[11][0], 'git reset --hard HEAD~1');
t.is(exec.args[11][0], 'git tag --delete v1.2.4');
t.is(exec.args[12][0], 'git reset --hard HEAD~1');
});

test.serial('should not touch existing history when rolling back', async t => {
Expand Down
2 changes: 1 addition & 1 deletion test/github.js
Expand Up @@ -357,7 +357,7 @@ test('should not call octokit client in dry run', async t => {
await runTasks(github);

t.is(spy.get.callCount, 0);
t.is(github.log.exec.args[0][0], 'octokit repos.createRelease "R 1.0.1" (v1.0.1)');
t.is(github.log.exec.args[1][0], 'octokit repos.createRelease "R 1.0.1" (v1.0.1)');
t.is(github.log.exec.lastCall.args[0], 'octokit repos.uploadReleaseAssets');
const { isReleased, releaseUrl } = github.getContext();
t.true(isReleased);
Expand Down
4 changes: 2 additions & 2 deletions test/gitlab.js
Expand Up @@ -231,8 +231,8 @@ test('should not make requests in dry run', async t => {

const { isReleased, releaseUrl } = gitlab.getContext();
t.is(spy.get.callCount, 0);
t.is(gitlab.log.exec.args[1][0], 'gitlab releases#uploadAssets');
t.is(gitlab.log.exec.args[2][0], 'gitlab releases#createRelease "R" (1.0.1)');
t.is(gitlab.log.exec.args[2][0], 'gitlab releases#uploadAssets');
t.is(gitlab.log.exec.args[3][0], 'gitlab releases#createRelease "R" (1.0.1)');
t.true(isReleased);
t.is(releaseUrl, `${pushRepo}/-/releases`);
spy.get.restore();
Expand Down
36 changes: 36 additions & 0 deletions test/tasks.js
Expand Up @@ -186,6 +186,42 @@ test.serial('should release all the things (basic)', async t => {
exec.restore();
});

test.serial('should release with correct tag name', async t => {
const { bare, target } = t.context;
const project = path.basename(bare);
const pkgName = path.basename(target);
const owner = path.basename(path.dirname(bare));
const { stdout } = sh.exec('git rev-parse --abbrev-ref HEAD');
const branchName = stdout.trim();
gitAdd(`{"name":"${pkgName}","version":"1.0.0"}`, 'package.json', 'Add package.json');
sh.exec(`git tag ${branchName}-1.0.0`);
const sha = gitAdd('line', 'file', 'More file');

interceptGitHubCreate({
owner,
project,
body: { tag_name: `${branchName}-1.0.1`, name: 'Release 1.0.1', body: `* More file (${sha})`, prerelease: false }
});

const container = getContainer({
git: { tagName: '${branchName}-${version}' },
github: { release: true, skipChecks: true, pushRepo: `https://github.com/${owner}/${project}` }
});

const exec = sinon.spy(container.shell, 'exec');

await runTasks({}, container);

const gitArgs = getArgs(container.shell.exec.args, 'git');

t.true(gitArgs.includes(`git tag --annotate --message Release 1.0.1 ${branchName}-1.0.1`));
t.true(
log.log.secondCall.args[0].endsWith(`https://github.com/${owner}/${project}/releases/tag/${branchName}-1.0.1`)
);

exec.restore();
});

test.serial('should release all the things (pre-release, github, gitlab)', async t => {
const { bare, target } = t.context;
const project = path.basename(bare);
Expand Down
5 changes: 4 additions & 1 deletion test/util/helpers.js
Expand Up @@ -19,6 +19,9 @@ const gitAdd = (content, file, message) => {
};

const getArgs = (args, prefix) =>
args.filter(args => typeof args[0] === 'string' && args[0].startsWith(prefix)).map(args => args[0].trim());
args
.map(args => (typeof args[0] !== 'string' ? args[0].join(' ') : args[0]))
.filter(cmd => cmd.startsWith(prefix))
.map(cmd => cmd.trim());

export { mkTmpDir, readFile, gitAdd, getArgs };

0 comments on commit a6f6eff

Please sign in to comment.