GithubHelp home page GithubHelp logo

justinsisley / jest-css-modules Goto Github PK

View Code? Open in Web Editor NEW
75.0 1.0 16.0 345 KB

A Jest script processor that prevents CSS module parse errors.

Home Page: https://www.npmjs.com/package/jest-css-modules

JavaScript 67.49% CSS 12.67% HCL 19.84%
jest testing css-modules webpack

jest-css-modules's Introduction

Note: As of v2.0.0, this library is simply implementing identity-obj-proxy. The Jest documentation provides more details on using identity-obj-proxy to solve this problem directly, and I recommend that you use that library instead of this one.

Jest CSS Modules

A Jest script processor that prevents CSS module parse errors.

Installation

npm install -D jest-css-modules

Update your package.json file's jest configuration:

{
  "jest": {
    "moduleNameMapper": {
      "\\.(css|less|scss|sss|styl)$": "<rootDir>/node_modules/jest-css-modules"
    }
  }
}

Now, imports such as import styles from './MyModule.css'; will pass through Jest without causing any pain.

Supports .css, .less, .scss, .sss, and .styl extensions.

Note: If you continue to experience CSS module parsing errors after installing and configuring this library, try running jest with the --no-cache flag. Read the Jest documentation on caching for more details.

jest-css-modules's People

Contributors

arnif avatar dependabot[bot] avatar fergmac avatar fezvrasta avatar justinsisley avatar lauterry avatar matheuspoleza avatar themarkappleby avatar tomtomsen avatar vcapretz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

jest-css-modules's Issues

Regex expression is incorrect

I'm no regex expert, so please correct me if I am wrong.

The current regex for me filtered out files names that ended in: myTest.spec.js. It was matching the .s part. I changed the regex to the following to make it work.

if (filename.match(/.*\.\(css\|less|scss|styl\)/)) {
   return '';
}

Missing LICENSE file

While package.json declares the license as ISC, there is no actual license file in the project.

README.md should be updated

● Deprecation Warning:

  Option "scriptPreprocessor" was replaced by "transform", which support multiple preprocessors.

  Jest now treats your current configuration as:
  {
    "transform": {".*": "<rootDir>/node_modules/jest-css-modules"}
  }

  Please update your configuration.

  Configuration Documentation:
  https://facebook.github.io/jest/docs/configuration.html

Upgrade babel-jest to ^9.0.0 or newer

Hello @justinsisley

Please upgrade babel-jest dependencies to ^9.0.0 or newer.

I got Unknow option: .babelrc.presets when running jest.

I have declared "babel-jest": "^9.0.0" in my devDependencies.

Best regards

Document usage of --no-cache after installing preprocessor.

People will generally first already have executed jest tests on a broken file before coming here and finding this project. They will then install the preprocessor, run again, but the test still fails.

Why? According to jest docs, you need to use the --no-cache flag when working with script preprocessors on files that have already been processed before. See: https://facebook.github.io/jest/docs/api.html#scriptpreprocessor-string

I think it would be very useful to document this as well.

Does not work with react-css-modules

After fixing #5 locally I am getting:

butler% npm test

> @ test /home/me/apps/frontend
> jest

 FAIL  library/paymentform.test.js
  ● paymentform › renders patterns without slashes

    "form-reactbuttons" CSS module is undefined.
      
      at exports.default (node_modules/react-css-modules/dist/generateAppendClassName.js:41:23)
      at linkElement (node_modules/react-css-modules/dist/linkClass.js:67:65)
      at node_modules/react-css-modules/dist/linkClass.js:59:24
      at mapSingleChildIntoContext (node_modules/react/lib/ReactChildren.js:108:26)
...

... which seems to make sense given that jest-css-modules skips loading of the css modules.

Am I missing something to make jest-css-modules work with react-css-modules?

TypeError: Jest: a transform must export a `process` function.

After installing the package and adding the transform, I'm getting a new error TypeError: Jest: a transform must export a process function. Not sure if this a breaking change introduced by a Jest upgrade? I ran using --no-cache

package.json

    "babel-jest": "^24.8.0",
    "jest": "^24.8.0",
    "jest-css-modules": "^2.1.0",
     ...
  "jest": {
    "transform": {
	  "^.+\\.js$": "babel-jest",
	  "\\.(css|less|scss|sss|styl)$": "<rootDir>/node_modules/jest-css-modules"

    }
  }

Validation Error on newer Jest

Validation Error:

  Option "transform" must be of type:
    object
  but instead received:
    string

It seems like Jest has updated something. I can't use this in package.json anymore


{
  "jest": {
    "scriptPreprocessor": "<rootDir>/node_modules/jest-css-modules",
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.