Transforms stealthy-require
calls into jest.isolateModules()
The purpose of this module is to address Jest + stealthy-require compatibility issue which causes issues like Unable to expose method "then" on modules that depend on stealthy-require.
npm install --save-dev jest-transform-stealthy-require
jest.config.js
const { requestPromise } = require('jest-transform-stealthy-require/dist/presets');
module.exports = {
// ...
transform: {
...requestPromise.transform
},
transformIgnorePatterns: [requestPromise.transformIgnorePattern]
};
jest.config.js
const { requestPromise } = require('jest-transform-stealthy-require/dist/presets');
module.exports = {
// ...
transform: {
...requestPromise.transform,
"^.+\\.[t|j]sx?$": "babel-jest"
},
transformIgnorePatterns: [requestPromise.transformIgnorePattern]
}
jest.config.js
const { requestPromise } = require('jest-transform-stealthy-require/dist/presets');
const { defaults: tsjPreset } = require('ts-jest/presets');
// [OR] const { jsWithTs: tsjPreset } = require('ts-jest/presets');
// [OR] const { jsWithBabel: tsjPreset } = require('ts-jest/presets');
module.exports = {
// ...
transform: {
...requestPromise.transform,
...tsjPreset.transform
},
transformIgnorePatterns: [requestPromise.transformIgnorePattern]
}
The transformer can be used to replace stealthy-require calls in arbitrary modules. Simply specify the file pattern to for the modules that you would like to transform in your Jest config:
jest.config.js
module.exports = {
// ...
transform: {
'my_pattern_to_module_to_transform': 'jest-transform-stealthy-require'
}
};