From a6f6efff0b25ac46d2e3275929576da749dfc156 Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Tue, 9 Aug 2022 13:47:06 +0200 Subject: [PATCH] Add tests for branchName in tag name --- test/git.js | 4 ++-- test/github.js | 2 +- test/gitlab.js | 4 ++-- test/tasks.js | 36 ++++++++++++++++++++++++++++++++++++ test/util/helpers.js | 5 ++++- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/test/git.js b/test/git.js index c3a8c79d..1fbe8a1e 100644 --- a/test/git.js +++ b/test/git.js @@ -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 => { diff --git a/test/github.js b/test/github.js index d3bd7de3..9a47ffc6 100644 --- a/test/github.js +++ b/test/github.js @@ -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); diff --git a/test/gitlab.js b/test/gitlab.js index 929ba6af..f688c631 100644 --- a/test/gitlab.js +++ b/test/gitlab.js @@ -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(); diff --git a/test/tasks.js b/test/tasks.js index dbd843ec..671c63e6 100644 --- a/test/tasks.js +++ b/test/tasks.js @@ -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); diff --git a/test/util/helpers.js b/test/util/helpers.js index 5b97e32d..e4afd48d 100644 --- a/test/util/helpers.js +++ b/test/util/helpers.js @@ -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 };