-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing with karma and karma-webpack-with-fast-source-maps #77
Comments
Hi, I'm not familiar with karma, but looks like if you managed to preprocess files with webpack then you don't need the require hook to be used here. Usually with webpack you need to configure css-loader properly. Can you show a small example of your configuration, so I can take a look into it? |
Hi @sullenor, Thanks for your prompt response. Hope it helps to visualise the issue. |
As far as I know every chain of webpack loaders should return a valid commonJs module in the end. Talking about css — you should use style-loader with css-loader together. Using them in that way will result in the valid commonJs modules. So your configuration should look similar to this: module: {
loaders: [
// ...
{
test: /\.css$/,
loader: 'style!css?modules&importLoaders=1&localIdentName=...',
},
]
} I sent you a small pr qmmr/yab#1 which fixes configuration for the webpack dev server and also added small patch to the |
Actually, I don't know a lot about loaders but looks like that the solution above should be valid :) You may check the examples to find more information about the topic: |
@sullenor I've tried your PR but it does not work for me. The
Your suggestion does not include css-modules-require-hook. This repo is just to solve the issue of finding DOM elements using css-selectors when running karma-webpack. So the question still remains, how can I include css-modules-require-hook into this setup so that when I run tests via karma, it will result in the same output as tests run with mocha. Thanks for the links, I will read about webpack and plugins. |
Hm, that's interesting cause I had the necessary markup in the example :)
Since you are able to use webpack, you don't need css-modules-require-hook. In my opinion it should fill the gap in case you don't have a possibility to use webpack. For example, server-side rendering. Update: Presumably, I didn't understand you. I guess I haven't checked all the files. Let me update my pr. |
I checked again your repo and reproduced errors with adding Presumably, all the errors come after the webpack tries to preprocess the provided files and it's dependencies. Since, the required hook was designed to compile CSS Modules in runtime it hardly depends on nodejs environment. That's why webpack can't load some core nodejs modules like fs. There is a solution for that problem here: http://webpack.github.io/docs/configuration.html#node As far as I know karma uses browser environment to execute all the tests: http://karma-runner.github.io/0.13/intro/how-it-works.html So setting css-modules-require-hook will be a wrong here cause it isn't suitable for that environment. Since you compile sources with webpack for karma, in my opinion with should fix webpack configuration I added style loader to the chain (add installed it) and it fixed issue with loading modules. PhantomJS 2.1.1 (Mac OS X 0.0.0) LOG LOG: 'styles', Object{menu: 'Menu__menu___cuY3N'}
LOG LOG: '<ul className="Menu__menu___cuY3N"> Still there is an another issue with enzyme. |
I've been using css-modules with mocha, enzyme and css-modules-require-hook without any problems.
I started using Karma with karma-webpack-with-fast-source-maps and now the test fails because the styles in Foo.js is an array:
[[376, '.Foo__foo___3QT3e { color: rebeccapurple; } ', '']]
I've tried importing the css-modules-require-hook in
test-bundler.js
for karma-webpack but that throws a bunch of errors.Is there a way to use css-modules-require-hook with karma-webpack?
The text was updated successfully, but these errors were encountered: