source: trip-planner-front/node_modules/istanbul-reports/lib/json-summary/index.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
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';
6const { ReportBase } = require('istanbul-lib-report');
7
8class JsonSummaryReport extends ReportBase {
9 constructor(opts) {
10 super();
11
12 this.file = opts.file || 'coverage-summary.json';
13 this.contentWriter = null;
14 this.first = true;
15 }
16
17 onStart(root, context) {
18 this.contentWriter = context.writer.writeFile(this.file);
19 this.contentWriter.write('{');
20 }
21
22 writeSummary(filePath, sc) {
23 const cw = this.contentWriter;
24 if (this.first) {
25 this.first = false;
26 } else {
27 cw.write(',');
28 }
29 cw.write(JSON.stringify(filePath));
30 cw.write(': ');
31 cw.write(JSON.stringify(sc));
32 cw.println('');
33 }
34
35 onSummary(node) {
36 if (!node.isRoot()) {
37 return;
38 }
39 this.writeSummary('total', node.getCoverageSummary());
40 }
41
42 onDetail(node) {
43 this.writeSummary(
44 node.getFileCoverage().path,
45 node.getCoverageSummary()
46 );
47 }
48
49 onEnd() {
50 const cw = this.contentWriter;
51 cw.println('}');
52 cw.close();
53 }
54}
55
56module.exports = JsonSummaryReport;
Note: See TracBrowser for help on using the repository browser.