JASMINE not defined when I try to run Karma test runner
Solution 1
If you want to use the latest stable Karma version (0.10.9) you should define Jasmine in the frameworks
section and be sure to have karma-jasmine in the plugins
section, in your karma configuration file.
Here's an example config file:
karma.conf.js
module.exports = function(config){
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// list of files / patterns to load in the browser
files: [
{pattern: 'app/**/*.js', watched: true, included: true, served: true}
],
// list of files to exclude
exclude: [
],
preprocessors: {
},
proxies: {
},
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
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,
autoWatch: true,
// frameworks to use
frameworks: ['jasmine'],
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
'Chrome'
],
plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-script-launcher',
'karma-jasmine'
],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
Source: Karma-runner docs
Solution 2
Including JASMINE
and JASMINE_ADAPTER
in the files array is applicable to Karma versions 0.8.x and down. With newer versions of Karma, that is version 0.13 currently, just remove those 2 lines from the files array since you are already loading Jasmine as the framework(framework=['jamsine']
).
tengen
Front end web developer specializing in javascript and its various flavors of awesome.
Updated on June 17, 2022Comments
-
tengen almost 2 years
I am trying to hook up the Karma test runner, using this seed project as a model.
I pull the seed project in, build it, and the test runner works great.
When I edit the
karma.conf.js
config file to start including the files from my project, and move it to my current setup (outside the seed project), I get this error:Running "karma:dev" (karma) task ERROR [config]: Error in config file! [ReferenceError: JASMINE is not defined] ReferenceError: JASMINE is not defined at module.exports (C:\dev_AD_2014.01_PHASE1\config\karma-dev.conf.js:4:7) ...
I think I see what it's complaining about... in the seed project, it's karma config file is of an older format, that must have
JASMINE
andJASMINE_ADAPTER
defined somewhere:Seed Project karma config snippet
files = [ JASMINE, JASMINE_ADAPTER, '../app/lib/angular/angular.js', 'lib/angular/angular-mocks.js', '../app/js/*.js', .... ]; exclude = ['karma.conf.js']; ...
My newer setup uses all the latest grunt plugins, and wants the config file wrapped in a module definition like so:
My karma config snippet
module.exports = function(config) { config.set({ files: [ JASMINE, JASMINE_ADAPTER, // library and vendor files '../dev/vendor/**/*.js' '../dev/app/**/*.js' ], exclude: ['**/*.e2e.js', '../config/*.js'], reporters: ['progress'], ...
So it seems the problem is clear: the newer version(s) of some grunt plugins expect the modular definition, but are longer is setting up
JASMINE
, etc, as variables that are defined. That's my guess, but I'm a little lost on how to resolve this. I don't want to use the version of Karma that comes with the seed project if I can help it... I think it's version 0.4.4. I believe the newest stable version is 0.10.x.What am I doing wrong?
Thanks!
-
fracz about 10 yearsYou have defined
frameworks
section twice in your config file which is not necessary. -
glepretre about 10 years@WojciechFrącz you're right! Thanks for pointing this out ;) I edited the answer :)