A Jest preprocessor that transforms CSS, SCSS, SASS, Less, and Stylus files into JavaScript objects mimicking Webpack's css-loader module output. Version 4.4.2 is current stable; released occasionally with bug fixes and minor features. Unlike simple identity mock objects (e.g., `{}`), this generates correct class name mappings (as-is, camelCase, dashes), supports PostCSS with custom plugins, and allows prepending variables or mixins. It provides configuration via `jest-css-modules-transform-config.js` for per-preprocessor options, making it ideal for visual regression testing or component testing where real class names matter.
npm install jest-css-modules-transformVerified import paths — ran on the pinned version, not inferred.
Shows basic setup for Jest transform configuration and optional config file for custom CSS module output style.
Rename config file or move to root directory.
Ensure postcss.config.js is in root or use postcssConfig in jest-css-modules-transform-config.js for non-.css files.
Upgrade Node to version 10 or higher.
Install 'sass' as a devDependency or set sassModuleName: 'node-sass' in config.
Use cssLoaderConfig.exportLocalsStyle to control class name format.
Run 'npm install sass --save-dev' or 'npm install node-sass --save-dev'.
Ensure 'jest-css-modules-transform-config.js' exports a plain object.
Add '.+\.(css|styl|less|sass|scss)$' to transform in Jest config.