mirror of
https://github.com/wagoid/commitlint-github-action.git
synced 2025-11-07 16:06:56 +00:00
test: add output tests for PR scenario
This commit is contained in:
parent
231d02e17f
commit
0c7da1b0a2
1 changed files with 96 additions and 48 deletions
|
|
@ -247,61 +247,109 @@ describe('Commit Linter action', () => {
|
||||||
td.verify(core.setFailed(contains('wrong commit from another branch')))
|
td.verify(core.setFailed(contains('wrong commit from another branch')))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should lint all commits from a pull request', async () => {
|
describe('when there are multiple commits failing in the pull request', () => {
|
||||||
cwd = await git.bootstrap('fixtures/conventional')
|
let expectedResultsOutput
|
||||||
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
const firstMessage = 'wrong message 1'
|
||||||
await gitEmptyCommit(cwd, 'message from before push')
|
const secondMessage = 'wrong message 2'
|
||||||
await gitEmptyCommit(cwd, 'wrong message 1')
|
|
||||||
await gitEmptyCommit(cwd, 'wrong message 2')
|
|
||||||
await gitEmptyCommit(cwd, 'wrong message 3')
|
|
||||||
await createPullRequestEventPayload(cwd)
|
|
||||||
const [, first, second, to] = await getCommitHashes(cwd)
|
|
||||||
updatePullRequestEnvVars(cwd, to)
|
|
||||||
td.when(
|
|
||||||
listCommits({
|
|
||||||
owner: 'wagoid',
|
|
||||||
repo: 'commitlint-github-action',
|
|
||||||
pull_number: '1',
|
|
||||||
}),
|
|
||||||
).thenResolve({
|
|
||||||
data: [first, second, to].map(sha => ({ sha })),
|
|
||||||
})
|
|
||||||
td.replace(process, 'cwd', () => cwd)
|
|
||||||
|
|
||||||
await runAction()
|
beforeEach(async () => {
|
||||||
|
cwd = await git.bootstrap('fixtures/conventional')
|
||||||
|
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
||||||
|
await gitEmptyCommit(cwd, 'message from before push')
|
||||||
|
await gitEmptyCommit(cwd, firstMessage)
|
||||||
|
await gitEmptyCommit(cwd, secondMessage)
|
||||||
|
await createPullRequestEventPayload(cwd)
|
||||||
|
const [, first, to] = await getCommitHashes(cwd)
|
||||||
|
updatePullRequestEnvVars(cwd, to)
|
||||||
|
td.when(
|
||||||
|
listCommits({
|
||||||
|
owner: 'wagoid',
|
||||||
|
repo: 'commitlint-github-action',
|
||||||
|
pull_number: '1',
|
||||||
|
}),
|
||||||
|
).thenResolve({
|
||||||
|
data: [first, to].map(sha => ({ sha })),
|
||||||
|
})
|
||||||
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
|
||||||
td.verify(core.setFailed(contains('message from before push')), {
|
expectedResultsOutput = [
|
||||||
times: 0,
|
{
|
||||||
|
hash: to,
|
||||||
|
message: secondMessage,
|
||||||
|
valid: false,
|
||||||
|
errors: ['subject may not be empty', 'type may not be empty'],
|
||||||
|
warnings: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hash: first,
|
||||||
|
message: firstMessage,
|
||||||
|
valid: false,
|
||||||
|
errors: ['subject may not be empty', 'type may not be empty'],
|
||||||
|
warnings: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should NOT show errors for a message from before the push', async () => {
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
td.verify(core.setFailed(contains('message from before push')), {
|
||||||
|
times: 0,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should show errors for the first wrong message', async () => {
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
td.verify(core.setFailed(contains(firstMessage)))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should show errors for the second wrong message', async () => {
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
td.verify(core.setFailed(contains(secondMessage)))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should generate a JSON output of the errors', async () => {
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
td.verify(core.setOutput(resultsOutputId, expectedResultsOutput))
|
||||||
})
|
})
|
||||||
td.verify(core.setFailed(contains('wrong message 1')))
|
|
||||||
td.verify(core.setFailed(contains('wrong message 2')))
|
|
||||||
td.verify(core.setFailed(contains('wrong message 3')))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should show an error message when failing to fetch commits', async () => {
|
describe('when it fails to fetch commits', () => {
|
||||||
cwd = await git.bootstrap('fixtures/conventional')
|
beforeEach(async () => {
|
||||||
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
cwd = await git.bootstrap('fixtures/conventional')
|
||||||
await gitEmptyCommit(cwd, 'commit message')
|
td.when(core.getInput('configFile')).thenReturn('./commitlint.config.js')
|
||||||
await createPullRequestEventPayload(cwd)
|
await gitEmptyCommit(cwd, 'commit message')
|
||||||
const [to] = await getCommitHashes(cwd)
|
await createPullRequestEventPayload(cwd)
|
||||||
updatePullRequestEnvVars(cwd, to)
|
const [to] = await getCommitHashes(cwd)
|
||||||
td.when(
|
updatePullRequestEnvVars(cwd, to)
|
||||||
listCommits({
|
td.when(
|
||||||
owner: 'wagoid',
|
listCommits({
|
||||||
repo: 'commitlint-github-action',
|
owner: 'wagoid',
|
||||||
pull_number: '1',
|
repo: 'commitlint-github-action',
|
||||||
}),
|
pull_number: '1',
|
||||||
).thenReject(new Error('HttpError: Bad credentials'))
|
}),
|
||||||
td.replace(process, 'cwd', () => cwd)
|
).thenReject(new Error('HttpError: Bad credentials'))
|
||||||
|
td.replace(process, 'cwd', () => cwd)
|
||||||
|
})
|
||||||
|
|
||||||
await runAction()
|
it('should show an error message', async () => {
|
||||||
|
await runAction()
|
||||||
|
|
||||||
td.verify(
|
td.verify(
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
contains("error trying to get list of pull request's commits"),
|
contains("error trying to get list of pull request's commits"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
td.verify(core.setFailed(contains('HttpError: Bad credentials')))
|
})
|
||||||
|
|
||||||
|
it('should show the original error message', async () => {
|
||||||
|
await runAction()
|
||||||
|
|
||||||
|
td.verify(core.setFailed(contains('HttpError: Bad credentials')))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("when there's a single commit with correct message", () => {
|
describe("when there's a single commit with correct message", () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue