| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 879679e commit e2211a0
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -177,7 +177,7 @@ class TestCoverage { | |||
| 177 | 177 | if (isBlockCoverage) { | |
| 178 | 178 | ArrayPrototypePush(branchReports, { | |
| 179 | 179 | __proto__: null, | |
| 180 | - line: range.lines[0].line, | ||
| 180 | + line: range.lines[0]?.line, | ||
| 181 | 181 | count: range.count, | |
| 182 | 182 | }); | |
| 183 | 183 | ||
@@ -197,7 +197,7 @@ class TestCoverage { | |||
| 197 | 197 | __proto__: null, | |
| 198 | 198 | name: functions[j].functionName, | |
| 199 | 199 | count: maxCountPerFunction, | |
| 200 | - line: range.lines[0].line, | ||
| 200 | + line: range.lines[0]?.line, | ||
| 201 | 201 | }); | |
| 202 | 202 | ||
| 203 | 203 | if (range.count !== 0 || range.ignoredLines === range.lines.length) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + const source = ` | ||
| 2 | + import { test } from 'node:test'; | ||
| 3 | + test('test', async () => {}); | ||
| 4 | + `; | ||
| 5 | + | ||
| 6 | + export async function load(url, context, nextLoad) { | ||
| 7 | + if (url.endsWith('virtual.js')) { | ||
| 8 | + return { format: "module", source, shortCircuit: true }; | ||
| 9 | + } | ||
| 10 | + return nextLoad(url, context); | ||
| 11 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + const { register } = require('node:module'); | ||
| 2 | + const { pathToFileURL } = require('node:url'); | ||
| 3 | + | ||
| 4 | + register('./hooks.mjs', pathToFileURL(__filename)); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -273,3 +273,33 @@ test('coverage with source maps', skipIfNoInspector, () => { | |||
| 273 | 273 | assert(result.stdout.toString().includes(report)); | |
| 274 | 274 | assert.strictEqual(result.status, 1); | |
| 275 | 275 | }); | |
| 276 | + | ||
| 277 | + test('coverage with ESM hook - source irrelevant', skipIfNoInspector, () => { | ||
| 278 | + let report = [ | ||
| 279 | + '# start of coverage report', | ||
| 280 | + '# ------------------------------------------------------------------', | ||
| 281 | + '# file | line % | branch % | funcs % | uncovered lines', | ||
| 282 | + '# ------------------------------------------------------------------', | ||
| 283 | + '# hooks.mjs | 100.00 | 100.00 | 100.00 | ', | ||
| 284 | + '# register-hooks.js | 100.00 | 100.00 | 100.00 | ', | ||
| 285 | + '# virtual.js | 100.00 | 100.00 | 100.00 | ', | ||
| 286 | + '# ------------------------------------------------------------------', | ||
| 287 | + '# all files | 100.00 | 100.00 | 100.00 |', | ||
| 288 | + '# ------------------------------------------------------------------', | ||
| 289 | + '# end of coverage report', | ||
| 290 | + ].join('\n'); | ||
| 291 | + | ||
| 292 | + if (common.isWindows) { | ||
| 293 | + report = report.replaceAll('/', '\\'); | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + const fixture = fixtures.path('test-runner', 'coverage-loader'); | ||
| 297 | + const args = [ | ||
| 298 | + '--import', './register-hooks.js', '--test', '--experimental-test-coverage', '--test-reporter', 'tap', 'virtual.js', | ||
| 299 | + ]; | ||
| 300 | + const result = spawnSync(process.execPath, args, { cwd: fixture }); | ||
| 301 | + | ||
| 302 | + assert.strictEqual(result.stderr.toString(), ''); | ||
| 303 | + assert(result.stdout.toString().includes(report)); | ||
| 304 | + assert.strictEqual(result.status, 0); | ||
| 305 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments