html-cov.js 876 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * Module dependencies.
  3. */
  4. var JSONCov = require('./json-cov')
  5. , fs = require('fs');
  6. /**
  7. * Expose `HTMLCov`.
  8. */
  9. exports = module.exports = HTMLCov;
  10. /**
  11. * Initialize a new `JsCoverage` reporter.
  12. *
  13. * @param {Runner} runner
  14. * @api public
  15. */
  16. function HTMLCov(runner) {
  17. var jade = require('jade')
  18. , file = __dirname + '/templates/coverage.jade'
  19. , str = fs.readFileSync(file, 'utf8')
  20. , fn = jade.compile(str, { filename: file })
  21. , self = this;
  22. JSONCov.call(this, runner, false);
  23. runner.on('end', function(){
  24. process.stdout.write(fn({
  25. cov: self.cov
  26. , coverageClass: coverageClass
  27. }));
  28. });
  29. }
  30. /**
  31. * Return coverage class for `n`.
  32. *
  33. * @return {String}
  34. * @api private
  35. */
  36. function coverageClass(n) {
  37. if (n >= 75) return 'high';
  38. if (n >= 50) return 'medium';
  39. if (n >= 25) return 'low';
  40. return 'terrible';
  41. }