David Schilling
David Schilling

Reputation: 2770

How to use globally installed Karma plugins

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?

Upvotes: 1

Views: 2124

Answers (1)

glepretre
glepretre

Reputation: 8167

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.

Upvotes: 1

Related Questions