| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2ff5cb1 commit 40a43ac
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,7 +108,9 @@ const kShouldNotSkipModuleHooks = { __proto__: null, shouldSkipModuleHooks: fals | |||
| 108 | 108 | * @param {boolean} isMain - Whether the module is the entrypoint | |
| 109 | 109 | */ | |
| 110 | 110 | function loadCJSModule(module, source, url, filename, isMain) { | |
| 111 | - const compileResult = compileFunctionForCJSLoader(source, filename, false /* is_sea_main */, false); | ||
| 111 | + // Use the full URL as the V8 resource name so that any search params | ||
| 112 | + // (e.g. ?node-test-mock) are preserved in coverage reports. | ||
| 113 | + const compileResult = compileFunctionForCJSLoader(source, url, false /* is_sea_main */, false); | ||
| 112 | 114 | ||
| 113 | 115 | const { function: compiledWrapper, sourceMapURL, sourceURL } = compileResult; | |
| 114 | 116 | // Cache the source map for the cjs module if present. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + throw new Error('This should never be called'); | ||
| 2 | + | ||
| 3 | + exports.dependency = function dependency() { | ||
| 4 | + return 'foo'; | ||
| 5 | + } | ||
| 6 | + | ||
| 7 | + exports.unused = function unused() { | ||
| 8 | + return 'bar'; | ||
| 9 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + import { dependency } from './dependency.cjs'; | ||
| 2 | + | ||
| 3 | + export function subject() { | ||
| 4 | + return dependency(); | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + import { mock, test } from 'node:test'; | ||
| 2 | + | ||
| 3 | + const dependency = mock.fn(() => 'mock-return-value'); | ||
| 4 | + mock.module('../coverage-with-mock/dependency.cjs', { namedExports: { dependency } }); | ||
| 5 | + | ||
| 6 | + const { subject } = await import('../coverage-with-mock/subject.mjs'); | ||
| 7 | + | ||
| 8 | + test('subject calls dependency', (t) => { | ||
| 9 | + t.assert.strictEqual(subject(), 'mock-return-value'); | ||
| 10 | + t.assert.strictEqual(dependency.mock.callCount(), 1); | ||
| 11 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + TAP version 13 | ||
| 2 | + # Subtest: subject calls dependency | ||
| 3 | + ok 1 - subject calls dependency | ||
| 4 | + --- | ||
| 5 | + duration_ms: * | ||
| 6 | + type: 'test' | ||
| 7 | + ... | ||
| 8 | + 1..1 | ||
| 9 | + # tests 1 | ||
| 10 | + # suites 0 | ||
| 11 | + # pass 1 | ||
| 12 | + # fail 0 | ||
| 13 | + # cancelled 0 | ||
| 14 | + # skipped 0 | ||
| 15 | + # todo 0 | ||
| 16 | + # duration_ms * | ||
| 17 | + # start of coverage report | ||
| 18 | + # ------------------------------------------------------------------------------- | ||
| 19 | + # file | line % | branch % | funcs % | uncovered lines | ||
| 20 | + # ------------------------------------------------------------------------------- | ||
| 21 | + # test | | | | | ||
| 22 | + # fixtures | | | | | ||
| 23 | + # test-runner | | | | | ||
| 24 | + # coverage-with-mock | | | | | ||
| 25 | + # subject.mjs | 100.00 | 100.00 | 100.00 | | ||
| 26 | + # output | | | | | ||
| 27 | + # coverage-with-mock-cjs.mjs | 100.00 | 100.00 | 100.00 | | ||
| 28 | + # ------------------------------------------------------------------------------- | ||
| 29 | + # all files | 100.00 | 100.00 | 100.00 | | ||
| 30 | + # ------------------------------------------------------------------------------- | ||
| 31 | + # end of coverage report | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,22 @@ | |||
| 1 | + import * as common from '../common/index.mjs'; | ||
| 2 | + import * as fixtures from '../common/fixtures.mjs'; | ||
| 3 | + import { spawnAndAssert, defaultTransform, ensureCwdIsProjectRoot } from '../common/assertSnapshot.js'; | ||
| 4 | + | ||
| 5 | + if (!process.features.inspector) { | ||
| 6 | + common.skip('inspector support required'); | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + ensureCwdIsProjectRoot(); | ||
| 10 | + await spawnAndAssert( | ||
| 11 | + fixtures.path('test-runner/output/coverage-with-mock-cjs.mjs'), | ||
| 12 | + defaultTransform, | ||
| 13 | + { | ||
| 14 | + flags: [ | ||
| 15 | + '--disable-warning=ExperimentalWarning', | ||
| 16 | + '--test-reporter=tap', | ||
| 17 | + '--experimental-test-module-mocks', | ||
| 18 | + '--experimental-test-coverage', | ||
| 19 | + '--test-coverage-exclude=!test/**', | ||
| 20 | + ], | ||
| 21 | + }, | ||
| 22 | + ); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments