Gathering detailed insights and metrics for jest-css-modules-transform-inject
Gathering detailed insights and metrics for jest-css-modules-transform-inject
npm install jest-css-modules-transform-inject
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (43.75%)
TypeScript (36.57%)
CSS (5.72%)
SCSS (3.92%)
Less (3.67%)
Stylus (3.4%)
Sass (2.96%)
Total Downloads
920
Last Day
3
Last Week
7
Last Month
26
Last Year
204
61 Stars
159 Commits
18 Forks
3 Watching
7 Branches
10 Contributors
Minified
Minified + Gzipped
Latest Version
1.2.0
Package Id
jest-css-modules-transform-inject@1.2.0
Unpacked Size
26.73 kB
Size
7.40 kB
File Count
10
NPM Version
6.14.10
Node Version
12.16.2
Cumulative downloads
Total Downloads
Last day
0%
3
Compared to previous day
Last week
40%
7
Compared to previous week
Last month
85.7%
26
Compared to previous month
Last year
37.8%
204
Compared to previous year
This preprocessor converts css files in modules like Webpack. If we have css files
1.class1, .class2, .class3 { 2 display: block; 3}
Webpack will transfrom it to object.
1{ 2 class1: 'class1', //value may be different. It depends of localIndentName property 3 class2: 'class2', 4 class3: 'class3', 5}
In testing you need to mock all css modules to aviod exception. But use pure object {}
for mocking is bad idea, because it makes wrong classNames in components. This preprocessor makes correct modules as if Webpack did.
In Jest config add option
1"transform": { 2 ".+\\.(css|styl|less|sass|scss)$": "jest-css-modules-transform" 3},
or
1"transform": { 2 ".+\\.(css|styl|less|sass|scss)$": "<rootDir>/node_modules/jest-css-modules-transform" 3},
It supports pure CSS
, SCSS
, SASS
, STYLUS
and LESS
.
For .css
, .pcss
, .postcss
files used postcss.config.js
from root folder(if file exist of course).
For tests you can rewrite your existed postcss.config.js
. See options.
You can save preproccessor options in file jest-css-modules-transform-config.js
in root of your project(Where is the file package.json
).
You can pass options for your preprocessors.
1const path = require('path'); 2const additionalResolvePath = path.resolve(__dirname, 'src', 'additional_modules'); 3 4module.exports = { 5 sassConfig: { 6 includePaths: [additionalResolvePath], 7 precision: 5, 8 }, 9 lessConfig: { 10 paths: [additionalResolvePath], 11 }, 12 stylusConfig: { 13 paths: [additionalResolvePath], 14 }, 15 postcssConfig: { 16 plugins: [ 17 require('autoprefixer')({ 18 browsers: ['Chrome 68', 'Firefox 62', 'Safari 12'] 19 }) 20 ] 21 }, 22};
For all preprocessor options see offical documentations for Sass, Less, Stylus.
Webpack's cssLoader has option exportLocalsStyle.
1// file jest-css-modules-transform-config.js 2module.exports = { 3 cssLoaderConfig: { 4 exportLocalsStyle: 'camelCase' 5 } 6};
then this css code
1 .foo__bar{color: red;} 2 .foo__bar2{color: red;}
converted to
1 { 2 foo__bar: 'foo__bar', 3 fooBar: 'foo__bar', 4 foo__bar2: 'foo__bar2', 5 fooBar: 'foo__bar2', 6 }
Available values camelCase
, camelCaseOnly
, dashes
, dashesOnly
, asIs
(by default)
Type: string
, Function
, Array<string | Function>
Default: null
Pass urls for prepend(before file content) to transformed files.
Useful in a situation where the module uses variables or mixins without explicit import.
For example you have vars in file, but without implicit import. You can prepend file with sass
variables before convert module.
Type: boolean
Default: false
Inject the generated CSS into the head of the document.
This option could be useful for visual regression testing, where the output dom has the styles applied to it.
Type: string
Default: null
The default nodejs module for sass/scss
files is sass
. If not found in node_modules, then node-sass
. You can define any another module.
1// file jest-css-modules-transform-config.js 2module.exports = { 3 prepend: [ 4 'some/url/vars.scss', 5 'some/url/theme.scss', 6 ], 7};
1// file jest-css-modules-transform-config.js 2module.exports = { 3 prepend: 'some/url/vars.scss', 4};
1// file jest-css-modules-transform-config.js 2module.exports = { 3 prepend: (filepath) => { 4 if (filepath.includes('components')) { 5 return [ 6 'components/vars.scss', 7 'components2/vars.scss', 8 ]; 9 } 10 11 return [ 12 'common/vars.scss', 13 'common/vars2.scss', 14 ]; 15 }, 16};
It works with any preprocessors(Sass, Less, Styles, PostCSS, pure CSS)
By default option plugin's config file is jest-css-modules-transform-config.js
from root. For specify custom path just add env JEST_CSS_MODULES_TRANSFORM_CONFIG
. For example:
1JEST_CSS_MODULES_TRANSFORM_CONFIG=custom-config-path npm test
or
1JEST_CSS_MODULES_TRANSFORM_CONFIG=custom-config-path yarn test
npm i jest-css-modules-transform
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
18 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More