mardi 7 mars 2017

Cannot run Karma with Angular-cli

I encounter a strange problem that happens to one of my projects and cannot reproduce it in others even with exactly the same setup.

Every time I try to run ng test or the alias npm test I'm getting errors that two modules are missing (karma-jasmine-html-reporter & karma-coverage-istanbul-reporter). The modules though are for sure there! For example:

web-app@0.0.3-alpha test /Users/vassilis/Projects/WebApp ng test

07 03 2017 12:08:27.157:ERROR [config]: Error in config file! { Error: Cannot find module 'karma-jasmine-html-reporter' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at module.exports (/Users/vassilis/Projects/WebApp/karma.conf.js:11:7) at Object.parseConfig (/Users/vassilis/Projects/WebApp/node_modules/karma/lib/config.js:342:5) at new Server (/Users/vassilis/Projects/WebApp/node_modules/karma/lib/server.js:56:20) at /Users/vassilis/Projects/WebApp/node_modules/@angular/cli/tasks/test.js:26:31 at Class.run (/Users/vassilis/Projects/WebApp/node_modules/@angular/cli/tasks/test.js:10:16) at Class.run (/Users/vassilis/Projects/WebApp/node_modules/@angular/cli/commands/test.js:29:25) at Class. (/Users/vassilis/Projects/WebApp/node_modules/@angular/cli/ember-cli/lib/models/command.js:134:17) at process._tickCallback (internal/process/next_tick.js:103:7) code: 'MODULE_NOT_FOUND' } npm ERR! Test failed. See above for more details.

This is my setup:

karma.conf.js
module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    files: [
      { pattern: './src/test.ts', watched: false }
    ],
    preprocessors: {
      './src/test.ts': ['@angular/cli']
    },
    mime: {
      'text/x-typescript': ['ts','tsx']
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      config: './angular-cli.json',
      environment: 'dev'
    },
    reporters: config.angularCli && config.angularCli.codeCoverage
              ? ['progress', 'coverage-istanbul']
              : ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

And the related part in angular-cli.json:
"test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  }

I am really confused over here. It seems project related issue but I cannot be sure if Karma don't even run at all. Any ideas on this?

Aucun commentaire:

Enregistrer un commentaire