| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4bad757 commit ea543d9
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,7 +99,16 @@ class TestCoverage { | |||
| 99 | 99 | // original line endings because those characters are necessary for | |
| 100 | 100 | // determining offsets in the file. | |
| 101 | 101 | const filePath = fileURLToPath(url); | |
| 102 | - const source = readFileSync(filePath, 'utf8'); | ||
| 102 | + let source; | ||
| 103 | + | ||
| 104 | + try { | ||
| 105 | + source = readFileSync(filePath, 'utf8'); | ||
| 106 | + } catch { | ||
| 107 | + // The file can no longer be read. It may have been deleted among | ||
| 108 | + // other possibilities. Leave it out of the coverage report. | ||
| 109 | + continue; | ||
| 110 | + } | ||
| 111 | + | ||
| 103 | 112 | const linesWithBreaks = | |
| 104 | 113 | RegExpPrototypeSymbolSplit(kLineSplitRegex, source); | |
| 105 | 114 | let ignoreCount = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,25 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | + const assert = require('node:assert'); | ||
| 3 | + const { unlinkSync, writeFileSync } = require('node:fs') | ||
| 4 | + const { join } = require('node:path'); | ||
| 2 | 5 | const { test } = require('node:test'); | |
| 3 | 6 | const common = require('./common'); | |
| 4 | 7 | ||
| 5 | 8 | test('third 1', () => { | |
| 6 | 9 | common.fnC(1, 4); | |
| 7 | 10 | common.fnD(99); | |
| 8 | 11 | }); | |
| 12 | + | ||
| 13 | + assert(process.env.NODE_TEST_TMPDIR); | ||
| 14 | + const tmpFilePath = join(process.env.NODE_TEST_TMPDIR, 'temp-module.js'); | ||
| 15 | + writeFileSync(tmpFilePath, ` | ||
| 16 | + module.exports = { | ||
| 17 | + fn() { | ||
| 18 | + return 42; | ||
| 19 | + } | ||
| 20 | + }; | ||
| 21 | + `); | ||
| 22 | + const tempModule = require(tmpFilePath); | ||
| 23 | + assert.strictEqual(tempModule.fn(), 42); | ||
| 24 | + // Deleted files should not be part of the coverage report. | ||
| 25 | + unlinkSync(tmpFilePath); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,7 +156,7 @@ test('coverage is combined for multiple processes', skipIfNoInspector, () => { | |||
| 156 | 156 | '| 100.00 | 100.00 | ', | |
| 157 | 157 | '# test/fixtures/v8-coverage/combined_coverage/third.test.js | 100.00 | ' + | |
| 158 | 158 | '100.00 | 100.00 | ', | |
| 159 | - '# all files | 90.72 | 72.73 | 88.89 |', | ||
| 159 | + '# all files | 92.11 | 72.73 | 88.89 |', | ||
| 160 | 160 | '# end of coverage report', | |
| 161 | 161 | ].join('\n'); | |
| 162 | 162 | ||
@@ -168,7 +168,9 @@ test('coverage is combined for multiple processes', skipIfNoInspector, () => { | |||
| 168 | 168 | const args = [ | |
| 169 | 169 | '--test', '--experimental-test-coverage', '--test-reporter', 'tap', fixture, | |
| 170 | 170 | ]; | |
| 171 | - const result = spawnSync(process.execPath, args); | ||
| 171 | + const result = spawnSync(process.execPath, args, { | ||
| 172 | + env: { ...process.env, NODE_TEST_TMPDIR: tmpdir.path } | ||
| 173 | + }); | ||
| 172 | 174 | ||
| 173 | 175 | assert.strictEqual(result.stderr.toString(), ''); | |
| 174 | 176 | assert(result.stdout.toString().includes(report)); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments