Karma: Strange error trying to run Jasmine specs

Created on 8 Jan 2014  Â·  24Comments  Â·  Source: karma-runner/karma

callum:tool-test $ gulp test
[gulp] Using file /Users/madebymany/tool-test/gulpfile.js
[gulp] Working directory changed to /Users/madebymany/tool-test
[gulp] Running 'scripts'...
[gulp] Finished 'scripts' in 4.52 ms
[gulp] Running 'test'...
/Users/madebymany/tool-test/src/main.js
[gulp] Starting Karma server...

/Users/madebymany/tool-test/node_modules/gulp-karma/node_modules/karma/node_modules/di/lib/injector.js:9
      throw error('No provider for "' + name + '"!');
            ^
Error: No provider for "framework:jasmine"! (Resolving: framework:jasmine)
    at error (/Users/madebymany/tool-test/node_modules/gulp-karma/node_modules/karma/node_modules/di/lib/injector.js:22:68)
    at Object.parent.get (/Users/madebymany/tool-test/node_modules/gulp-karma/node_modules/karma/node_modules/di/lib/injector.js:9:13)
    at get (/Users/madebymany/tool-test/node_modules/gulp-karma/node_modules/karma/node_modules/di/lib/injector.js:54:19)
    at /Users/madebymany/tool-test/node_modules/gulp-karma/node_modules/karma/lib/server.js:29:14
    at Array.forEach (native)
    at start (/Users/madebymany/tool-test/node_modules/gulp-karma/node_modules/karma/lib/server.js:28:21)
    at invoke (/Users/madebymany/tool-test/node_modules/gulp-karma/node_modules/karma/node_modules/di/lib/injector.js:75:15)
    at Object.exports.start (/Users/madebymany/tool-test/node_modules/gulp-karma/node_modules/karma/lib/server.js:272:12)
    at Object.<anonymous> (/Users/madebymany/tool-test/node_modules/gulp-karma/lib/background.js:3:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
[gulp] Finished 'test' in 566 ms

I have tried reinstalling Karma and associated modules. Explicitly installing karma-jasmine didn't seem to work (http://stackoverflow.com/questions/19185548/no-provider-error-on-karma-serve-running-angularjs-phonecat-tutorial).

support

Most helpful comment

I had the same problem. Adding 'karma-jasmine', 'karma-chrome-launcher' in the plugins fixed it.

  plugins : [
        require('karma-webpack'),
        'karma-jasmine',
        'karma-chrome-launcher'
    ]

All 24 comments

Karma needs to load the plugins (such as karma-jasmine). By default (if you don't specify config.plugins), Karma loads all the karma-* modules that are siblings to Karma.

It sounds like you have Karma installed globally (npm install -g karma) and jasmine plugin locally (npm install karma-jasmine). If that's the case, install Karma locally.

The recomended way is to install Karma and all the plugins locally, per project.

@vojtajina - I tried above steps but still I am getting the same issue. I have also tried with Visual Studio 2013 on Windows7 (64 bit) machine.

Unofrtunately, I am getting the same exception (on console) as mentioned above. In VS2013 its showing 'INFO: Starting karma server...'

P.S.: For vs2013, I am using Plugin

@garora Try remove global karma and install karma-cli global.
Then install karma local to the project and run karma.

Thanks

I am getting same error as garora. Tried all steps as by vojtajina but still getting this error. Any suggestions what to do?

@munishmehta27 Did you remove global karma?

Yes removed global karma then installed karma-cli globally. thereafter i installed karma local to project and then runned karma.

  1. npm uninstall karma -g
  2. npm install karma-cli -g
  3. npm install karma --save-dev
  4. grunt karma test -v
    Still getting "Warning: No provider for "framework:jasmine"! (Resolving: framework:jasmine)".
    Please help.

Thanks

@munishmehta27 can you post your karma.config.js and package.json?

Yes i did but issue is still there!!!

Please suggest

On Thu, Dec 11, 2014 at 8:28 PM, Maksim Ryzhikov [email protected]
wrote:

@munishmehta27 https://github.com/munishmehta27 Did you remove global
karma?

—
Reply to this email directly or view it on GitHub
https://github.com/karma-runner/karma/issues/880#issuecomment-66630137.

Hi Maksim,

Please find the attached ....

Thanks

On Fri, Dec 12, 2014 at 4:25 PM, Maksim Ryzhikov [email protected]
wrote:

@munishmehta27 https://github.com/munishmehta27 can you post your
karma.config.js and package.json?

—
Reply to this email directly or view it on GitHub
https://github.com/karma-runner/karma/issues/880#issuecomment-66758568.

Any progress with this, @munishmehta27 or @maksimr? I'm experiencing the same issue. Below are my config files. Thanks in advance!

_EDIT:_ I found the error in the below karma.config.js file. The configuration file specified a plugins configuration which was only setup to load the karma-webpack module. This caused the default "load all _karma-*_ modules" to be abandoned and hence the karma-jasmine module was not loaded. On to the next!

// Karma configuration
// Generated on Mon Feb 09 2015 11:38:40 GMT-0700 (Mountain Standard Time)

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

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


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


    // list of files / patterns to load in the browser
    files: [
      'app/build/*',
      'Test/*Spec.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: {
        'app/build/*': ['webpack', 'sourcemap'],
        'Test/*Spec.js': ['webpack', 'sourcemap'],
    },


    webpack: {
        devtool: 'inline-source-map'
    },


    webpackMiddleware: {
        // webpack-dev-middleware configuration
        noInfo: true
    },


    plugins: [
        require("karma-webpack")
    ],


    // 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: false
  });
};

