karma-runner / karma-commonjs

A Karma plugin. Test CommonJS modules.
MIT License
73 stars 30 forks source link

Requiring node_modules works and I don't know why #40

Closed jednano closed 9 years ago

jednano commented 9 years ago

I know that we're supposed to reference any and all node_modules in the karma.conf.js if we want to require them, but I accidentally stumbled upon a scenario in which that isn't required.

In my case, I'm using browserify as a build process, but I don't have this luxury in karma, because I need to generate a coverage report and browserify messes all that up (unless I'm doing something wrong).

Anyway, long story short, I figured out that adding the following to my package.json allows me to get accurate coverage reports w/o karma-commonjs throwing errors that it can't find a node module:

{
  "devDependencies": {
    "karma-commonjs": "git://github.com/karma-runner/karma-commonjs.git#v0.0.12"
  }
}

If I do a normal npm install --save-dev karma-commonjs I get errors that I can't find the react node_module, but if I manually specify the github repo and tag name, all is well.

The thing that scares me is that I don't know WHY this works! Can you think of anything?

Here's my karma.conf.js:

module.exports = function(config) {
    config.set({

        basePath: '',

        frameworks: ['jasmine', 'commonjs'],

        files: [
            'lib/src/**/*.js',
        ],

        exclude: [
        ],

        preprocessors: {
            'lib/src/**/*.js': ['commonjs'],
            'lib/src/**/*[^(\.spec)].js': ['coverage']
        },

        reporters: ['progress', 'coverage'],

        coverageReporter: {
            type: 'lcov'
        },

        port: 9876,

        colors: true,

        logLevel: config.LOG_INFO,

        autoWatch: true,

        browsers: ['PhantomJS'],

        singleRun: false
    });
};
jednano commented 9 years ago

FWIW, I did an npm cache clean before each npm install command and diffed the two karma-commonjs installations and the only thing different is their package.json files, which have the whole path in the _from key, so I'm still utterly confused.

pkozlowski-opensource commented 9 years ago

@jedmao I'm afraid that nothing comes to my mind based on your description... If you would put together a small repo with the reproduce scenario maybe someone would have an idea...

pkozlowski-opensource commented 9 years ago

@jedmao closing this issue since I haven't heard from you and it is impossible to guess what is going on without minimal reproduce scenario. Feel free to re-open when you've got a small repo that shows the issue.