karma-runner / karma-commonjs

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

Simple example #46

Closed danielzen closed 9 years ago

danielzen commented 9 years ago

I know that you say "For an example project, check out Karma's client tests."

I was trying to create an extremely simple example with a minimum configuration. But I am getting an error

ReferenceError: Can't find variable: global

in the Jasmine2 library. I have put more detail at StackOverflow, but I would be remiss if I didn't ask here... Any help much appreciated, and would be glad to add to examples.

danielzen commented 9 years ago

It seems like my whole problem came down to the line in karma.conf.js (not shown in my original question:

preprocessors: {
  '**/*.js': ['commonjs']
},

For some reason, jasmine.js is not happy being pre-processed by commonjs, and "*/.js" says to go through all subdirectories (which is probably overkill), including node_modules which has jasmine-core/jasmine.js

So I can either make my pre-processor more specific (best practice):

preprocessors: {
  'spec/*.js': ['commonjs'],
  'js/*.js': ['commonjs']
},

but as a test to see if any other files would give me a problem, I tried:

preprocessors: {
  '**/!(jasmine).js': ['commonjs'],
},

And, everything worked as well. Bottom line. Do not process jasmine.js through commonjs preprocessor!