0

I am trying to use jasmine for writing unit test for Angular services, firstly it was unable to find module "angularcli/plugins/karma' after a quick search i changed every instance of "angularcli" to "@angularcli" but still on running "ng test" problem exist. Here is the error:

20 07 2018 17:07:57.919:ERROR [config]: Error in config file!
 { Error: Cannot find module '@angular-cli/plugins/karma'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
    at Function.Module._load (internal/modules/cjs/loader.js:497:25)
    at Module.require (internal/modules/cjs/loader.js:626:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at module.exports (D:\new project\MarsWeb\MarsWeb-FrontEnd\karma.conf.js:13:7)
    at Object.parseConfig (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\karma\lib\config.js:396:5)
    at new Server (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\karma\lib\server.js:56:20)
    at Promise (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\tasks\test.js:45:33)
    at new Promise (<anonymous>)
    at Class.run (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\tasks\test.js:23:16)
    at Class.run (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\commands\test.js:122:25)
    at resolve (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\ember-cli\lib\models\command.js:261:20)
    at new Promise (<anonymous>)
    at Class.validateAndRun (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\ember-cli\lib\models\command.js:240:12)
    at Promise.resolve.then.then (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\ember-cli\lib\cli\cli.js:140:24)
    at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' }

i have updated karma.conf.js to work with @angular-cli still node can not find the module

here is my 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
    },
    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
    },
    coverage: {
      reports: {
        html: 'coverage',
        lcovonly: './coverage/coverage.lcov'
      }
    },
    angularCli: {
      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 this is dev dependencies from package.json

"devDependencies": {
        "@angular/cli": "^1.2.5",
        "@angular/compiler-cli": "^5.2.0",
        "@types/jasmine": "2.5.38",
        "@types/node": "~6.0.60",
        "codelyzer": "~2.0.0",
        "jasmine-core": "~2.5.2",
        "jasmine-spec-reporter": "~3.2.0",
        "karma": "~1.4.1",
        "karma-chrome-launcher": "~2.0.0",
        "karma-cli": "~1.0.1",
        "karma-coverage-istanbul-reporter": "^0.2.0",
        "karma-jasmine": "~1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "karma-remap-istanbul": "^0.6.0",
        "protractor": "~5.1.0",
        "ts-node": "~2.0.0",
        "tslint": "~4.5.0",
        "typescript": "^2.4.2"
    }

1 Answer 1

2

You need to change @angular-cli to @angular/cli in all the occurences.

Hope this helps!

Sign up to request clarification or add additional context in comments.

6 Comments

@Can you please mark my answer as answered then? :-)
yeah i did, SO was not allowing to mark your answer as answered so early. :)
No problem. Thanks! :-)
It is 2022 and this does not work. My packages were already @angular/cli to begin with.
@chitgoks for more recent versions of angular, its require('@angular-devkit/build-angular/plugins/karma')
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.