123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- /**
- * Module dependencies.
- */
- var JSONCov = require('./json-cov')
- , fs = require('fs');
- /**
- * Expose `HTMLCov`.
- */
- exports = module.exports = HTMLCov;
- /**
- * Initialize a new `JsCoverage` reporter.
- *
- * @param {Runner} runner
- * @api public
- */
- function HTMLCov(runner) {
- var jade = require('jade')
- , file = __dirname + '/templates/coverage.jade'
- , str = fs.readFileSync(file, 'utf8')
- , fn = jade.compile(str, { filename: file })
- , self = this;
- JSONCov.call(this, runner, false);
- runner.on('end', function(){
- process.stdout.write(fn({
- cov: self.cov
- , coverageClass: coverageClass
- }));
- });
- }
- /**
- * Return coverage class for `n`.
- *
- * @return {String}
- * @api private
- */
- function coverageClass(n) {
- if (n >= 75) return 'high';
- if (n >= 50) return 'medium';
- if (n >= 25) return 'low';
- return 'terrible';
- }
|