1

I have installed some karma plugins, like: karma-requirejs, karma-jasmine... globally using npm install -g

Now i want to use them in a karma test execution. The only way i found to use them ist to use the require function in the plugins section of the karma config:

plugins: [

      require('/usr/local/lib/node_modules/karma-requirejs'),
      require('/usr/local/lib/node_modules/karma-jasmine'),
      require('/usr/local/lib/node_modules/karma-junit-reporter'),
      require('/usr/local/lib/node_modules/karma-phantomjs-launcher'),
      require('/usr/local/lib/node_modules/karma-coverage'),
      require('/usr/local/lib/node_modules/karma-requirejs')
  ],

I thought karma would first look at the local node_modules and then at the global. But i have to set the full Path. Is there a way to use the global installed plugins without the full path?

David Schilling
  • 2,442
  • 3
  • 17
  • 24
  • Global modules are for command line tools. They are not shared modules! So you should not `require` them despite that there some trick to do that. – damphat Jul 10 '14 at 16:13
  • I have a setup without internet and without the possibility to use a local replicated couchdb for the npm registry. And i thought the best way, although it doesn't sound nice, would be to copy all plugins to the global npm directory. Because i have a lot of projects depending on them and to copy the plugins to all projects would be a lot of work. – David Schilling Jul 11 '14 at 07:15

1 Answers1

1

It looks like a bad practice to me... but, you can do it this way I think:

  • List them as usual in your karma config:
plugins: [
  'karma-requirejs',
  'karma-jasmine',
  'karma-junit-reporter',
  'karma-phantomjs-launcher',
  'karma-coverage',
  'karma-requirejs'
],
  • Don't add them to your package.json (npm)
"devDependencies": {
  "karma": "0.12.17"
  // remove all the plugins listed above
}

NB: Karma will use the globally installed node modules and throw an error if one is missing.

glepretre
  • 8,154
  • 5
  • 43
  • 57
  • @eugene82 Which aspect would you like me to emphasize? I thought the `NB` was clear enough but let me know if you think I can improve this answer ;) – glepretre Jan 30 '15 at 13:09
  • I mean, a global instance of Karma may be used so that it won't be declared as a dependency. In such case installing the plugins as globals is a must. – eugene82 Feb 02 '15 at 13:42