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

Method getLines

lib/internal/test_runner/coverage.js:92–153  ·  view source on GitHub ↗
(fileUrl, source)

Source from the content-addressed store, hash-verified

90 #includeMatchers = null;
91
92 getLines(fileUrl, source) {
93 // Split the file source into lines. Make sure the lines maintain their
94 // original line endings because those characters are necessary for
95 // determining offsets in the file.
96 if (this.#sourceLines.has(fileUrl)) {
97 return this.#sourceLines.get(fileUrl);
98 }
99
100 try {
101 source ??= readFileSync(fileURLToPath(fileUrl), 'utf8');
102 } catch {
103 // The file can no longer be read. It may have been deleted among
104 // other possibilities. Leave it out of the coverage report.
105 this.#sourceLines.set(fileUrl, null);
106 return;
107 }
108
109 const linesWithBreaks =
110 RegExpPrototypeSymbolSplit(kLineSplitRegex, source);
111 let ignoreCount = 0;
112 let enabled = true;
113 let offset = 0;
114
115 const lines = ArrayPrototypeMap(linesWithBreaks, (line, i) => {
116 const startOffset = offset;
117 const coverageLine = new CoverageLine(i + 1, startOffset, line);
118
119 offset += line.length;
120
121 // Determine if this line is being ignored.
122 if (ignoreCount > 0) {
123 ignoreCount--;
124 coverageLine.ignore = true;
125 } else if (!enabled) {
126 coverageLine.ignore = true;
127 }
128
129 if (!coverageLine.ignore) {
130 // If this line is not already being ignored, check for ignore
131 // comments.
132 const match = RegExpPrototypeExec(kIgnoreRegex, line);
133
134 if (match !== null) {
135 ignoreCount = NumberParseInt(match.groups?.count ?? 1, 10);
136 }
137 }
138
139 // Check for comments to enable/disable coverage no matter what. These
140 // take precedence over ignore comments.
141 const match = RegExpPrototypeExec(kStatusRegex, line);
142 const status = match?.groups?.status;
143
144 if (status) {
145 ignoreCount = 0;
146 enabled = status === 'enable';
147 }
148
149 return coverageLine;

Callers 3

summaryMethod · 0.95

Calls 5

fileURLToPathFunction · 0.85
hasMethod · 0.65
getMethod · 0.65
readFileSyncFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected