To preconfigure rewiremock for all tests, it is recommended to create a central configuration file (e.g., rewiremock.js) rather than importing it directly in every test. The setup depends on your runtime/module system:
TS/ES6/ESM
Use import. You must call rewiremock.overrideEntryPoint(module) to transfer the module parent to rewiremock.
CommonJS/Node.js
Use require('rewiremock/node'). You must call rewiremock.overrideEntryPoint(module).
Webpack
Use import rewiremock from 'rewiremock/webpack'. You must call rewiremock.overrideEntryPoint(module) and add necessary plugins to your webpack test configuration.
// rewiremock.es6.js (TS/ES6/ESM)
import rewiremock from 'rewiremock';
// settings...
rewiremock.overrideEntryPoint(module);
export { rewiremock }
// rewiremock.cjs.js (CommonJS/Node.js)
const rewiremock = require('rewiremock/node');
// settings...
rewiremock.overrideEntryPoint(module);
module.exports = rewiremock;
// rewiremock.es6.js (Webpack)
import rewiremock from 'rewiremock/webpack';
// settings...
rewiremock.overrideEntryPoint(module);
export { rewiremock }