Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update how we track coverage during unit tests (#5779)
* chore: update how we track coverage during unit tests The old method of tracking coverage was causing issues. If a test failed on CI, that test's failure would be lost because the test failing would in turn cause the coverage to fail, but the `process.exit(1)` in the coverage code caused Mocha to not output anything useful. Instead the coverage checker now: * tracks the coverage in memory in a Map (this hasn't changed) * after all tests, writes that to disk in test/coverage.json (which is gitignored) * we then run a single Mocha test that asserts every method was called. This means if the test run fails, the build will fail and give the error about that test run, and that output won't be lost when the coverage then fails too. Co-authored-by: Mathias Bynens <mathias@qiwi.be>
- Loading branch information
1 parent
4a47867
commit 5518bac
Showing
8 changed files
with
76 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ yarn.lock | |
/utils/browser/puppeteer-web.js | ||
/index.d.ts | ||
/lib | ||
test/coverage.json |
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,6 @@ | ||
const base = require('./base'); | ||
|
||
module.exports = { | ||
...base, | ||
spec: 'test/assert-coverage-test.js', | ||
}; |
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,24 @@ | ||
const {describe, it} = require('mocha'); | ||
const {getCoverageResults} = require('./coverage-utils'); | ||
const expect = require('expect'); | ||
|
||
describe('API coverage test', () => { | ||
it('calls every method', () => { | ||
if (!process.env.COVERAGE) return; | ||
|
||
const coverageMap = getCoverageResults(); | ||
const missingMethods = []; | ||
for (const method of coverageMap.keys()) { | ||
if (!coverageMap.get(method)) | ||
missingMethods.push(method); | ||
} | ||
if (missingMethods.length) { | ||
console.error('\nCoverage check failed: not all API methods called. See above output for list of missing methods.'); | ||
console.error(missingMethods.join('\n')); | ||
} | ||
|
||
// We know this will fail because we checked above | ||
// but we need the actual test to fail. | ||
expect(missingMethods.length).toEqual(0); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.