[Feature]: Mock all files with certain extension
What problem does this feature solve?
In Jest it's common to create following configuration to ignore / mock files with certain file extensions (css, less, scss, png, etc.).
{
"moduleNameMapper": {
"\\.(css|less|scss)$": "<rootDir>/src/Mocks/styleMock.js" // module.exports = {}
}
}
It seems that in the case of rstest this is not so easy to achieve without a custom plugin.
What does the proposed API look like?
Support regexpes in resolve.alias or create native "ignore" plugin that will override files content with empty export.
This can be achieved using rspack NormalModuleReplacementPlugin.
export default defineConfig({
tools: {
rspack: (config, { rspack}) => {
config.plugins.push(
new rspack.NormalModuleReplacementPlugin(/\.(css|less|scss)/, require.resolve('./src/Mocks/styleMock.js'))
);
}
}
});
Thanks for the reply. I didn't know about this plugin, maybe it would be worth considering adding this information to the migration guide from Jest? I'm closing this thread.
I agree that it would be helpful to include this method in the Jest migration guide or offer a more direct solution. I'll reopen this issue so we can follow up on it.
+1. The NormalModuleReplacementPlugin is a bit difficult for users to use.
Perhaps it would be simpler for rstest or rsbuild to provide a configuration option similar to resolve.moduleNameMapper.