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 | const { ReportBase } = require('istanbul-lib-report');
|
---|
7 |
|
---|
8 | class TextSummaryReport extends ReportBase {
|
---|
9 | constructor(opts) {
|
---|
10 | super();
|
---|
11 |
|
---|
12 | opts = opts || {};
|
---|
13 | this.file = opts.file || null;
|
---|
14 | }
|
---|
15 |
|
---|
16 | onStart(node, context) {
|
---|
17 | const summary = node.getCoverageSummary();
|
---|
18 | const cw = context.writer.writeFile(this.file);
|
---|
19 | const printLine = function(key) {
|
---|
20 | const str = lineForKey(summary, key);
|
---|
21 | const clazz = context.classForPercent(key, summary[key].pct);
|
---|
22 | cw.println(cw.colorize(str, clazz));
|
---|
23 | };
|
---|
24 |
|
---|
25 | cw.println('');
|
---|
26 | cw.println(
|
---|
27 | '=============================== Coverage summary ==============================='
|
---|
28 | );
|
---|
29 | printLine('statements');
|
---|
30 | printLine('branches');
|
---|
31 | printLine('functions');
|
---|
32 | printLine('lines');
|
---|
33 | cw.println(
|
---|
34 | '================================================================================'
|
---|
35 | );
|
---|
36 | cw.close();
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | function lineForKey(summary, key) {
|
---|
41 | const metrics = summary[key];
|
---|
42 |
|
---|
43 | key = key.substring(0, 1).toUpperCase() + key.substring(1);
|
---|
44 | if (key.length < 12) {
|
---|
45 | key += ' '.substring(0, 12 - key.length);
|
---|
46 | }
|
---|
47 | const result = [
|
---|
48 | key,
|
---|
49 | ':',
|
---|
50 | metrics.pct + '%',
|
---|
51 | '(',
|
---|
52 | metrics.covered + '/' + metrics.total,
|
---|
53 | ')'
|
---|
54 | ].join(' ');
|
---|
55 | const skipped = metrics.skipped;
|
---|
56 | if (skipped > 0) {
|
---|
57 | return result + ', ' + skipped + ' ignored';
|
---|
58 | }
|
---|
59 | return result;
|
---|
60 | }
|
---|
61 |
|
---|
62 | module.exports = TextSummaryReport;
|
---|