I have my own babel plugin mentioned in babel.config.js
and when I change the plugin, jest doesn't pick the updated plugin code and breaks tests. When I run
npx jest --no-cache
, updated changes are picked up.
I do not want to run with --no-cache
everytime I update the plugin.
I am curious to know how jest picks the latest babel plugins, when they are updated in npm artifactory?
I have mentioned my plugin in babel.config.js
as:
module.exports = function (api) {
api.cache(true);
const presets = ["@babel/preset-env", "@babel/preset-react"];
const plugins = [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime",
["module:@babel-plugin-dynamic-import-override", {
options: someOptions
}]
];
return {
presets,
plugins
};
}
Also, what changes do I make to my jest.config.js
to make it pick the latest plugins?
Jest caches the babel config for performance boost. This is same as providing cacheDirectory: true
with babel-loader
in webpack. babel-loader
also has option to burst cache using cacheIdentifier
, which jest doesn't has as of now and doesn't plan to add it in future too.
However, there is workaround by extending babel-jest. Detailed discussion can be read here: https://github.com/facebook/jest/issues/8932