简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM