-
Notifications
You must be signed in to change notification settings - Fork 90
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
Rewire with Webpack and Karma #44
Comments
@bunkat I am not sure. But it could be that the problem is that you use babel loader twice. |
Same here... |
My problem was indeed loading the loader twice. That fixed it for me. |
This is happening to me as well. Not sure if its due to the fact that I'm loading webpack via karma? module.exports = function (config) {
config.set({
// browsers: ['PhantomJS'],
browsers: ['Chrome'],
frameworks: [
'jasmine',
'jasmine-matchers'
],
reporters: ['progress', 'beep'],
files: [
'https://code.jquery.com/jquery-2.1.4.js',
'public/scripts/vendor/tinymce/tinymce.full.js',
'karma.tests.webpack.js'
],
preprocessors: {
'karma.tests.webpack.js': [
'webpack',
'sourcemap'
]
},
webpack: {
devtool: 'inline-source-map',
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
plugins: ['babel-plugin-rewire']
}
}
]
}
},
webpackServer: {
noInfo: true
}
});
}; |
query: {
plugins: ['babel-plugin-rewire']
} I'd never seen the query for a loader written in this form before. According to the Webpack docs, {
test: /\.js$/,
loader: 'babel?plugins[]=babel-plugin-rewire'
} |
@volkanunsal This might be the case. We use babel-plugin-rewire with webpack and karma with the following loader config: |
Same here. Any solution for that? |
@screendriver could you please provide a simple failing sample project? |
I made a sample project Just make a |
I have a sample working project here, which you could have a look at and see if it helps. It was created with another reason in mind, but perhaps it is useful: https://github.com/jseminck/karma-rewire-istanbul-example |
@screendriver thank you for your sample project. I created two pull request for your sample project making it work. Could please let me know if this helps? |
@speedskater thank you. It seems to work. But how can I rewire the whole function instead extracting the return value to a variable? For example if I have a function that returns internal state or something? If I remove the |
@screendriver you can mock a complete function as long as it represents a dependency in the module (in this context a dependency is anything defined at module scope which is used seomewhere in the module e.g. variable, class, function, import..) |
I'm trying to get babel-plugin-rewire to work in a project based on react-boilerplate with inspiration from https://github.com/jseminck/karma-rewire-istanbul-example by @jseminck. I't doesn't mess with babel loader in webpack config, instead rewire is added in the plugins section in .babelrc. I think this is a good way to configure babel-plugin-rewire but when I try to do it in my project the tests passes but report generation fails. I have forked react-boilerplate, bumped some dependencies, changed karma config to use PhantomJS and added babel-plugin-rewire if someone would like to have a look https://github.com/olabalboa/react-boilerplate |
I can't figure out how to make this plugin work correctly. I'm using webpack and have installed the latest version of the plugin. I've tried adding the following to my webpack config:
I'm not seeing any errors from webpack, but when I then do the following:
sessionActions.js
tests/sessionActions-test.js
There is no
__Rewire__
call being added to the module. Obviously I'm missing something and I can't figure out what. How exactly does the plugin get loaded? How can I test to see if it is getting loaded correctly?I've also tried the following but then SesssionRewireAPI is just undefined.
The text was updated successfully, but these errors were encountered: