| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ const { | |||
| 28 | 28 | const { setupCoverageHooks } = require('internal/util'); | |
| 29 | 29 | const { tmpdir } = require('os'); | |
| 30 | 30 | const { join, resolve, relative } = require('path'); | |
| 31 | - const { fileURLToPath } = require('internal/url'); | ||
| 31 | + const { fileURLToPath, URL } = require('internal/url'); | ||
| 32 | 32 | const { kMappings, SourceMap } = require('internal/source_map/source_map'); | |
| 33 | 33 | const { | |
| 34 | 34 | codes: { | |
@@ -37,6 +37,7 @@ const { | |||
| 37 | 37 | }, | |
| 38 | 38 | } = require('internal/errors'); | |
| 39 | 39 | const { matchGlobPattern } = require('internal/fs/glob'); | |
| 40 | + const { kMockSearchParam } = require('internal/test_runner/mock/mock'); | ||
| 40 | 41 | ||
| 41 | 42 | const kCoverageFileRegex = /^coverage-(\d+)-(\d{13})-(\d+)\.json$/; | |
| 42 | 43 | const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//; | |
@@ -497,6 +498,11 @@ class TestCoverage { | |||
| 497 | 498 | return true; | |
| 498 | 499 | } | |
| 499 | 500 | ||
| 501 | + const searchParams = new URL(url).searchParams; | ||
| 502 | + if (searchParams.get(kMockSearchParam)) { | ||
| 503 | + return true; | ||
| 504 | + } | ||
| 505 | + | ||
| 500 | 506 | // This check filters out the node_modules/ directory, unless it is explicitly included. | |
| 501 | 507 | return StringPrototypeIncludes(url, '/node_modules/'); | |
| 502 | 508 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + import {getData, sum} from './sum.js' | ||
| 2 | + | ||
| 3 | + export const theModuleSum = (a, b) => sum(a,b) | ||
| 4 | + | ||
| 5 | + export const theModuleGetData = () => getData() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + // console.log('imported') | ||
| 2 | + | ||
| 3 | + const data = { type: 'object' } | ||
| 4 | + | ||
| 5 | + // console.log(data) | ||
| 6 | + | ||
| 7 | + export const sum = (a, b) => a + b | ||
| 8 | + | ||
| 9 | + export const getData = () => data | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + import { describe, it, mock } from 'node:test'; | ||
| 2 | + | ||
| 3 | + describe('module test with mock', async () => { | ||
| 4 | + mock.module('../coverage-with-mock/sum.js', { | ||
| 5 | + namedExports: { | ||
| 6 | + sum: (a, b) => 1, | ||
| 7 | + getData: () => ({}), | ||
| 8 | + }, | ||
| 9 | + }); | ||
| 10 | + | ||
| 11 | + const { theModuleSum, theModuleGetData } = await import('../coverage-with-mock/module.js'); | ||
| 12 | + | ||
| 13 | + it('tests correct thing', (t) => { | ||
| 14 | + t.assert.strictEqual(theModuleSum(1, 2), 1); | ||
| 15 | + t.assert.deepStrictEqual(theModuleGetData(), {}); | ||
| 16 | + }); | ||
| 17 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + TAP version 13 | ||
| 2 | + # Subtest: module test with mock | ||
| 3 | + # Subtest: tests correct thing | ||
| 4 | + ok 1 - tests correct thing | ||
| 5 | + --- | ||
| 6 | + duration_ms: * | ||
| 7 | + type: 'test' | ||
| 8 | + ... | ||
| 9 | + 1..1 | ||
| 10 | + ok 1 - module test with mock | ||
| 11 | + --- | ||
| 12 | + duration_ms: * | ||
| 13 | + type: 'suite' | ||
| 14 | + ... | ||
| 15 | + 1..1 | ||
| 16 | + # tests 1 | ||
| 17 | + # suites 1 | ||
| 18 | + # pass 1 | ||
| 19 | + # fail 0 | ||
| 20 | + # cancelled 0 | ||
| 21 | + # skipped 0 | ||
| 22 | + # todo 0 | ||
| 23 | + # duration_ms * | ||
| 24 | + # start of coverage report | ||
| 25 | + # --------------------------------------------------------------------------- | ||
| 26 | + # file | line % | branch % | funcs % | uncovered lines | ||
| 27 | + # --------------------------------------------------------------------------- | ||
| 28 | + # test | | | | | ||
| 29 | + # fixtures | | | | | ||
| 30 | + # test-runner | | | | | ||
| 31 | + # coverage-with-mock | | | | | ||
| 32 | + # module.js | 100.00 | 100.00 | 100.00 | | ||
| 33 | + # output | | | | | ||
| 34 | + # coverage-with-mock.mjs | 100.00 | 100.00 | 100.00 | | ||
| 35 | + # --------------------------------------------------------------------------- | ||
| 36 | + # all files | 100.00 | 100.00 | 100.00 | | ||
| 37 | + # --------------------------------------------------------------------------- | ||
| 38 | + # end of coverage report | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,11 +29,11 @@ ok 1 - foo | |||
| 29 | 29 | # fixtures | | | | | |
| 30 | 30 | # test-runner | | | | | |
| 31 | 31 | # coverage | | | | | |
| 32 | - # bar.mts | 0.00 | 100.00 | 100.00 | 1-3 | ||
| 32 | + # bar.mts | 33.33 | 100.00 | 0.00 | 2-3 | ||
| 33 | 33 | # foo.mts | 100.00 | 100.00 | 100.00 | | |
| 34 | 34 | # output | | | | | |
| 35 | 35 | # typescript-coverage.mts | 100.00 | 100.00 | 100.00 | | |
| 36 | 36 | # ---------------------------------------------------------------------------- | |
| 37 | - # all files | 85.29 | 100.00 | 85.71 | | ||
| 37 | + # all files | 93.55 | 100.00 | 85.71 | | ||
| 38 | 38 | # ---------------------------------------------------------------------------- | |
| 39 | 39 | # end of coverage report | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -329,6 +329,15 @@ const tests = [ | |||
| 329 | 329 | '--experimental-test-coverage', | |
| 330 | 330 | '--test-coverage-exclude=!test/**'] | |
| 331 | 331 | } : false, | |
| 332 | + process.features.inspector ? { | ||
| 333 | + name: 'test-runner/output/coverage-with-mock.mjs', | ||
| 334 | + flags: ['--disable-warning=ExperimentalWarning', | ||
| 335 | + '--test-reporter=tap', | ||
| 336 | + '--experimental-transform-types', | ||
| 337 | + '--experimental-test-module-mocks', | ||
| 338 | + '--experimental-test-coverage', | ||
| 339 | + '--test-coverage-exclude=!test/**'] | ||
| 340 | + } : false, | ||
| 332 | 341 | ] | |
| 333 | 342 | .filter(Boolean) | |
| 334 | 343 | .map(({ flags, name, tty, transform, cwd }) => ({ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments