Files
node/test/fixtures/test-runner/output/coverage-with-mock.mjs
sangwook 7d1f1b4483 test_runner: add exports option for module mocks
Add options.exports support in mock.module() and normalize option

shapes through a shared exports path.

Keep defaultExport and namedExports as aliases, emit runtime

deprecation warnings for legacy options, and update docs and tests,

including output fixtures and coverage snapshots.

Refs: https://github.com/nodejs/node/issues/58443
PR-URL: https://github.com/nodejs/node/pull/61727
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2026-03-27 15:52:13 +00:00

18 lines
470 B
JavaScript

import { describe, it, mock } from 'node:test';
describe('module test with mock', async () => {
mock.module('../coverage-with-mock/sum.js', {
exports: {
sum: (a, b) => 1,
getData: () => ({}),
},
});
const { theModuleSum, theModuleGetData } = await import('../coverage-with-mock/module.js');
it('tests correct thing', (t) => {
t.assert.strictEqual(theModuleSum(1, 2), 1);
t.assert.deepStrictEqual(theModuleGetData(), {});
});
});