Created
April 19, 2018 13:00
-
-
Save akoppela/7ffe4cd2c3797a236f73be000d15e21c to your computer and use it in GitHub Desktop.
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
gulp.task('elm:coverage', function () { | |
var coverageHtml = new jsdom.JSDOM(fs.readFileSync(PATH_COVERAGE + 'coverage.html').toString()), | |
mainOverview = coverageHtml.window.document.getElementsByClassName('overview')[0], | |
mainOverviewBodyRows = Array.from(mainOverview.querySelectorAll('tbody tr')); | |
var errors = mainOverviewBodyRows.reduce(function (accumulator, row) { | |
var result = Array.from(row.querySelectorAll('td')).reduce(function (accumulator, cell) { | |
var progress = cell.querySelector('progress'); | |
if (progress) { | |
var value = progress.getAttribute('value'), | |
max = progress.getAttribute('max'); | |
if (value !== max) { | |
accumulator.hasErrors = true; | |
accumulator.values.push(value / max * 100 + '%'); | |
} | |
} else { | |
accumulator.values.push('n/a'); | |
} | |
return accumulator; | |
}, { hasErrors: false, values: [] }); | |
if (result.hasErrors) { | |
var moduleName = row.querySelector('th code').innerHTML; | |
result.values.unshift(moduleName); | |
accumulator.push(result.values); | |
} | |
return accumulator; | |
}, []); | |
if (errors.length) { | |
var firstRow = ['Module', 'case branches', 'Declarations', 'if/else branches', 'Lambdas', 'let declarations']; | |
console.log('\n**** Modules below are required to have 100% coverage ****\n'); | |
console.log(table.table([firstRow].concat(errors))); | |
throw 'Modules above are required to have 100% coverage'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment