MCPcopy Index your code
hub / github.com/nodejs/node / _transform

Method _transform

lib/internal/test_runner/reporter/lcov.js:15–104  ·  view source on GitHub ↗
(event, _encoding, callback)

Source from the content-addressed store, hash-verified

13 }
14
15 _transform(event, _encoding, callback) {
16 if (event.type !== 'test:coverage') {
17 return callback(null);
18 }
19 let lcov = '';
20 // A tracefile is made up of several human-readable lines of text, divided
21 // into sections. If available, a tracefile begins with the testname which
22 // is stored in the following format:
23 // ## TN:\<test name\>
24 lcov += 'TN:\n';
25 const {
26 data: {
27 summary: { workingDirectory },
28 },
29 } = event;
30 try {
31 for (let i = 0; i < event.data.summary.files.length; i++) {
32 const file = event.data.summary.files[i];
33 // For each source file referenced in the .da file, there is a section
34 // containing filename and coverage data:
35 // ## SF:\<path to the source file\>
36 lcov += `SF:${relative(workingDirectory, file.path)}\n`;
37
38 // Following is a list of line numbers for each function name found in
39 // the source file:
40 // ## FN:\<line number of function start\>,\<function name\>
41 //
42 // After, there is a list of execution counts for each instrumented
43 // function:
44 // ## FNDA:\<execution count\>,\<function name\>
45 //
46 // This loop adds the FN lines to the lcov variable as it goes and
47 // gathers the FNDA lines to be added later. This way we only loop
48 // through the list of functions once.
49 let fnda = '';
50 for (let j = 0; j < file.functions.length; j++) {
51 const func = file.functions[j];
52 const name = func.name || `anonymous_${j}`;
53 lcov += `FN:${func.line},${name}\n`;
54 fnda += `FNDA:${func.count},${name}\n`;
55 }
56 lcov += fnda;
57
58 // This list is followed by two lines containing the number of
59 // functions found and hit:
60 // ## FNF:\<number of functions found\>
61 // ## FNH:\<number of function hit\>
62 lcov += `FNF:${file.totalFunctionCount}\n`;
63 lcov += `FNH:${file.coveredFunctionCount}\n`;
64
65 // Branch coverage information is stored which one line per branch:
66 // ## BRDA:\<line number\>,\<block number\>,\<branch number\>,\<taken\>
67 // Block number and branch number are gcc internal IDs for the branch.
68 // Taken is either '-' if the basic block containing the branch was
69 // never executed or a number indicating how often that branch was
70 // taken.
71 for (let j = 0; j < file.branches.length; j++) {
72 lcov += `BRDA:${file.branches[j].line},${j},0,${file.branches[j].count}\n`;

Callers 2

zlib.jsFile · 0.45
transform.jsFile · 0.45

Calls 2

relativeFunction · 0.85
callbackFunction · 0.50

Tested by

no test coverage detected