From daa0d8f2450a150486d0bac70cf488ff3af1b284 Mon Sep 17 00:00:00 2001 From: tasshi / Masaharu TASHIRO <33759872+mshrtsr@users.noreply.github.com> Date: Tue, 19 Jul 2022 07:39:23 +0900 Subject: [PATCH] test: fix `createPullRequestsFake()` returns wrong values (#521) test: fix createPullRequestsFake() returns wrong values Co-authored-by: Jeff Ching --- test/release-please.js | 92 +++++++++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/test/release-please.js b/test/release-please.js index 0c08ee8..688237c 100644 --- a/test/release-please.js +++ b/test/release-please.js @@ -25,6 +25,27 @@ const defaultInput = { 'draft-pull-request': 'false' } +const fixturePrs = [ + { + headBranchName: 'release-please--branches--main', + baseBranchName: 'main', + number: 22, + title: 'chore(master): release 1.0.0', + body: ':robot: I have created a release *beep* *boop*', + labels: ['autorelease: pending'], + files: [] + }, + { + headBranchName: 'release-please--branches--main', + baseBranchName: 'main', + number: 23, + title: 'chore(master): release 1.0.0', + body: ':robot: I have created a release *beep* *boop*', + labels: ['autorelease: pending'], + files: [] + } +] + let input let output @@ -55,7 +76,7 @@ describe('release-please-action', () => { if (trueValue.includes(val)) { return true } if (falseValue.includes(val)) { return false } throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` + - 'Support boolean input list: `true | True | TRUE | false | False | FALSE`') + 'Support boolean input list: `true | True | TRUE | false | False | FALSE`') } // Default branch lookup: nock('https://api.github.com') @@ -76,7 +97,7 @@ describe('release-please-action', () => { '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]' } - const createPullRequestsFake = sandbox.fake.returns([22]) + const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]]) const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({ createPullRequests: createPullRequestsFake }) @@ -104,7 +125,7 @@ describe('release-please-action', () => { 'pull-request-title-pattern': 'beep boop' } - const createPullRequestsFake = sandbox.fake.returns([22]) + const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]]) const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({ createPullRequests: createPullRequestsFake }) @@ -132,7 +153,7 @@ describe('release-please-action', () => { tagName: 'v1.0.0' } ]) - const createPullRequestsFake = sandbox.fake.returns([22]) + const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]]) const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({ createPullRequests: createPullRequestsFake, createReleases: createReleasesFake @@ -142,15 +163,16 @@ describe('release-please-action', () => { sinon.assert.calledTwice(createManifestCommand) sinon.assert.calledOnce(createPullRequestsFake) sinon.assert.calledOnce(createReleasesFake) - assert.deepStrictEqual(output, { + const { prs, ...outputWithoutPrs } = output + assert.deepStrictEqual(outputWithoutPrs, { release_created: true, upload_url: 'http://example.com', tag_name: 'v1.0.0', - pr: 22, - prs: '[22]', + pr: fixturePrs[0], releases_created: true, paths_released: '["."]' }) + assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]]) }) it('both opens PR to a different default branch and tags GitHub releases by default', async () => { @@ -164,7 +186,7 @@ describe('release-please-action', () => { tag_name: 'v1.0.0' } ]) - const createPullRequestsFake = sandbox.fake.returns([22]) + const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]]) const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({ createPullRequests: createPullRequestsFake, createReleases: createReleasesFake @@ -180,15 +202,16 @@ describe('release-please-action', () => { sinon.match.any, sinon.match.any ) - assert.deepStrictEqual(output, { + const { prs, ...outputWithoutPrs } = output + assert.deepStrictEqual(outputWithoutPrs, { release_created: true, upload_url: 'http://example.com', tag_name: 'v1.0.0', - pr: 22, - prs: '[22]', + pr: fixturePrs[0], releases_created: true, paths_released: '["."]' }) + assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]]) }) it('only opens PR, if command set to release-pr', async () => { @@ -202,7 +225,7 @@ describe('release-please-action', () => { tag_name: 'v1.0.0' } ]) - const createPullRequestsFake = sandbox.fake.returns([22]) + const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]]) const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({ createPullRequests: createPullRequestsFake, createReleases: createReleasesFake @@ -212,10 +235,11 @@ describe('release-please-action', () => { sinon.assert.calledOnce(createManifestCommand) sinon.assert.calledOnce(createPullRequestsFake) sinon.assert.notCalled(createReleasesFake) - assert.deepStrictEqual(output, { - pr: 22, - prs: '[22]' + const { prs, ...outputWithoutPrs } = output + assert.deepStrictEqual(outputWithoutPrs, { + pr: fixturePrs[0] }) + assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]]) }) it('only creates GitHub release, if command set to github-release', async () => { @@ -229,7 +253,7 @@ describe('release-please-action', () => { tag_name: 'v1.0.0' } ]) - const createPullRequestsFake = sandbox.fake.returns([22]) + const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]]) const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({ createPullRequests: createPullRequestsFake, createReleases: createReleasesFake @@ -290,7 +314,7 @@ describe('release-please-action', () => { 'release-type': 'node', command: 'release-pr' } - const createPullRequestsFake = sandbox.fake.returns([22]) + const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]]) const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({ createPullRequests: createPullRequestsFake }) @@ -298,10 +322,11 @@ describe('release-please-action', () => { sinon.assert.calledOnce(createManifestCommand) sinon.assert.calledOnce(createPullRequestsFake) - assert.deepStrictEqual(output, { - pr: 22, - prs: '[22]' + const { prs, ...outputWithoutPrs } = output + assert.deepStrictEqual(outputWithoutPrs, { + pr: fixturePrs[0] }) + assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]]) }) it('does not set PR output, when no release PR is returned', async () => { @@ -340,7 +365,7 @@ describe('release-please-action', () => { tag_name: 'v1.0.0' } ]) - const createPullRequestsFake = sandbox.fake.returns([22]) + const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]]) const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({ createPullRequests: createPullRequestsFake, createReleases: createReleasesFake @@ -356,20 +381,21 @@ describe('release-please-action', () => { sinon.match.any, sinon.match.any ) - assert.deepStrictEqual(output, { + const { prs, ...outputWithoutPrs } = output + assert.deepStrictEqual(outputWithoutPrs, { release_created: true, upload_url: 'http://example.com', tag_name: 'v1.0.0', - pr: 22, - prs: '[22]', + pr: fixturePrs[0], releases_created: true, paths_released: '["."]' }) + assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]]) }) it('opens PR only for manifest-pr', async () => { input = { command: 'manifest-pr' } - const createPullRequestsFake = sandbox.fake.returns([22]) + const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]]) const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({ createPullRequests: createPullRequestsFake }) @@ -383,10 +409,11 @@ describe('release-please-action', () => { sinon.match.any, sinon.match.any ) - assert.deepStrictEqual(output, { - pr: 22, - prs: '[22]' + const { prs, ...outputWithoutPrs } = output + assert.deepStrictEqual(outputWithoutPrs, { + pr: fixturePrs[0] }) + assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]]) }) it('sets appropriate output if multiple releases and prs created', async () => { @@ -403,7 +430,7 @@ describe('release-please-action', () => { path: 'b' } ]) - const createPullRequestsFake = sandbox.fake.returns([22, 33]) + const createPullRequestsFake = sandbox.fake.returns(fixturePrs) const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({ createPullRequests: createPullRequestsFake, createReleases: createReleasesFake @@ -419,9 +446,9 @@ describe('release-please-action', () => { sinon.match.any, sinon.match.any ) - assert.deepStrictEqual(output, { - pr: 22, - prs: '[22,33]', + const { prs, ...outputWithoutPrs } = output + assert.deepStrictEqual(outputWithoutPrs, { + pr: fixturePrs[0], releases_created: true, 'a--release_created': true, 'a--upload_url': 'http://example.com', @@ -433,5 +460,6 @@ describe('release-please-action', () => { 'b--path': 'b', paths_released: '["a","b"]' }) + assert.deepStrictEqual(JSON.parse(prs), fixturePrs) }) })