GeezerVison is showing github.com — test: improve lcov reporter snapshot diagnostics · nodejs/node@ff9122c
File tree
Expand file treeCollapse file tree
Open diff view settings
fixtures/test-runner/output
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: test/common/assertSnapshot.js +18-1Lines changed: 18 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -235,13 +235,30 @@ function replaceJunitDuration(str) { |
235 | 235 | // This transform picks only the first line and then the lines from the test |
236 | 236 | // file. |
237 | 237 | function pickTestFileFromLcov(str) { |
| 238 | + const expectedFile = 'output.js'; |
238 | 239 | const lines = str.split(/\n/); |
239 | 240 | const firstLineOfTestFile = lines.findIndex( |
240 | | - (line) => line.startsWith('SF:') && line.trim().endsWith('output.js'), |
| 241 | + (line) => line.startsWith('SF:') && line.trim().endsWith(expectedFile), |
241 | 242 | ); |
| 243 | + |
| 244 | + if (firstLineOfTestFile === -1) { |
| 245 | + assert.fail( |
| 246 | + `Could not find LCOV source record ending with ${expectedFile} ` + |
| 247 | + `in LCOV output:\n${str || '<empty>'}`, |
| 248 | + ); |
| 249 | + } |
| 250 | + |
242 | 251 | const lastLineOfTestFile = lines.findIndex( |
243 | 252 | (line, index) => index > firstLineOfTestFile && line.trim() === 'end_of_record', |
244 | 253 | ); |
| 254 | + |
| 255 | + if (lastLineOfTestFile === -1) { |
| 256 | + assert.fail( |
| 257 | + `Could not find end_of_record for LCOV source record ending with ${expectedFile} ` + |
| 258 | + `in LCOV output:\n${str}`, |
| 259 | + ); |
| 260 | + } |
| 261 | + |
245 | 262 | return ( |
246 | 263 | lines[0] + '\n' + lines.slice(firstLineOfTestFile, lastLineOfTestFile + 1).join('\n') + '\n' |
247 | 264 | ); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/lcov_reporter.js +14-1Lines changed: 14 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ require('../../../common'); |
3 | 3 | const fixtures = require('../../../common/fixtures'); |
4 | 4 | const spawn = require('node:child_process').spawn; |
5 | 5 |
|
6 | | -spawn( |
| 6 | +const child = spawn( |
7 | 7 | process.execPath, |
8 | 8 | [ |
9 | 9 | '--no-warnings', |
@@ -14,3 +14,16 @@ spawn( |
14 | 14 | ], |
15 | 15 | { stdio: 'inherit' }, |
16 | 16 | ); |
| 17 | + |
| 18 | +child.on('error', (err) => { |
| 19 | + throw err; |
| 20 | +}); |
| 21 | + |
| 22 | +child.on('exit', (code, signal) => { |
| 23 | + if (signal) { |
| 24 | + process.kill(process.pid, signal); |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + process.exitCode = code ?? 1; |
| 29 | +}); |