package.json

{
  "name": "RVC",
  "version": "0.0.1",
  "description": "",
  "main": " ",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^0.9.0",
    "exports-loader": "^0.6.2",
    "expose-loader": "^0.6.0",
    "imports-loader": "^0.6.3",
    "jasmine-core": "^2.2.0",
    "karma": "^0.12.31",
    "karma-chrome-launcher": "^0.1.7",
    "karma-ie-launcher": "^0.1.5",
    "karma-jasmine": "^0.3.5",
    "karma-sourcemap-loader": "^0.3.3",
    "karma-webpack": "^1.5.0",
    "raw-loader": "^0.5.1",
    "style-loader": "^0.8.2"
  },
  "dependencies": {
    "knockout": "^3.2.0",
    "page": "^1.5.0",
    "webpack": "^1.4.14"
  }
}

I had the same problem. Adding 'karma-jasmine', 'karma-chrome-launcher' in the plugins fixed it.

  plugins : [
        require('karma-webpack'),
        'karma-jasmine',
        'karma-chrome-launcher'
    ]

Why this is closed?

Resolved this issue by checking if I had karma/jasmine installed globally:

npm ls -g karma
npm ls -g jasmine

Removed both, then npm install -g karma-cli and have jasmine+karma only locally installed

I had the same problem and the @raphaelhudvoy suggestion to add 'karma-jasmine' in the plugins inside karma.config.js fixed it.

Still having problem with VS2015

I can confirm that adding 'karma-jasmine' to the plugins works. I kinda wonder why the karma init does not add it if it becomes a necessary step now.

I have karma-cli installed globally, and karma, karma-jasmine locally.

I had the same problem, and uninstalling the global instance of karma fixed it for me, too. Since this is a 1.5 year old bug, it would make sense if the dev team found an actual fix for this...

Its again broke my dev environment

@EightArmCode it's not bug. If you run global karma then karma will try find global karma-jasmine that logical. Special for this case was made karma-cli which run project instance of karma that solve this issue.

Thanks!

npm install -g karma-cli
worked for me

I have included all the dependencies then working fine.
"devDependencies": {
"angular-mocks": "^1.3.12",
"jasmine": "^2.4.1",
"requirejs": "2.1",
"karma": "^0.10.10",
"karma-chrome-launcher": "0.1.2",
"karma-coffee-preprocessor": "0.1.3",
"karma-firefox-launcher": "0.1.0",
"karma-html2js-preprocessor": "0.1.0",
"karma-jasmine": "0.1.0",
"karma-phantomjs-launcher": "0.1.0",
"karma-requirejs": "0.2.0",
"karma-script-launcher": "0.1.0"
}

I resolved this problem doing:

rm -rf node_modules/
npm install --save-dev karma
npm install --save-dev karma-cli
npm install --save-dev jasmine
npm install --save-dev jasmine-core
npm install --save-dev karma-jasmine
npm install --save-dev karma-chrome-launcher
npm install --save-dev requirejs
npm install --save-dev karma-requirejs

I resolved this problem with this conf:

frameworks: ['jasmine'],
plugins: [
    require("karma-jasmine"),
 ]

by the way, i also get:

{ Error: Cannot find module 'PhantomJS'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)...

with:

browsers: ['PhantomJS'],

and I also resolved this problem with:

plugins: [
   require("karma-phantomjs-launcher")
],

maybe this will help somebody.

I struggled with the exact same problem. After investigating I realized that karma was running globally using '/usr/' directory as the base folder.

A solution that worked for me was to replace karma with karma-cli:

npm remove -g karma
npm install -g karma-cli
Was this page helpful?
0 / 5 - 0 ratings