isparta 模块未正确加载,因此无法 运行 测试用例

isparta module not loading properly so can't run test cases

我的测试 曾经 运行 绝对没问题 ,但突然间我在 运行 测试时遇到以下错误。请帮忙。我坚持了两天。

这是一个反应项目。我正在使用 web-pack 和 babel。使用 isparta 进行代码覆盖。

    enter cosapMac:dealScore saptarshichatterjee$ karma start ./client/karma.conf.js
10 01 2016 09:43:36.482:DEBUG [config]: autoWatch set to false, because of singleRun
10 01 2016 09:43:36.488:DEBUG [plugin]: Loading plugin karma-browserify.
10 01 2016 09:43:36.924:DEBUG [plugin]: Loading plugin karma-chrome-launcher.
10 01 2016 09:43:36.932:DEBUG [plugin]: Loading plugin karma-jasmine.
10 01 2016 09:43:36.934:DEBUG [plugin]: Loading plugin karma-coverage.
10 01 2016 09:43:37.190:DEBUG [plugin]: Loading plugin isparta-instrumenter-loader.
10 01 2016 09:43:37.927:DEBUG [plugin]: Loading plugin babel-loader.
10 01 2016 09:43:38.310:DEBUG [plugin]: Loading plugin karma-webpack.
10 01 2016 09:43:38.587:DEBUG [plugin]: Loading plugin isparta.
/usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:116
        var type = module[name][0];
                               ^

TypeError: Cannot read property '0' of undefined
    at /usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:116:32
    at Array.forEach (native)
    at /usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:115:27
    at Array.forEach (native)
    at new Injector (/usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:104:11)
    at new Server (/usr/local/lib/node_modules/karma/lib/server.js:90:20)
    at Object.exports.run (/usr/local/lib/node_modules/karma/lib/cli.js:231:7)
    at Object.<anonymous> (/usr/local/lib/node_modules/karma/bin/karma:3:23)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)
    at node.js:963:3

这是我的package.json:

{
  "name": "redux-scafford",
  "version": "0.1.0",
  "description": "combination of redux, react-router and ES7+ support ",
  "repository": "",
  "author": "MDL <abc@abc.com>",
  "src": "src",
  "test": "test",
  "dist": "dist",
  "mainInput": "main",
  "mainOutput": "main",
  "dependencies": {
    "belle": "^1.2.2",
    "griddle-react": "^0.2.14",
    "i18next": "^2.0.1",
    "immutable": "^3.7.4",
    "jquery": "^2.1.4",
    "jsxstyle": "0.0.17",
    "lodash": "^3.10.1",
    "moment": "^2.10.6",
    "radium": "^0.13.7",
    "react": "0.13.x",
    "react-redux": "^1.0.1",
    "react-router": "1.0.0-beta3",
    "redux": "^1.0.1",
    "redux-thunk": "^0.1.0"
  },
  "devDependencies": {
    "autoprefixer-loader": "^2.0.0",
    "babel-core": "5.8.23",
    "babel-eslint": "^4.0.10",
    "babel-loader": "5.3.2",
    "babel-runtime": "^5.8.20",
    "babelify": "^6.3.0",
    "css-loader": "~0.17.0",
    "del": "^2.0.1",
    "ecstatic": "^0.8.0",
    "eslint": "^1.1.0",
    "eslint-config-airbnb": "0.0.8",
    "eslint-config-airplus": "^1.0.4",
    "eslint-loader": "^1.0.0",
    "eslint-plugin-react": "^3.2.3",
    "express": "^4.13.3",
    "gulp": "^3.9.0",
    "gulp-load-plugins": "^1.0.0-rc.1",
    "gulp-serve": "^1.0.0",
    "gulp-size": "^2.0.0",
    "http-proxy": "^1.11.1",
    "isparta": "^3.5.1",
    "isparta-instrumenter-loader": "^0.2.1",
    "karma-browserify": "^4.4.0",
    "karma-chrome-launcher": "^0.2.0",
    "karma-cli": "^0.1.1",
    "karma-coverage": "^0.5.2",
    "karma-jasmine": "^0.3.6",
    "karma-webpack": "^1.7.0",
    "raw-loader": "^0.5.1",
    "react-hot-loader": "^1.2.8",
    "redux-devtools": "~1.0.2",
    "run-sequence": "^1.1.2",
    "style-loader": "^0.12.4",
    "url-loader": "~0.5.6",
    "webpack": "~1.12.1",
    "webpack-dev-server": "~1.10.1"
  }
}

这是我的业力配置文件:

const babelify = require('babelify');
var path = require('path');

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['browserify', 'jasmine'],
    plugins: [
      'karma-browserify',
      'karma-chrome-launcher',
      'karma-jasmine',
      'karma-coverage',
      'isparta-instrumenter-loader',
      'babel-loader',
      'karma-webpack',
      'isparta' 
    ], // If you see `cant find plugin errors` npm install -g above plugins.
    // start these browsers
    browsers: ['Chrome'],
    reporters: ['progress', 'coverage'],
    preprocessors: {
      './src/tests/testsuits/**/*.js': ['webpack'],
    },
    coverageReporter: {
      type: 'html',
      dir: 'src/tests/coverage'
    },
    logLevel: config.LOG_BEBUG,
    singleRun: true,
    webpack: {
      module: {
        loaders: [{
          test: /\.js?$/,
          loader: 'babel-loader',
          include: path.resolve(__dirname, './src')
        }],
        preLoaders: [{
          test: /\.js?$/,
          exclude: [/node_modules/, /\.spec\.js/],
          loader: 'isparta-instrumenter-loader'
        }, ]
      }
    },
    webpackServer: {
      noInfo: true
    },
    files: [
      './src/tests/testsuits/**/*.js'
    ]
  });
};

更改了以下内容并且有效。 1) 从 karma 配置插件列表中删除了 v 'isparta'。 2) 而不是 karma start 我做了 ./node_modules/karma/bin/karma 开始。

错误是因为如果你只做 karma start 你实际上指的是全局安装的业力,并且默认情况下搜索全局 space 中的插件模块。而那个 karma 和全局安装的插件模块是 out-dated,它不能与更新的 isparta 模块一起工作。