Karma-找不到插件 [英] karma - Cannot find plugin

查看:27
本文介绍了Karma-找不到插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Karma运行js测试用例。但总是收到找不到插件的错误。有趣的是相同的配置文件,对我的其他同事来说工作正常

日志如下:

$ karma start karma.conf.js 
04 10 2016 17:51:24.755:ERROR [plugin]: Cannot find plugin "karma-babel-preprocessor".
  Did you forget to install it?
  npm install karma-babel-preprocessor --save-dev
04 10 2016 17:51:24.769:ERROR [plugin]: Cannot find plugin "karma-mocha".
  Did you forget to install it?
  npm install karma-mocha --save-dev
04 10 2016 17:51:24.778:ERROR [plugin]: Cannot find plugin "karma-chrome-launcher".
  Did you forget to install it?
  npm install karma-chrome-launcher --save-dev
04 10 2016 17:51:24.791:ERROR [preprocess]: Can not load "babel", it is not registered!
  Perhaps you are missing some plugin?
/usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:9
      throw error('No provider for "' + name + '"!');
      ^

Error: No provider for "framework:mocha"! (Resolving: framework:mocha)
    at error (/usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:22:12)
    at Object.parent.get (/usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:9:13)
    at get (/usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:54:19)
    at /usr/local/lib/node_modules/karma/lib/server.js:143:20
    at Array.forEach (native)
    at Server._start (/usr/local/lib/node_modules/karma/lib/server.js:142:21)
    at invoke (/usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)
    at Server.start (/usr/local/lib/node_modules/karma/lib/server.js:103:18)
    at Object.exports.run (/usr/local/lib/node_modules/karma/lib/cli.js:280:26)
    at Object.<anonymous> (/usr/local/lib/node_modules/karma/bin/karma:3:23)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)

这里是karma.config.js

// Karma configuration
// Generated on Thu Jan 28 2016 12:33:59 GMT-0500 (EST)

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

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    plugins: [
      'karma-babel-preprocessor', 
      'karma-mocha',
      'karma-chrome-launcher',
    ],

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['mocha', 'chai'],


    // list of files / patterns to load in the browser
    files: [
      '.venv/lib/python2.7/site-packages/xstatic/pkg/jquery/data/jquery.min.js',
      '.venv/lib/python2.7/site-packages/horizon/static/horizon/js/horizon.js',
      '.venv/lib/python2.7/site-packages/horizon/static/horizon/js/horizon.quota.js',
      '.venv/lib/python2.7/site-packages/horizon/static/horizon/js/horizon.instances.js',
      'myapp/static/comp/js/pricing.js',
      'myapp/test/js/**/*.js'
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'myapp/test/js/**/*.js': ['babel']
    },

    babelPreprocessor: {
      options: {
        presets: ['es2015'],
        sourceMap: 'inline'
      },
      filename: function (file) {
        return file.originalPath.replace(/.js$/, '.es5.js');
      },
      sourceFileName: function (file) {
        return file.originalPath;
      }
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: true,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  })
}

这里是Package.json

{
  "name": "comp_horizon",
  "version": "1.0.0",
  "description": "some description",
  "main": "index.js",
  "scripts": {
    "test": "node node_modules/karma/bin/karma start karma.conf.js --single-run"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/priverepo/comp_horizon.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/priverepo/comp_horizon/issues"
  },
  "homepage": "https://github.com/priverepo/comp_horizon#readme",
  "devDependencies": {
    "babel": "^6.3.26",
    "babel-core": "^6.4.5",
    "babel-loader": "^6.2.1",
    "babel-preset-es2015": "^6.3.13",
    "chai": "^3.4.1",
    "karma": "^0.13.19",
    "karma-babel-preprocessor": "^6.0.1",
    "karma-chai": "^0.1.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-coverage": "0.3.1",
    "karma-mocha": "^1.2.0",
    "mocha": "^3.1.0",
    "webpack": "^1.12.12",
    "webpack-bundle-tracker": "0.0.93"
  },
  "dependencies": {
    "babel-polyfill": "^6.3.14"
  }
}
对于无法文件插件错误,我正在安装该插件。但错误仍然存在。例如,对于找不到插件"karma-babel-pre处理器",我做了NPM安装karma-babel-pre处理器--save-dev。它被找到了。但仍收到错误。

谢谢

推荐答案

我安装了karma-requirejsnpm i -D karma-requirejs Karma抱怨说它找不到那个模块 直到我试了才知道

plugins: [
  require("karma-requirejs")
]

在我看到错误堆栈跟踪的karma.conf.js中:karma-requirejs不包括requirejs作为依赖项。

我用npm i -D requirejs

解决了问题

这篇关于Karma-找不到插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