Last active
February 5, 2020 08:55
-
-
Save dyaa/f5b729385f966ecdc1bcc60ee0218dc7 to your computer and use it in GitHub Desktop.
Jest coverage collection from multi-project and merging them into single coverage .lcov file
This file contains hidden or 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
import fs from 'fs-extra'; | |
import glob from 'glob'; | |
import { exec } from 'child_process'; | |
const coverageOutputDir = '.nyc_output'; | |
fs.emptyDirSync(coverageOutputDir); | |
glob('**/coverage-final.json', (err, coverageFiles) => { | |
if (err) { | |
throw err; | |
} | |
if (!coverageFiles.length) { | |
throw new Error('Error finding coverage files'); | |
} | |
coverageFiles.forEach((coverageFile, index) => { | |
if (!coverageFile) { | |
throw new Error('Error finding coverage files'); | |
} | |
const [fileName, fileExtention] = (coverageFile | |
.split('/') | |
.pop() as string).split('.'); | |
const destination = `${coverageOutputDir}/${fileName}-${index + | |
1}.${fileExtention}`; | |
fs.copyFile(coverageFile, destination, copyFileError => { | |
if (copyFileError) { | |
throw copyFileError; | |
} | |
// tslint:disable-next-line no-console | |
console.log(`${coverageFile} was copied to ${destination}`); | |
}); | |
}); | |
exec( | |
`./node_modules/nyc/bin/nyc.js report --reporter=lcov --report-dir=${coverageOutputDir}`, | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment