diff --git a/lib/closePR.js b/lib/closePR.js index 6239d4e..f8d8045 100644 --- a/lib/closePR.js +++ b/lib/closePR.js @@ -16,7 +16,7 @@ module.exports = async ({ dependents }) => { const branch = await context.getTestingBranchName(parentBranchName) const resp = await github.getChecks(dependentPkgInfo.owner, dependentPkgInfo.name, branch) const closedPR = await closeDependencyPR(dependentPkgInfo.owner, dependentPkgInfo.name, branch, resp.data.check_runs) - if (closedPR) { + if (closedPR && closedPR.length) { closedPrs.push(closedPR) } } diff --git a/test/cli/closePR.js b/test/cli/closePR.js index 02ce01b..c187380 100644 --- a/test/cli/closePR.js +++ b/test/cli/closePR.js @@ -40,4 +40,14 @@ tap.test('closePRs command', async (t) => { }).toString() t.match(result, '1 PRs closed\n') }) + t.test('close-pr with no result as PR was failing', async (t) => { + const result = childProcess.execSync(`${wibyCommand} close-pr`, { + env: { + ...process.env, + NODE_OPTIONS: `-r ${fixturesPath}/http/close-pr-command-no-positive.js` + } + }).toString() + console.log(`pattern was => ${result}`) + t.match(result, '0 PRs closed\n') + }) }) diff --git a/test/fixtures/http/close-pr-command-no-positive.js b/test/fixtures/http/close-pr-command-no-positive.js new file mode 100644 index 0000000..1c7fa00 --- /dev/null +++ b/test/fixtures/http/close-pr-command-no-positive.js @@ -0,0 +1,45 @@ +'use strict' + +/* + Mocks of HTTP calls for close-pr command + */ +const nock = require('nock') + +nock.disableNetConnect() + +function nockRepo (nockInstance, owner, repo, branch) { + return nockInstance + // /repos/{owner}/{repo}/commits/{ref}/check-runs + .get(`/repos/${owner}/${repo}/commits/${branch}/check-runs`) + .reply(200, { + check_runs: [ + { + status: 'completed', + conclusion: 'failure', + pull_requests: [{ + number: 1, + head: { + ref: branch + } + }, { + status: 'completed', + conclusion: 'failure', + number: 2, + head: { + ref: 'any-other-branch' + } + }] + } + ] + }) +} + +function buildNock () { + let nockInstance = nock('https://api.github.com') + + nockInstance = nockRepo(nockInstance, 'wiby-test', 'fakeRepo', 'wiby-running-unit-tests') + nockInstance = nockRepo(nockInstance, 'wiby-test', 'pass', 'wiby-running-unit-tests') + return nockInstance +} + +buildNock()