-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add basic test coverage for codecov score calculation
- Loading branch information
Filip Maj
committed
May 15, 2024
1 parent
1f6551b
commit 27cfeba
Showing
3 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { assert } = require('chai'); | ||
const sinon = require('sinon'); | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
const codecov = require('@api/codecov'); | ||
const cov = require('../../src/score_components/coverage'); | ||
|
||
describe('score component: code coverage', () => { | ||
const fakeCore = sinon.stub(core); | ||
const fakeGithub = sinon.stub(github); | ||
const fakeCodecov = sinon.stub(codecov); | ||
const originalGithubContext = fakeGithub.context; | ||
beforeEach(() => { | ||
sinon.reset(); | ||
fakeCore.info.callsFake(console.log); | ||
fakeCore.error.callsFake(console.error); | ||
fakeGithub.context = originalGithubContext; | ||
}); | ||
|
||
it('should export a function', () => { | ||
assert.isFunction(cov); | ||
}); | ||
it('should return 0 if no `codecov_token` input provided', async () => { | ||
fakeCore.getInput.withArgs('codecov_token').returns(null); | ||
const res = await cov(fakeCore, fakeGithub); | ||
assert.equal(res, 0); | ||
}); | ||
it('should return total number of missed lines from codecov API response', async () => { | ||
fakeCore.getInput.withArgs('codecov_token').returns('abcd1234'); | ||
fakeGithub.context = { | ||
eventName: 'pull_request', | ||
payload: { | ||
after: 'abcd1234', | ||
}, | ||
repo: { | ||
owner: 'slackapi', | ||
repo: 'slack-health-score', | ||
}, | ||
}; | ||
fakeCodecov.repos_commits_retrieve.resolves({ | ||
data: { | ||
totals: { | ||
misses: 1337, | ||
}, | ||
}, | ||
}); | ||
const res = await cov(fakeCore, fakeGithub); | ||
assert.equal(res, 1337); | ||
}); | ||
}); |