Skip to content

Report code coverage fails when using experimental mock feature #58119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
didiercolens opened this issue May 2, 2025 · 0 comments · Fixed by #58193
Closed

Report code coverage fails when using experimental mock feature #58119

didiercolens opened this issue May 2, 2025 · 0 comments · Fixed by #58193
Labels
confirmed-bug Issues with confirmed bugs. source maps Issues and PRs related to source map support.

Comments

@didiercolens
Copy link

didiercolens commented May 2, 2025

Version

v23.11.0

Platform

Darwin Kernel Version 24.4.0 (ARM) but likely not relevant

Subsystem

test_runner

What steps will reproduce the bug?

Create the 3 below files in a folder and run node --experimental-transform-types --experimental-test-module-mocks --test --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout ./foo.test.mts

files

bar.mts

export default function bar() {
  return 'original bar';
}

foo.mts

import bar from './bar.mts';

export const foo = () => bar();

foo.test.mts

import assert from 'node:assert/strict';
import { before, describe, it, mock } from 'node:test';

describe('foo', { concurrency: true }, () => {
  let barMock = mock.fn();
  let foo;

  before(async () => {
    const barNamedExports = await import('./bar.mts')
      .then(({ default: _, ...rest }) => rest);

    mock.module('./bar.mts', {
      defaultExport: barMock,
      namedExports: barNamedExports,
    });

    ({ foo } = await import('./foo.mts'));
  });

  it('should do the thing', () => {
    barMock.mock.mockImplementationOnce(()  => 42);

    assert.equal(foo(), 42);
  });
});

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

tests pass and test coverage is displayed

What do you see instead?

tests pass but test coverage failed:

(node:49928) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:49928) ExperimentalWarning: Module mocking is an experimental feature and might change at any time
▶ foo
  ✔ should do the thing (0.46475ms)
✔ foo (36.605917ms)
ℹ Warning: Could not report code coverage. TypeError: Cannot read properties of undefined (reading 'startOffset')
ℹ tests 1
ℹ suites 1
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 155.707375

Additional information

looks similar to #55054

@marco-ippolito marco-ippolito added confirmed-bug Issues with confirmed bugs. source maps Issues and PRs related to source map support. labels May 6, 2025
nodejs-github-bot pushed a commit that referenced this issue May 8, 2025
PR-URL: #58193
Fixes: #58119
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. source maps Issues and PRs related to source map support.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants