Ad

Isparta Module Not Loading Properly So Can't Run Test Cases

My tests used to run absolutely fine, but all of a sudden I'm getting the following error while running tests. Please help. I'm stuck on this for two days.

It's a react project. I'm using web-pack and babel. Using isparta for code-coverage.

    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

This is my package.json:

{
  "name": "redux-scafford",
  "version": "0.1.0",
  "description": "combination of redux, react-router and ES7+ support ",
  "repository": "",
  "author": "MDL <[email protected]>",
  "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"
  }
}

And this is my karma config file:

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'
    ]
  });
};
Ad

Answer

Changed following things and it worked. 1) removedv 'isparta' from karma config plugin list. 2) instead of karma start I did ./node_modules/karma/bin/karma start.

The error was because if you do just karma start you are actually referring to globally installed karma, and that by default searches plugin modules in global space . And that karma, and globally installed plugin modules were out-dated, which wasn't working with newer isparta module.

Ad
source: stackoverflow.com
Ad