index.js 908 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 JsonReport(opts) {
  7. this.file = opts.file || 'coverage-final.json';
  8. this.first = true;
  9. }
  10. JsonReport.prototype.onStart = function (root, context) {
  11. this.contentWriter = context.writer.writeFile(this.file);
  12. this.contentWriter.write("{");
  13. };
  14. JsonReport.prototype.onDetail = function (node) {
  15. var fc = node.getFileCoverage(),
  16. key = fc.path,
  17. cw = this.contentWriter;
  18. if (this.first) {
  19. this.first = false;
  20. } else {
  21. cw.write(",");
  22. }
  23. cw.write(JSON.stringify(key));
  24. cw.write(': ');
  25. cw.write(JSON.stringify(fc));
  26. cw.println("");
  27. };
  28. JsonReport.prototype.onEnd = function () {
  29. var cw = this.contentWriter;
  30. cw.println("}");
  31. cw.close();
  32. };
  33. module.exports = JsonReport;