mirror of
https://github.com/joaquinjsb/gitea-release-please-action
synced 2026-05-12 23:51:35 +02:00
test: fix createPullRequestsFake() returns wrong values (#521)
test: fix createPullRequestsFake() returns wrong values Co-authored-by: Jeff Ching <chingor@google.com>
This commit is contained in:
committed by
GitHub
parent
c4bc4b336c
commit
daa0d8f245
@@ -25,6 +25,27 @@ const defaultInput = {
|
|||||||
'draft-pull-request': 'false'
|
'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 input
|
||||||
let output
|
let output
|
||||||
|
|
||||||
@@ -55,7 +76,7 @@ describe('release-please-action', () => {
|
|||||||
if (trueValue.includes(val)) { return true }
|
if (trueValue.includes(val)) { return true }
|
||||||
if (falseValue.includes(val)) { return false }
|
if (falseValue.includes(val)) { return false }
|
||||||
throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name}\n` +
|
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:
|
// Default branch lookup:
|
||||||
nock('https://api.github.com')
|
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}]'
|
'[{"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({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||||
createPullRequests: createPullRequestsFake
|
createPullRequests: createPullRequestsFake
|
||||||
})
|
})
|
||||||
@@ -104,7 +125,7 @@ describe('release-please-action', () => {
|
|||||||
'pull-request-title-pattern': 'beep boop'
|
'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({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||||
createPullRequests: createPullRequestsFake
|
createPullRequests: createPullRequestsFake
|
||||||
})
|
})
|
||||||
@@ -132,7 +153,7 @@ describe('release-please-action', () => {
|
|||||||
tagName: 'v1.0.0'
|
tagName: 'v1.0.0'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]])
|
||||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||||
createPullRequests: createPullRequestsFake,
|
createPullRequests: createPullRequestsFake,
|
||||||
createReleases: createReleasesFake
|
createReleases: createReleasesFake
|
||||||
@@ -142,15 +163,16 @@ describe('release-please-action', () => {
|
|||||||
sinon.assert.calledTwice(createManifestCommand)
|
sinon.assert.calledTwice(createManifestCommand)
|
||||||
sinon.assert.calledOnce(createPullRequestsFake)
|
sinon.assert.calledOnce(createPullRequestsFake)
|
||||||
sinon.assert.calledOnce(createReleasesFake)
|
sinon.assert.calledOnce(createReleasesFake)
|
||||||
assert.deepStrictEqual(output, {
|
const { prs, ...outputWithoutPrs } = output
|
||||||
|
assert.deepStrictEqual(outputWithoutPrs, {
|
||||||
release_created: true,
|
release_created: true,
|
||||||
upload_url: 'http://example.com',
|
upload_url: 'http://example.com',
|
||||||
tag_name: 'v1.0.0',
|
tag_name: 'v1.0.0',
|
||||||
pr: 22,
|
pr: fixturePrs[0],
|
||||||
prs: '[22]',
|
|
||||||
releases_created: true,
|
releases_created: true,
|
||||||
paths_released: '["."]'
|
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 () => {
|
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'
|
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({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||||
createPullRequests: createPullRequestsFake,
|
createPullRequests: createPullRequestsFake,
|
||||||
createReleases: createReleasesFake
|
createReleases: createReleasesFake
|
||||||
@@ -180,15 +202,16 @@ describe('release-please-action', () => {
|
|||||||
sinon.match.any,
|
sinon.match.any,
|
||||||
sinon.match.any
|
sinon.match.any
|
||||||
)
|
)
|
||||||
assert.deepStrictEqual(output, {
|
const { prs, ...outputWithoutPrs } = output
|
||||||
|
assert.deepStrictEqual(outputWithoutPrs, {
|
||||||
release_created: true,
|
release_created: true,
|
||||||
upload_url: 'http://example.com',
|
upload_url: 'http://example.com',
|
||||||
tag_name: 'v1.0.0',
|
tag_name: 'v1.0.0',
|
||||||
pr: 22,
|
pr: fixturePrs[0],
|
||||||
prs: '[22]',
|
|
||||||
releases_created: true,
|
releases_created: true,
|
||||||
paths_released: '["."]'
|
paths_released: '["."]'
|
||||||
})
|
})
|
||||||
|
assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('only opens PR, if command set to release-pr', async () => {
|
it('only opens PR, if command set to release-pr', async () => {
|
||||||
@@ -202,7 +225,7 @@ describe('release-please-action', () => {
|
|||||||
tag_name: 'v1.0.0'
|
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({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||||
createPullRequests: createPullRequestsFake,
|
createPullRequests: createPullRequestsFake,
|
||||||
createReleases: createReleasesFake
|
createReleases: createReleasesFake
|
||||||
@@ -212,10 +235,11 @@ describe('release-please-action', () => {
|
|||||||
sinon.assert.calledOnce(createManifestCommand)
|
sinon.assert.calledOnce(createManifestCommand)
|
||||||
sinon.assert.calledOnce(createPullRequestsFake)
|
sinon.assert.calledOnce(createPullRequestsFake)
|
||||||
sinon.assert.notCalled(createReleasesFake)
|
sinon.assert.notCalled(createReleasesFake)
|
||||||
assert.deepStrictEqual(output, {
|
const { prs, ...outputWithoutPrs } = output
|
||||||
pr: 22,
|
assert.deepStrictEqual(outputWithoutPrs, {
|
||||||
prs: '[22]'
|
pr: fixturePrs[0]
|
||||||
})
|
})
|
||||||
|
assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('only creates GitHub release, if command set to github-release', async () => {
|
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'
|
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({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||||
createPullRequests: createPullRequestsFake,
|
createPullRequests: createPullRequestsFake,
|
||||||
createReleases: createReleasesFake
|
createReleases: createReleasesFake
|
||||||
@@ -290,7 +314,7 @@ describe('release-please-action', () => {
|
|||||||
'release-type': 'node',
|
'release-type': 'node',
|
||||||
command: 'release-pr'
|
command: 'release-pr'
|
||||||
}
|
}
|
||||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]])
|
||||||
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromConfig').returns({
|
||||||
createPullRequests: createPullRequestsFake
|
createPullRequests: createPullRequestsFake
|
||||||
})
|
})
|
||||||
@@ -298,10 +322,11 @@ describe('release-please-action', () => {
|
|||||||
|
|
||||||
sinon.assert.calledOnce(createManifestCommand)
|
sinon.assert.calledOnce(createManifestCommand)
|
||||||
sinon.assert.calledOnce(createPullRequestsFake)
|
sinon.assert.calledOnce(createPullRequestsFake)
|
||||||
assert.deepStrictEqual(output, {
|
const { prs, ...outputWithoutPrs } = output
|
||||||
pr: 22,
|
assert.deepStrictEqual(outputWithoutPrs, {
|
||||||
prs: '[22]'
|
pr: fixturePrs[0]
|
||||||
})
|
})
|
||||||
|
assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not set PR output, when no release PR is returned', async () => {
|
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'
|
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({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({
|
||||||
createPullRequests: createPullRequestsFake,
|
createPullRequests: createPullRequestsFake,
|
||||||
createReleases: createReleasesFake
|
createReleases: createReleasesFake
|
||||||
@@ -356,20 +381,21 @@ describe('release-please-action', () => {
|
|||||||
sinon.match.any,
|
sinon.match.any,
|
||||||
sinon.match.any
|
sinon.match.any
|
||||||
)
|
)
|
||||||
assert.deepStrictEqual(output, {
|
const { prs, ...outputWithoutPrs } = output
|
||||||
|
assert.deepStrictEqual(outputWithoutPrs, {
|
||||||
release_created: true,
|
release_created: true,
|
||||||
upload_url: 'http://example.com',
|
upload_url: 'http://example.com',
|
||||||
tag_name: 'v1.0.0',
|
tag_name: 'v1.0.0',
|
||||||
pr: 22,
|
pr: fixturePrs[0],
|
||||||
prs: '[22]',
|
|
||||||
releases_created: true,
|
releases_created: true,
|
||||||
paths_released: '["."]'
|
paths_released: '["."]'
|
||||||
})
|
})
|
||||||
|
assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('opens PR only for manifest-pr', async () => {
|
it('opens PR only for manifest-pr', async () => {
|
||||||
input = { command: 'manifest-pr' }
|
input = { command: 'manifest-pr' }
|
||||||
const createPullRequestsFake = sandbox.fake.returns([22])
|
const createPullRequestsFake = sandbox.fake.returns([fixturePrs[0]])
|
||||||
const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({
|
||||||
createPullRequests: createPullRequestsFake
|
createPullRequests: createPullRequestsFake
|
||||||
})
|
})
|
||||||
@@ -383,10 +409,11 @@ describe('release-please-action', () => {
|
|||||||
sinon.match.any,
|
sinon.match.any,
|
||||||
sinon.match.any
|
sinon.match.any
|
||||||
)
|
)
|
||||||
assert.deepStrictEqual(output, {
|
const { prs, ...outputWithoutPrs } = output
|
||||||
pr: 22,
|
assert.deepStrictEqual(outputWithoutPrs, {
|
||||||
prs: '[22]'
|
pr: fixturePrs[0]
|
||||||
})
|
})
|
||||||
|
assert.deepStrictEqual(JSON.parse(prs), [fixturePrs[0]])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sets appropriate output if multiple releases and prs created', async () => {
|
it('sets appropriate output if multiple releases and prs created', async () => {
|
||||||
@@ -403,7 +430,7 @@ describe('release-please-action', () => {
|
|||||||
path: 'b'
|
path: 'b'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
const createPullRequestsFake = sandbox.fake.returns([22, 33])
|
const createPullRequestsFake = sandbox.fake.returns(fixturePrs)
|
||||||
const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({
|
const createManifestCommand = sandbox.stub(Manifest, 'fromManifest').returns({
|
||||||
createPullRequests: createPullRequestsFake,
|
createPullRequests: createPullRequestsFake,
|
||||||
createReleases: createReleasesFake
|
createReleases: createReleasesFake
|
||||||
@@ -419,9 +446,9 @@ describe('release-please-action', () => {
|
|||||||
sinon.match.any,
|
sinon.match.any,
|
||||||
sinon.match.any
|
sinon.match.any
|
||||||
)
|
)
|
||||||
assert.deepStrictEqual(output, {
|
const { prs, ...outputWithoutPrs } = output
|
||||||
pr: 22,
|
assert.deepStrictEqual(outputWithoutPrs, {
|
||||||
prs: '[22,33]',
|
pr: fixturePrs[0],
|
||||||
releases_created: true,
|
releases_created: true,
|
||||||
'a--release_created': true,
|
'a--release_created': true,
|
||||||
'a--upload_url': 'http://example.com',
|
'a--upload_url': 'http://example.com',
|
||||||
@@ -433,5 +460,6 @@ describe('release-please-action', () => {
|
|||||||
'b--path': 'b',
|
'b--path': 'b',
|
||||||
paths_released: '["a","b"]'
|
paths_released: '["a","b"]'
|
||||||
})
|
})
|
||||||
|
assert.deepStrictEqual(JSON.parse(prs), fixturePrs)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user