Installations
npm install jest-css-modules-transform-inject
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=10.0.0
Node Version
12.16.2
NPM Version
6.14.10
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (43.75%)
TypeScript (36.57%)
CSS (5.72%)
SCSS (3.92%)
Less (3.67%)
Stylus (3.4%)
Sass (2.96%)
Developer
Connormiha
Download Statistics
Total Downloads
920
Last Day
3
Last Week
7
Last Month
26
Last Year
204
GitHub Statistics
61 Stars
159 Commits
18 Forks
3 Watching
7 Branches
10 Contributors
Bundle Size
109.80 kB
Minified
31.01 kB
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
920
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
jest-css-modules-transform
Preprocessor css modules for Jest test framework
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.
Usage
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 PostCSS
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.
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.
example:
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.
cssLoaderConfig
exportLocalsStyle
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)
prepend
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.
injectIntoDOM
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.
sassModuleName
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.
Example with array of paths
1// file jest-css-modules-transform-config.js 2module.exports = { 3 prepend: [ 4 'some/url/vars.scss', 5 'some/url/theme.scss', 6 ], 7};
Example with single string
1// file jest-css-modules-transform-config.js 2module.exports = { 3 prepend: 'some/url/vars.scss', 4};
Example with custom function
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)
Custom config path
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
Install
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Reason
18 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-7mwh-4pqv-wmr8
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
1.3
/10
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