index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Copyright 2012-2015, Yahoo Inc.
  3. Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
  4. */
  5. "use strict";
  6. function TextSummaryReport(opts) {
  7. opts = opts || {};
  8. this.file = opts.file || null;
  9. }
  10. function lineForKey(summary, key) {
  11. var metrics = summary[key],
  12. skipped,
  13. result;
  14. key = key.substring(0, 1).toUpperCase() + key.substring(1);
  15. if (key.length < 12) {
  16. key += ' '.substring(0, 12 - key.length);
  17. }
  18. result = [key, ':', metrics.pct + '%', '(', metrics.covered + '/' + metrics.total, ')'].join(' ');
  19. skipped = metrics.skipped;
  20. if (skipped > 0) {
  21. result += ', ' + skipped + ' ignored';
  22. }
  23. return result;
  24. }
  25. TextSummaryReport.prototype.onStart = function (node, context) {
  26. var summary = node.getCoverageSummary(),
  27. cw,
  28. printLine = function (key) {
  29. var str = lineForKey(summary, key),
  30. clazz = context.classForPercent(key, summary[key].pct);
  31. cw.println(cw.colorize(str, clazz));
  32. };
  33. cw = context.writer.writeFile(this.file);
  34. cw.println('');
  35. cw.println('=============================== Coverage summary ===============================');
  36. printLine('statements');
  37. printLine('branches');
  38. printLine('functions');
  39. printLine('lines');
  40. cw.println('================================================================================');
  41. cw.close();
  42. };
  43. module.exports = TextSummaryReport;