Coder Social home page Coder Social logo

grunt-karma's Introduction

grunt-karma

js-standard-style npm version npm downloads

Build Status Dependency Status devDependency Status

Grunt plugin for Karma

This current version uses karma@^3.0.0. For using older versions see the old releases of grunt-karma.

Getting Started

From the same directory as your project's Gruntfile and package.json, install karma and grunt-karma with the following commands:

$ npm install karma --save-dev
$ npm install grunt-karma --save-dev

Once that's done, add this line to your project's Gruntfile:

grunt.loadNpmTasks('grunt-karma');

Config

Inside your Gruntfile.js file, add a section named karma, containing any number of configurations for running karma. You can either put your config in a [karma config file] or leave it all in your Gruntfile (recommended).

Here's an example that points to the config file:

karma: {
  unit: {
    configFile: 'karma.conf.js'
  }
}

Here's an example that puts the config in the Gruntfile:

karma: {
  unit: {
    options: {
      files: ['test/**/*.js']
    }
  }
}

You can override any of the config file's settings by putting them directly in the Gruntfile:

karma: {
  unit: {
    configFile: 'karma.conf.js',
    port: 9999,
    singleRun: true,
    browsers: ['PhantomJS'],
    logLevel: 'ERROR'
  }
}

To change the logLevel in the grunt config file instead of the karma config, use one of the following strings: OFF, ERROR, WARN, INFO, DEBUG

The files option can be extended "per-target" in the typical way Grunt handles files:

karma: {
  options: {
    files: ['lib/**/*.js']
  },
  unit: {
    files: [
      { src: ['test/**/*.js'] }
    ]
  }
}

When using the "Grunt way" of specifying files, you can also extend the file objects with the options supported by karma:

karma: {
  unit: {
    files: [
      { src: ['test/**/*.js'], served: true },
      { src: ['lib/**/*.js'], served: true, included: false }
    ]
  }
}

Config with Grunt Template Strings in files

When using template strings in the files option, the results will flattened. Therefore, if you include a variable that includes an array, the array will be flattened before being passed to Karma.

Example:

meta: {
  jsFiles: ['jquery.js','angular.js']
},
karma: {
  options: {
    files: ['<%= meta.jsFiles %>','angular-mocks.js','**/*-spec.js']
  }
}

Sharing Configs

If you have multiple targets, it may be helpful to share common configuration settings between them. Grunt-karma supports this by using the options property:

karma: {
  options: {
    configFile: 'karma.conf.js',
    port: 9999,
    browsers: ['Chrome', 'Firefox']
  },
  continuous: {
    singleRun: true,
    browsers: ['PhantomJS']
  },
  dev: {
    reporters: 'dots'
  }
}

In this example the continuous and dev targets will both use the configFile and port specified in the options. But the continuous target will override the browser setting to use PhantomJS, and also run as a singleRun. The dev target will simply change the reporter to dots.

Running tests

There are three ways to run your tests with karma:

Karma Server with Auto Runs on File Change

Setting the autoWatch option to true will instruct karma to start a server and watch for changes to files, running tests automatically:

karma: {
  unit: {
    configFile: 'karma.conf.js',
    autoWatch: true
  }
}

Now run $ grunt karma

Karma Server with Grunt Watch

Many Grunt projects watch several types of files using grunt-contrib-watch. Config karma like usual (without the autoWatch option), and add background:true:

karma: {
  unit: {
    configFile: 'karma.conf.js',
    background: true,
    singleRun: false
  }
}

The background option will tell grunt to run karma in a child process so it doesn't block subsequent grunt tasks.

The singleRun: false option will tell grunt to keep the karma server up after a test run.

Config your watch task to run the karma task with the :run flag. For example:

watch: {
  //run unit tests with karma (server needs to be already running)
  karma: {
    files: ['app/js/**/*.js', 'test/browser/**/*.js'],
    tasks: ['karma:unit:run'] //NOTE the :run flag
  }
},

In your terminal window run $ grunt karma:unit:start watch, which starts the karma server and the watch task. Now when grunt watch detects a change to one of your watched files, it will run the tests specified in the unit target using the already running karma server. This is the preferred method for development.

Single Run

Keeping a browser window & karma server running during development is productive, but not a good solution for build processes. For that reason karma provides a "continuous integration" mode, which will launch the specified browser(s), run the tests, and close the browser(s). It also supports running tests in PhantomJS, a headless webkit browser which is great for running tests as part of a build. To run tests in continous integration mode just add the singleRun option:

karma: {
  unit: {
    configFile: 'config/karma.conf.js',
  },
  //continuous integration mode: run tests once in PhantomJS browser.
  continuous: {
    configFile: 'config/karma.conf.js',
    singleRun: true,
    browsers: ['PhantomJS']
  },
}

The build would then run grunt karma:continuous to start PhantomJS, run tests, and close PhantomJS.

Using additional client.args

You can pass arbitrary client.args through the commandline like this:

$ grunt karma:dev watch --grep=mypattern

License

MIT License

grunt-karma's People

Contributors

antarasi avatar aslansky avatar cevou avatar christianreed avatar chriswren avatar dcherman avatar dependabot[bot] avatar dignifiedquire avatar eddiemonge avatar edg2s avatar geddski avatar greenkeeperio-bot avatar jdforrester avatar johnjbarton avatar jonnyarnold avatar jpommerening avatar julkue avatar jvinai avatar kavu avatar killmenot avatar krinkle avatar luis-almeida avatar mgol avatar mikedimmickmnetics avatar nicbright avatar psyked avatar semantic-release-bot avatar trabianmatt avatar xhmikosr avatar zzo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-karma's Issues

grunt-karma not closing out browser instances

I have grunt configured to run using regarde as described in the README, but grunt isn't a particularly stable process (by default, it dies every time a test fails, and even if you fix that using --force, it crashes occasionally anyway).

When running it this way, I notice it often leaves PhantomJS open after grunt dies, and when I restart the process, Karma is listening to both Phantoms (see karma-runner/karma#509). (I've actually gotten it up to four.) I can fix this by manually killing all the open 'testacular' processes, but it'd be nice if it could prevent these processes outliving their master.

When using background mode, task initialisation does not run tests

If I have a target with the option background set to true, when it is initialised, the tests do not run. They only run when my watch tasks calls karma:[target]:run.

It would be good if Karma did run the tests upon initialisation, as well as every time the run task is triggered by my watch.

Customize "files" option in Gruntfile

Hi there,

I wanted to override the "files" parameters of my karma.conf.js inside grunt-karma plugin. My use case is having a list of common files (like all AngularJS files) and adding either underscore or lodash to test that the library is compatible with both third part libraries.

My first idea was something like:

karma: {
  options: {
    configFile: 'karma.conf.js',
    browsers: ['PhantomJS']
  },
  buildLodash: {
    files: [
       JASMINE,
       JASMINE_ADAPTER,
      'http://code.angularjs.org/1.1.4/angular.js',
      'http://code.angularjs.org/1.1.4/angular-resource.js',
      'http://code.angularjs.org/1.1.4/angular-mocks.js',
      'http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.1.1/lodash.js',
      'src/*.js',
      'test/*.js'
      'src/*.js',
      'test/*.js'
    ],
    singleRun: true
  },
  buildUnderscore: {
    files: [
       JASMINE,
       JASMINE_ADAPTER,
      'http://code.angularjs.org/1.1.4/angular.js',
      'http://code.angularjs.org/1.1.4/angular-resource.js',
      'http://code.angularjs.org/1.1.4/angular-mocks.js',
      'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore.js',
      'src/*.js',
      'test/*.js'
    ],
    singleRun: true
  }
}

But that didn't work because JASMINE is not defined... fair enough. Is there a way to define both JASMINE and JASMINE_ADAPTER? I saw there was defined inside grunt-karma/node_modules/karma/lib/config.js but I have no idea how to import them...

As an alternative, what would think about a way to extend the arrays from the config file rather than only overriding them? Something like filesExtend, exludeExtend, reportersExtend and browersExtend options which would apply a concat between the array from the karma.conf.js file and the Gruntfile. It could be extend a second time inside tasks. Example:

karma.conf.js

files = [
  JASMINE,
  JASMINE_ADAPTER
]

Gruntfile.js

karma: {
  options: {
    configFile: 'karma.conf.js',
    browsers: ['PhantomJS'],
    filesExtend: [
      'http://code.angularjs.org/1.1.4/angular.js',
      'http://code.angularjs.org/1.1.4/angular-resource.js',
      'http://code.angularjs.org/1.1.4/angular-mocks.js',
      'src/*.js',
      'test/*.js'
    ]
  },
  buildLodash: {
    filesExtend: [
      'http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.1.1/lodash.js'
    ],
    singleRun: true
  },
  buildUnderscore: {
    filesExtend: [
      'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore.js'
    ],
    singleRun: true
  }
}

This would produce the expected result : both builds would have all AngularJS and JASMINE files, and either lodash or underscore depending on the task.

What do you think?

Test failure should cause a "ding" to the console

If the jshint task defined by grunt-contrib-jshint fails, the OS X terminal icon jumps in dock and shows a number of alerts displayed:
Terminal alert
This is probably sth system-independent so Linux terminals should behave in the same way.

This also doesn't stop the watch task defined by grunt-contrib-watch. This is extremely useful in a continuous testing scenario for which karma is created. It would be incredibly useful if the grunt-karma task behaved in the same way.

grunt-karma and watch nospawn dont play along very well

Is it possible to run karma using watch (grunt-contrib-watch) when the watch task is set with "nospawn": true

watch:{
            dev: {
                options: {
                    interrupt: true,
                    nospawn: true
                },
                files: [............],
                tasks:['concat:dev', 'karma:dev:run']
            }
}
karma: {
            dev: {
                configFile: 'config.js',
                browsers: ['PhantomJS'],
                background: true,
                singleRun: false
            }
}

It currently only works when i dont use the nospawn configuration to watch.
i would like to use nospawn since the watcher runs a lot faster that way on my env.

Thanks, your help is highly appreciated :)

ReferenceError: module is not defined

If I try to launch the karma using grunt, I get this error:

$ grunt karma:unit
Running "karma:unit" (karma) task
[2013-08-11 09:32:48.977] [ERROR] config - Invalid config file!
 [ReferenceError: module is not defined]

The karma:unit task is the default one:

    karma: {
      unit: {
        configFile: 'karma.conf.js',
        singleRun: true
      }
    }

The funny thing is that launching karma directly works without issues:

$ karma start
INFO [karma]: Karma v0.10.1 server started at http://localhost:9876/
INFO [Chrome 23.0.1271 (Windows 7)]: Connected on socket id rwyNL2Rpse1w7jb-q7jt
Chrome 23.0.1271 (Windows 7): Executed 1 of 1 SUCCESS (0.467 secs / 0.012 secs)

package.json if needed:

{
  "name": "testage",
  "version": "0.0.0",
  "dependencies": {},
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-copy": "~0.4.1",
    "grunt-contrib-concat": "~0.3.0",
    "grunt-contrib-coffee": "~0.7.0",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-compass": "~0.3.0",
    "grunt-contrib-jshint": "~0.6.0",
    "grunt-contrib-cssmin": "~0.6.0",
    "grunt-contrib-connect": "~0.3.0",
    "grunt-contrib-clean": "~0.4.1",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-imagemin": "~0.1.4",
    "grunt-contrib-watch": "~0.4.0",
    "grunt-usemin": "~0.1.11",
    "grunt-svgmin": "~0.2.0",
    "grunt-rev": "~0.1.0",
    "grunt-karma": "~0.4.3",
    "grunt-open": "~0.2.0",
    "grunt-concurrent": "~0.3.0",
    "grunt-google-cdn": "~0.2.0",
    "grunt-ngmin": "~0.0.2",
    "matchdep": "~0.1.2",
    "connect-livereload": "~0.2.0",
    "karma-chrome-launcher": "~0.1.0",
    "karma-firefox-launcher": "~0.1.0",
    "karma-script-launcher": "~0.1.0",
    "karma-html2js-preprocessor": "~0.1.0",
    "karma-jasmine": "~0.1.0",
    "karma-requirejs": "~0.1.0",
    "karma-coffee-preprocessor": "~0.1.0",
    "karma-phantomjs-launcher": "~0.1.0",
    "karma": "~0.10.1"
  },
  "engines": {
    "node": ">=0.8.0"
  },
  "scripts": {
    "test": "grunt test"
  }
}

Am I doing something wrong?

how to configure 2 karma tasks on different config files?

Imagine you have unit and e2e suites of tests, each using it's own config file.

How can I set up grunt-karma for each of them with a specific task for each one?

I don't get the grunt.initConfig part of it, when you an only have a single karma property.

No output from background mode

So I just gave background: true a shot. While it does indeed allow other tasks to keep chugging along, I'm not even sure that it's running.

I don't see any output in the terminal and I'm not seeing any growls show up either.

This is on Win7 x64 / Node 0.8.21

TypeError: Cannot read property 'os' of undefined

I've been receiving numerous reports of errors using the Grunt Karma task within the Backbone Boilerplate project.

See issue reported here: tbranyen/backbone-boilerplate#244

I've reproduced this problem myself as well. Upon running grunt --stack karma I've observed the following output:

Fatal error: Cannot read property 'os' of undefined
TypeError: Cannot read property 'os' of undefined
    at Agent.lazyparse (/tmp/tmp.ekvu9jMU0T/node_modules/karma/node_modules/useragent/index.js:75:7)
    at Object.exports.browserFullNameToShort (/tmp/tmp.ekvu9jMU0T/node_modules/karma/lib/helper.js:9:40)
    at new Browser (/tmp/tmp.ekvu9jMU0T/node_modules/karma/lib/browser.js:38:21)
    at invoke (/tmp/tmp.ekvu9jMU0T/node_modules/karma/node_modules/di/lib/injector.js:75:15)
    at instantiate (/tmp/tmp.ekvu9jMU0T/node_modules/karma/node_modules/di/lib/injector.js:59:20)
    at Socket.<anonymous> (/tmp/tmp.ekvu9jMU0T/node_modules/karma/lib/server.js:101:13)

This appears to be a problem with the useragent library that is a dependency of Karma. Perhaps a version bump is necessary? I am unsure how it is used within Karma.

grunt config not finding jasmine? (`describe` is not defined)

Following issue using versions:

grunt 0.4.1
grunt-cli 0.1.6
grunt-karma 0.4.4
karma 0.9.2

$> karma start <path to config> works fine, but when I run:

$> grunt -v karma:unit, with the minimal grunt-karma config;

karma: {

    unit: {
        configFile: 'unit.conf.js'
    }

}

where the karma config file contains:

basePath = './';

frameworks = ['jasmine']

files = [
  'app/lib/angular.js',
  'test/lib/angular/angular-mocks.js',
  'app/js/**/*.js',
  'test/unit/**/*.js'
];

autoWatch = true;

browsers = ['Chrome'];

junitReporter = {
  outputFile: 'test_out/unit.xml',
  suite: 'unit'
};

...[grunt] isn't able to find Jasmine, i've tried putting my karma config in the application root, in case it was a path issue. Full output below..

Initializing
Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

[...]

Registering "grunt-karma" local Npm module tasks.
Reading /path/to/project/node_modules/grunt-karma/package.json...OK
Parsing /path/to/project/node_modules/grunt-karma/package.json...OK
Loading "grunt-karma.js" tasks...OK
+ karma

Running tasks: karma:unit

Running "karma:unit" (karma) task
Verifying property karma.unit exists in config...OK
File: [no files]
INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 26.0 (Mac)]: Connected on socket id ynrvuZlQN6l4FPt1-C85
Chrome 26.0 (Mac) ERROR
    Uncaught ReferenceError: describe is not defined
    at /path/to/project/test/unit/controllerSpec.js:1
Chrome 26.0 (Mac): Executed 0 of 0
๏ฟฝ[1A๏ฟฝ[2KChrome 26.0 (Mac): Executed 0 of 0 ERROR (0.082 secs / 0 secs)

"Fatal error: Parse Error" when using accentuated characters in a partial

Hi everyone,
I'm not sure if its the right place to post this issue, and I'm far from mastering Grunt or Karma, but I think you might be interested by a weird bug I stumbled upon.

Basically, when running e2e tests on an Angular app with Karma via Grunt (still there ?), the task stops abruptly with the message:
Fatal error: Parse Error

After a long and painfull investigation, I managed to find the guilty line : an accentuated character in a partial.
A pushed a simple setup and the steps that allow to reproduce the bug : https://github.com/abanctelchevrel/karma-e2e-bug

I must admit that I reached the limit of my understanding of Grunt and Karma on this one, maybe you guys can tell me if you manage to reproduce it ? If so do you have any idea of how to fix it ?

Background option error

I'am getting following error when running grunt karma:unit watch -v --stack:

running tasks: karma:unit, watch

Running "karma:unit" (karma) task
Verifying property karma.unit exists in config...OK
File: [no files]

Running "watch" task
Verifying property watch exists in config...OK
Verifying properties watch.coffee.files, watch.coffee.tasks exist in config...OK
Verifying properties watch.css.files, watch.css.tasks exist in config...OK
Verifying properties watch.grunt.files, watch.grunt.tasks exist in config...OK
Verifying properties watch.docs.files, watch.docs.tasks exist in config...OK
Waiting...Fatal error: undefined is not a function
TypeError: undefined is not a function
    at util.spawn.callDone (/Users/martinhalamicek/Development/projects/angular-kb/node_modules/grunt/lib/grunt/util.js:147:5)
    at ChildProcess.util.spawn (/Users/martinhalamicek/Development/projects/angular-kb/node_modules/grunt/lib/grunt/util.js:186:5)
    at ChildProcess.EventEmitter.emit (events.js:99:17)
    at maybeClose (child_process.js:638:16)
    at Socket.ChildProcess.spawn.stdin (child_process.js:815:11)
    at Socket.EventEmitter.emit (events.js:96:17)
    at Socket._destroy.destroyed (net.js:358:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

grunt-karma configuration:

    karma:
            unit:
                configFile: "karma.conf.js"
                background: true

            ci:
                configFile: "karma.conf.js"
                singleRun: true
                browsers: ["PhantomJS"]
          watch:
            coffee:
                files: ["src/**/*.coffee"]
                tasks: ["coffee", "concat:dist_scripts", "uglify", "karma:unit:run"]

There is missing callback done callback for grunt.util.spawn call, if i fix it there is a problem with path to lib/background.js.

I prefer solution from #6 , it works ok for me (except double tests execution).

Mac OSX 10.8.2, node v0.8.16

Coverage does not seem to work when running grunt-karma with background

I am trying to setup a grunt-based project to use karma with code coverage enabled. For some reason this doesn't seem to be working.

I have setup a sample project that shows the issue: https://github.com/abierbaum/test_karma/tree/dev/add_grunt

If I run:

./node_modules/grunt build

Then it will run in singleRun mode and the following output as expected.

~/Source/test_karma (dev/add_grunt *% u=)$ ./node_modules/.bin/grunt build
Running "clean:dist" (clean) task

Running "copy:dist" (copy) task
Copied 3 files

Running "jshint:files" (jshint) task
>> 5 files lint free.

Running "karma:build" (karma) task
[2013-06-25 16:25:24.812] [DEBUG] config - autoWatch set to false, because of singleRun
INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 28.0 (Linux)]: Connected on socket id wy4fHhIWpvTmRdOnOhDY
Chrome 28.0 (Linux) LOG: 'play file: '
Chrome 28.0 (Linux) LOG: { currentlyPlayingSong: {}, isPlaying: true }
Chrome 28.0 (Linux): Executed 5 of 5 SUCCESS (0.028 secs / 0.007 secs)

=============================== Coverage summary ===============================
Statements   : 93.33% ( 14/15 )
Branches     : 100% ( 2/2 )
Functions    : 85.71% ( 6/7 )
Lines        : 93.33% ( 14/15 )
================================================================================

Running "concat:dist" (concat) task
File "dist/karma_test.js" created.

Running "uglify:dist" (uglify) task
File "dist/karma_test.min.js" created.

Done, without errors.

If instead I try to run using a watch and background: true, I get the following output where karma works, but it doesn't run the coverage.

~/Source/test_karma (dev/add_grunt *% u=)$ ./node_modules/.bin/grunt dev
Running "clean:dist" (clean) task
Cleaning "dist/"...OK

Running "copy:dist" (copy) task
Copied 3 files

Running "jshint:files" (jshint) task
>> 5 files lint free.

Running "concat:dist" (concat) task
File "dist/karma_test.js" created.

Running "uglify:dist" (uglify) task
File "dist/karma_test.min.js" created.

Running "karma:unit" (karma) task

Running "watch" task
Waiting...OK
>> File "spec/PlayerSpec.js" changed.

Running "clean:dist" (clean) task
Cleaning "dist/"...OK

Running "copy:dist" (copy) task
Copied 3 files

Running "jshint:files" (jshint) task
>> 5 files lint free.

Running "concat:dist" (concat) task
File "dist/karma_test.js" created.

Running "uglify:dist" (uglify) task
File "dist/karma_test.min.js" created.

Running "karma:unit:run" (karma) task
Chrome 28.0 (Linux) LOG: 'play file:  '
Chrome 28.0 (Linux) LOG: { currentlyPlayingSong: {}, isPlaying: true }
Chrome 28.0 (Linux): Executed 5 of 5 SUCCESS (0.026 secs / 0.01 secs)

Done, without errors.
Completed in 0.774s at Tue Jun 25 2013 16:27:50 GMT-0500 (CDT) - Waiting...

Any idea how to fix this up?

I am running Ubuntu 12.10 with node v0.10.12. The package versions I am using are shown in the package file: https://github.com/abierbaum/test_karma/blob/dev/add_grunt/package.json

ANGULAR_SCENARIO and MOCHA in background and separated watch tasks

Repasting karma-runner/karma#608 in here

I have two test setups:

// in tests/client/e2e/karma.conf.js
basePath = '../../../';

logLevel = LOG_DEBUG;

files = [
  ANGULAR_SCENARIO,
  ANGULAR_SCENARIO_ADAPTER,
  'tests/client/e2e/**/*.coffee'
];

and

// in tests/client/js/karma.conf.js
basePath = '../../../';

logLevel = LOG_DEBUG;

files = [
  MOCHA,
  MOCHA_ADAPTER,
  'node_modules/chai/chai.js',
  'javascripts/modernizr.js',
  'javascripts/jquery.js',
  'javascripts/jquery-ui.js',
  'javascripts/jquery.ui.datepicker-pt-BR.js',
  'javascripts/angular.js',
  'javascripts/angular-locale_pt-br.js',
  'javascripts/jquery.maskedinput.js',
  'javascripts/select2/select2.js',
  'javascripts/select2/select2_locale_pt-BR.js',
  'javascripts/amplify.store.js',
  'javascripts/ui/mask/mask.js',
  'javascripts/ui/select2/select2.js',
  'javascripts/ui/date/date.js',
  'javascripts/plugins/jquery.magnific-popup.js',
  'javascripts/groundwork.all.js',
  'javascripts/components/forms.js',
  'javascripts/components/menus.js',
  'javascripts/components/modals.js',
  'javascripts/lodash.underscore.js',
  'javascripts/backbone.js',
  'javascripts/deep-model.js',
  'javascripts/backbone-query.js',
  'javascripts/app.js',
  'tests/client/js/**/*.coffee'
];

and my grunt file:

    karma  : {
      options: {
        background: true,
        reporters: 'dots',
        hostname: '127.0.0.1',
        browsers: ['Firefox']
      },
      e2e: {
        configFile: 'tests/client/e2e/karma.conf.js',
        port: 9876
      },
      js: {
        configFile: 'tests/client/js/karma.conf.js',
        port: 9877
      }
    },

When I run the tests, using grunt karma for example, both browsers start, but only the test from e2e appear to be running. how can I make it run each setup separatedly?

I'm on windows 7 64 bits, node 0.10.12, karma 0.8.6.

grunt watch is expecting to do a karma:e2e:run and karma:js:run on change, but the run is executing only one of them. two browsers open up (that is, 2 firefox instances), but both execute the same test, and not separated ones.

C:\Users\Webdev\Inetpub\project>grunt
Running "karma:js" (karma) task

Running "karma:e2e" (karma) task

Running "watch" task
Waiting...OK
>> File "tests\client\e2e\plans.coffee" changed.

Running "karma:js:run" (karma) task
Firefox 21.0 (Windows): Executed 20 of 20 SUCCESS (3.578 secs / 1.948 secs)

Running "karma:e2e:run" (karma) task
Firefox 21.0 (Windows): Executed 20 of 20 SUCCESS (4.175 secs / 2.676 secs)

my watch part of the grunt file

    watch  : {
      compass    : {
        files: "stylesheets/*.scss",
        tasks: ["compass:main"]
      },
      karma      : {
        files: ['tests/client/**/*.coffee','tests/client/**/*.js','javascripts/app.js'],
        tasks: ['karma:js:run','karma:e2e:run'] 
      },
      coffeefront: {
        files: ["javascripts/app/front/**/*.coffee", "<%= src.coffee %>"],
        tasks: ["coffee:front"]
      },
      coffeeback : {
        files: ["javascripts/app/back/**/*.coffee", "<%= src.coffee %>"],
        tasks: ["coffee:back"]
      }
    }

 /* ... */
 grunt.registerTask('default', ['karma:js','karma:e2e','watch']);

The first command that is called, either karma:js or karma:e2e "wins". If I call the following grunt command:

    karma: {
      jsonce: {
        background: false,
        singleRun: true,
        configFile: 'tests/client/js/karma.conf.js'
      },
      e2eonce: {
        background: false,
        singleRun: true,
        configFile: 'tests/client/e2e/karma.conf.js'
      }
    }

  /* ... */
  grunt.registerTask('test', ['coffee','karma:jsonce','karma:e2eonce']);

it works. only the background: true that doesn't (for continuous development)

PhantomJS not being run...

I'm getting the following error when watch runs the karma:unit:run task

There is no server listening on port 9100

my GruntFile looks like this:

karma: {
      unit: {
        configFile: 'karma.conf.js',
        autoWatch: false,
        background: true,
        browsers: ['PhantomJS']
      }
    },

my karma.conf.js file appears to be okay as running karma start works correctly.

I'm using phantomJS 1.9.1, node 0.10.15

thanks for any help!

Delay in starting 'karma:unit:run' in background mode

Hi there,

following the README, I'm using the following config in my Gruntfile in development

 karma: {
   options: {
      configFile: 'karma.conf.js'
    },

   unit: {
     background: true,
     browsers: ['Chrome']
   },
},
watch: {
  karma: {
    files: ['app/assets/**/*.js', 'spec/javascripts/**/*.js'],
    tasks: ['karma:unit:run'] 
  }
},

when I run grunt karma:unit watch I get quite a bit of delay in the karma:unit task to run after I change something in a watched file.

grunt watch hangs on karma:unit:run task

Hi,

I have this issue every time I update a js file, for example a Ctrl.
But runnig "grunt delta" and "karma start karma/karma-unit.js", in two different console, it's works well.

This the output after an hangs:

Running "clean:0" (clean) task
Cleaning "dist"...OK

Running "html2js:app" (html2js) task

Running "html2js:component" (html2js) task

Running "jshint:src" (jshint) task
>> 16 files lint free.

Running "jshint:test" (jshint) task
>> 4 files lint free.

Running "jshint:gruntfile" (jshint) task
>> 1 file lint free.

Running "jshint:globals" (jshint) task
>> 0 files lint free.

Running "karma:continuous" (karma) task
INFO [karma]: Karma server started at http://localhost:9018/
INFO [launcher]: Starting browser Firefox
INFO [Firefox 20.0 (Linux)]: Connected on socket id Znh0ouyJ14JFR2s9d17s
......
Firefox 20.0 (Linux): Executed 6 of 6 SUCCESS (0.434 secs / 0.039 secs)

Running "concat:dist" (concat) task
File "dist/assets/clean-power-circle.js" created.

Running "concat:libs" (concat) task
File "dist/assets/libs.js" created.

Running "ngmin:dist" (ngmin) task
ngminifying dist/assets/clean-power-circle.js

Running "uglify:dist" (uglify) task
File "dist/assets/clean-power-circle.min.js" created.

Running "recess:build" (recess) task
File "dist/assets/clean-power-circle.css" created.
Uncompressed size: 150906 bytes.
Compressed size: 17191 bytes gzipped (125053 bytes minified).

Running "index" task

Running "copy:assets" (copy) task
Created 3 directories, copied 8 files

Running "copy:bin" (copy) task
Created 1 directories, copied 1 files

Running "karma:unit" (karma) task

Running "delta" task
Waiting...OK
>> File "src/app/membership/membership.js" changed.
Running "jshint:src" (jshint) task
>> 16 files lint free.

Running "karma:unit:run" (karma) task

karma runs very slow

I've set up grunt-contrib-watch to run karma unit test when a JavaScript file changes with grunt-karma.
It works, but is very slow. This is the following output:

Running "karma:unit:run" (karma) task
[2013-09-27 12:39:26.047] [DEBUG] config - Loading config (path to file)
ERROR: 'There is no timestamp for base/functions/compute.js!'
ERROR: 'There is no timestamp for base/compose/compose.js!'
ERROR: 'There is no timestamp for base/functions/add.js!'
Chrome 29.0.1547 (Windows 7): Executed 2 of 2 SUCCESS (7.647 secs / 1.966 secs)

(I removed the filepath, it was very long)

It runs 2 unit tests in 7.6 seconds.
I've set up karma to work with requirejs.

Is this normal?

node 0.10 and karma 0.9

Looks like the package json is specifying karma ~0.8.0, but the lastest is 0.9.0 and it's making the build to fail

> [email protected] install C:\Users\Webdev\Inetpub\socketexpress\node_modules\grunt-karma\node_modules\karma
> node install-log4js.js


events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:948:11)
    at Process.ChildProcess._handle.onexit (child_process.js:739:34)
npm ERR! [email protected] install: `node install-log4js.js`
npm ERR! `cmd "/c" "node install-log4js.js"` failed with 8
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the karma package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node install-log4js.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls karma
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--msvs_version=vs2012"
npm ERR! cwd C:\Users\Webdev\Inetpub\socketexpress
npm ERR! node -v v0.10.2
npm ERR! npm -v 1.2.15
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Users\Webdev\Inetpub\socketexpress\npm-debug.log
npm ERR! not ok code 0

grunt-karma and jasmine

Hi,

I try to use jasmine with karma but when I run grunt karma I obtained the following error : Can't find variable: describe

I think that a module is missing for jasmine but there is a lot module on npm repo related to jasmine.
I'm a newbie with grunt, karma and jasmine. I can't find a solution in the doc or google, please help me.

Thanks

don't let grunt exit when using :run

certain exceptions can cause grunt to bail and stop the watch task, which isn't ideal. For example:

expect('foo'.to.be.a('string'); //missing parenthesis

would do it.

Change the :run case to fail the tests but not to crash grunt.

Multitask port re-use

I have several different test suites being run, however it doesn't seem like the karma server is shut down after each task target completes, so the port I've specified isn't available for the next target that runs. It automatically increments, but in my case that port is being blocked. Seems like after a task target completes, any resources that it used should be cleaned up so that it's available for other targets.

Merge with grunt-testacular?

It would be cool if this project was merged with grunt-testacular. grunt-testacular is nice because it runs a testacular server without blocking grunt so you can run grunt watch without opening another terminal.

Karma is blocking another tasks

Related to #2

There is such configuration inside our Gruntfile.js:

module.exports = function(grunt) {
    grunt.initConfig({
        copy: {
            // ...
        },

        sass: {
            // ...
        },

        regarde: {
            js: {
                files: ['app/**/*.js', 'tests/**/*.js'],
                tasks: ['copy', 'livereload']
            },
            css: {
                // ...
            },
            scss: {
                files: [
                    'app/assets/scss/*.scss'
                ],
                tasks: ['sass', 'livereload']
            },
            html: {
                files: [
                    'app/**/*.html'
                ],
                tasks: ['copy', 'livereload']
            }
        },

        testacular: {
            unit: {
                options: {
                    configFile: 'testacular_conf.js'
                }
            }
        }

    });

    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-regarde');
    grunt.loadNpmTasks('grunt-testacular');
    grunt.loadNpmTasks('grunt-contrib-livereload');

    // Setup tasks.
    // Watch should be last
    grunt.registerTask('run', [
        'copy',
        'livereload-start',
        'testacular',
        'regarde'

    ]);
    grunt.registerTask('default', ['run']);
};

And it's working well with testacular.
So when I'm starting grunt, it watches files and runs all necessary tasks on file changes.
But when we replace testacular with karma and grunt-testacular with grunt-karma karma is blocking another tasks so only karma task is working on file changes and other tasks are not going to execute.

Error while installing karma

Hi. I wanted to install karma on my computer, because we need it for a project in school, but then I ran in some trouble.
I already have Node.js installed on my compputer and I used npm install -g karma (I'm running on Windows 7) command to install karma. This is the error I got:

[email protected] install C:\Users\Koshy\AppData\Roaming\npm\node_modules\karma\node_m
odules\socket.io\node_modules\socket.io-client\node_modules\ws
(node-gyp rebuild 2> builderror.log) || (exit 0)

Navedene poti ni mogoฤe najti.

C:\Users\Koshy\AppData\Roaming\npm\node_modules\karma\node_modules\socket.io\nod
e_modules\socket.io-client\node_modules\ws>node "C:\Program Files\nodejs\node_mo
dules\npm\bin\node-gyp-bin....\node_modules\node-gyp\bin\node-gyp.js" rebuild

C:\Users\Koshy\AppData\Roaming\npm\karma -> C:\Users\Koshy\AppData\Roaming\npm\n
ode_modules\karma\bin\karma

[email protected] install C:\Users\Koshy\AppData\Roaming\npm\node_modules\karma
node install-log4js.js

Navedene poti ni mogoฤe najti.
Navedene poti ni mogo?e najti.
npm http GET https://registry.npmjs.org/log4js/0.6.2
npm http 304 https://registry.npmjs.org/log4js/0.6.2
npm http GET https://registry.npmjs.org/async/0.1.15
npm http GET https://registry.npmjs.org/dequeue/1.0.3
npm http 304 https://registry.npmjs.org/dequeue/1.0.3
npm http 304 https://registry.npmjs.org/async/0.1.15
[email protected] C:\Users\Koshy\AppData\Roaming\npm\node_modules\log4js
+ยฆยฆ [email protected]
Lยฆยฆ [email protected]
npm ERR! [email protected] install: node install-log4js.js
npm ERR! cmd "/c" "node install-log4js.js" failed with 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the karma package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install-log4js.js
npm ERR! You can get their info via:
npm ERR! npm owner ls karma
npm ERR! There is likely additional logging output above.

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nod
ejs\node_modules\npm\bin\npm-cli.js" "install" "-g" "karma"
npm ERR! cwd C:\Users\Koshy
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\Koshy\npm-debug.log
npm ERR! not ok code 0

Error: spawn ENOENT` when installing via npm (Windows 7)

Im getting error while installing karma

C:\Users\username>npm install -g karma
npm http GET https://registry.npmjs.org/karma
npm http 304 https://registry.npmjs.org/karma
npm http GET https://registry.npmjs.org/di
npm http GET https://registry.npmjs.org/socket.io
npm http GET https://registry.npmjs.org/chokidar
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/http-proxy
npm http GET https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/q
npm http GET https://registry.npmjs.org/colors/0.6.0-1
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/log4js
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/useragent
npm http 304 https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/chokidar
npm http 304 https://registry.npmjs.org/di
npm http 304 https://registry.npmjs.org/http-proxy
npm http 304 https://registry.npmjs.org/optimist
npm http 304 https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/glob
npm http 304 https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/rimraf
npm http 304 https://registry.npmjs.org/q
npm http 304 https://registry.npmjs.org/colors/0.6.0-1
npm http 304 https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/graceful-fs
npm http 304 https://registry.npmjs.org/log4js
npm http 304 https://registry.npmjs.org/connect
npm http 304 https://registry.npmjs.org/useragent
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/socket.io-client/0.9.16
npm http GET https://registry.npmjs.org/policyfile/0.0.4
npm http GET https://registry.npmjs.org/base64id/0.1.0
npm http GET https://registry.npmjs.org/redis/0.7.3
npm http GET https://registry.npmjs.org/async/0.1.15
npm http GET https://registry.npmjs.org/semver
npm http GET https://registry.npmjs.org/readable-stream
npm http GET https://registry.npmjs.org/pkginfo
npm http GET https://registry.npmjs.org/formidable/1.0.14
npm http GET https://registry.npmjs.org/send/0.1.4
npm http GET https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/cookie-signature/1.0.1
npm http GET https://registry.npmjs.org/cookie/0.1.0
npm http GET https://registry.npmjs.org/qs/0.6.5
npm http GET https://registry.npmjs.org/bytes/0.2.0
npm http GET https://registry.npmjs.org/fresh/0.2.0
npm http GET https://registry.npmjs.org/uid2/0.0.2
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http GET https://registry.npmjs.org/utile
npm http GET https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/wordwrap
npm http 304 https://registry.npmjs.org/policyfile/0.0.4
npm http 304 https://registry.npmjs.org/base64id/0.1.0
npm http 304 https://registry.npmjs.org/redis/0.7.3
npm http 304 https://registry.npmjs.org/async/0.1.15
npm http 304 https://registry.npmjs.org/semver
npm http 304 https://registry.npmjs.org/readable-stream
npm http 304 https://registry.npmjs.org/socket.io-client/0.9.16
npm http 304 https://registry.npmjs.org/pkginfo
npm http 304 https://registry.npmjs.org/formidable/1.0.14
npm http 304 https://registry.npmjs.org/send/0.1.4
npm http 304 https://registry.npmjs.org/buffer-crc32/0.2.1
npm http 304 https://registry.npmjs.org/cookie-signature/1.0.1
npm http 304 https://registry.npmjs.org/cookie/0.1.0
npm http 304 https://registry.npmjs.org/qs/0.6.5
npm http 304 https://registry.npmjs.org/bytes/0.2.0
npm http 304 https://registry.npmjs.org/fresh/0.2.0
npm http 304 https://registry.npmjs.org/uid2/0.0.2
npm http 304 https://registry.npmjs.org/pause/0.0.1
npm http 304 https://registry.npmjs.org/utile
npm http 304 https://registry.npmjs.org/methods/0.0.1
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/deep-equal
npm http GET https://registry.npmjs.org/mkdirp
npm http GET https://registry.npmjs.org/i
npm http GET https://registry.npmjs.org/ncp
npm http GET https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/mkdirp
npm http 304 https://registry.npmjs.org/i
npm http 304 https://registry.npmjs.org/deep-equal
npm http 304 https://registry.npmjs.org/ncp
npm http GET https://registry.npmjs.org/uglify-js/1.2.5
npm http GET https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http GET https://registry.npmjs.org/ws
npm http GET https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/ws
npm http 304 https://registry.npmjs.org/xmlhttprequest/1.4.2
npm http 304 https://registry.npmjs.org/active-x-obfuscator/0.0.1
npm http 304 https://registry.npmjs.org/uglify-js/1.2.5
npm http GET https://registry.npmjs.org/zeparser/0.0.5
npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/tinycolor
npm http GET https://registry.npmjs.org/options
npm http GET https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/zeparser/0.0.5
npm http 304 https://registry.npmjs.org/commander
npm http 304 https://registry.npmjs.org/tinycolor
npm http 304 https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/options

[email protected] install C:\Users\username\AppData\Roaming\npm\node_modules\karma\node
_modules\socket.io\node_modules\socket.io-client\node_modules\ws
(node-gyp rebuild 2> builderror.log) || (exit 0)

npm ERR! Error: spawn ENOENT
npm ERR! at errnoException (child_process.js:980:11)
npm ERR! at Process.ChildProcess._handle.onexit (child_process.js:771:34)
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nod
ejs\node_modules\npm\bin\npm-cli.js" "install" "-g" "karma"
npm ERR! cwd C:\Users\username
npm ERR! node -v v0.10.21
npm ERR! npm -v 1.3.11
npm ERR! syscall spawn
npm ERR! code ENOENT
npm ERR! errno ENOENT
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\Username\npm-debug.log
npm ERR! not ok code 0

update description

@vojtajina please change this repo's description from "Grunt plugin for testacular" to "Grunt plugin for Karma" or whatever. Thx.

Karma tasks not being loaded on Travis

My tests run just fine locally, but on travis I get this error:

Registering "grunt-karma" local Npm module tasks.
Reading /Users/travis/build/openxo/client/node_modules/grunt-karma/package.json...OK
Parsing /Users/travis/build/openxo/client/node_modules/grunt-karma/package.json...OK
Loading "grunt-karma.js" tasks...ERROR
>> Error: Cannot find module '../bin/builder'
>>     at Function.Module._resolveFilename (module.js:338:15)
>>     at Function.Module._load (module.js:280:25)
>>     at Module.require (module.js:364:17)
>>     at require (module.js:380:17)
>>     at object.module.io (/Users/travis/build/openxo/client/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/lib/io.js:156:18)
>>     at Object.<anonymous> (/Users/travis/build/openxo/client/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/lib/io.js:206:3)
>>     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)

colors

How set --no-colors or log-level options into grunt-karma ?

Thank
Ami44

Causes grunt-contrib-watch to stop

After setting up grunt-karma per the readme, when I use it with grunt-contrib-watch, the karma:*:run task stops the watch task after finishing all remaining tasks on that watch command. E.g.:

  // ...
  karma: {
    options: {
      configFile: 'karma/karma-unit.js'
    },
    unit: {
      background: true
    },
    continuous: {
      singleRun: true
    }
  },
  // ...
  watch: {
    // ...
    src: {
      files: [ 
        '<%= src.js %>'
      ],
      tasks: [ 'jshint:src', 'karma:unit:run', 'concat:dist', 'uglify:dist' ]
    },
    // ...
  },
  // ...

Here's the config file:

basePath = '../';
files = [
  JASMINE,
  JASMINE_ADAPTER,
  'vendor/angular/angular.js',
  'vendor/angular/angular-mocks.js',
  'src/**/*.js',
  'dist/tmp/**/*.js'
];
reporters = 'dots';
port = 9018;
runnerPort = 9100;
urlRoot = '/';
logLevel = LOG_INFO;
autoWatch = false;
browsers = [
// 'Firefox'
];

When the src watch is triggered, all tasks listed run and their output is seen in the terminal, but then grunt watch command just ends without any message. All tasks succeed. Removing the karma:unit:run task makes grunt stay running. Running with --debug --verbose gives only the expected output. Running with nospawn: true yields the same result.

Relevant version:

  • node v0.10.3
  • grunt-cli v0.1.7
  • grunt v0.4.1
  • grunt-contrib-watch 0.3.1
  • grunt-karma 0.4.4
  • karma 0.8.5

Update: Forgot to mention I'm running Arch Linux.

Fire errors with grunt logger

I believe the grunt-notify task monitors Grunt for errors logged via grunt.log. However, this task does not appear to filter errors through to the Grunt logger, so it is therefore incompatible with grunt-notify.

It would be incredibly useful if support was implemented.

IE not exiting in Jenkins

I'm trying to setup a CI build with Jenkins. The build will execute grunt tool chain which includes grunt-karma for unit tests. It works fine with Chrome, Firefox and Safari but unfortunately not for IE. IE will just not exit and cause the whole build to stall. I've tried to run the grunt chain via command prompt on the same system and it works perfectly. May someone points out whether i missed something during the setup?

System
Windows 7 x64 SP1
Internet Explorer 8.0 (Tried IE 9 also)

grunt-karma 0.6.2
karma 0.10.2
karma-ie-launcher 0.1.1

IE_BIN (Tried both)
C:\Program Files (x86)\Internet Explorer\iexplore.exe
C:\Program Files\Internet Explorer\iexplore.exe

Here's the log of karma, i deleted some for clarity:

Running "karma:continuous" (karma) task
DEBUG [plugin]: Loading karma-* from C:\Jenkins\jobs\TestIE\workspace\node_modules
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-coffee-preprocessor.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-coverage.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-firefox-launcher.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-html2js-preprocessor.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-ie-launcher.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-junit-reporter.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-opera-launcher.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-requirejs.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-safari-launcher.
DEBUG [plugin]: Loading plugin C:\Jenkins\jobs\TestIE\workspace\node_modules/karma-script-launcher.
DEBUG [plugin]: Loading inlined plugin (defining ).
INFO [karma]: Karma v0.10.2 server started at http://localhost:9876/
INFO [launcher]: Starting browser IE
DEBUG [launcher]: Creating temp dir at C:\Windows\TEMP\karma-98974088
DEBUG [launcher]: C:\Program Files\Internet Explorer\iexplore.exe http://localhost:9876/?id=98974088
DEBUG [watcher]: Excluded file "C:/Jenkins/jobs/TestIE/workspace/scripts/services/adapters/config.js"
  // A bunch of files
DEBUG [preprocessor.html2js]: Processing "C:/Jenkins/jobs/TestIE/workspace/template/accordion/accordion-group.html".
  // A bunch of files
DEBUG [watcher]: Resolved files:
    // A bunch of files
DEBUG [web-server]: serving: C:\Jenkins\jobs\TestIE\workspace\node_modules\karma\static/client.html
DEBUG [web-server]: serving: C:\Jenkins\jobs\TestIE\workspace\node_modules\karma\static/karma.js
DEBUG [karma]: A browser has connected on socket gmXEnoE93meu_PVKS2fO
INFO [IE 9.0.0 (Windows 7)]: Connected on socket gmXEnoE93meu_PVKS2fO
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving: C:\Jenkins\jobs\TestIE\workspace\node_modules\karma\static/context.html

karma.conf.js

// Karma configuration
// Generated on Wed Aug 28 2013 17:01:18 GMT+0800 (Malay Peninsula Standard Time)

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

    // base path, that will be used to resolve files and exclude
    basePath: '',


    // frameworks to use
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
      'scripts/vendor/jquery-1.10.2.min.js', // The order here is important
      'scripts/vendor/angular.js',
      'tests/lib/angular-mocks.js',
      'scripts/vendor/angular-ui-router.min.js',
      'scripts/*.js',
      'scripts/**/*.js',
      'template/**/*.html',
      //'tests/lib/angular-scenario.js',
      'tests/specs/**/*.js'
    ],


    // list of files to exclude
    exclude: [
      'scripts/services/adapters/*.js'
    ],


    // 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_DEBUG,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: [/*'Chrome', 'Firefox', 'Safari', 'PhantomJS', 'Opera',*/ 'IE'],


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

Gruntfile.js

// More stuffs -----
    karma: {
      options: {
        configFile: 'karma.conf.js'
      },
      dev: {
        browsers: ['PhantomJS'],
        reporters: [
          'progress',
          'coverage'
        ],
        coverageReporter: {
          type: 'html',
          dir: reportRoot + '/coverage/'
        },
        color: true,
        background: true
      },
      continuous: {
        singleRun: true,
        browsers: [
          'IE', // Freeze Jenkins
          //'Chrome',
          //'Firefox',
          //'Safari',
          //'Opera', //Cannot be launched...
          //'PhantomJS'
        ],
        reporters: [
          'dots',
          'junit',
          'coverage'
        ],
        junitReporter: {
          outputFile: reportRoot + '/test_results.xml'
        },
        coverageReporter: {
          type: 'cobertura',
          dir: reportRoot + '/coverage/',
          file: 'coverage.xml'
        },
        color: false
      }
    },
// More stuffs -----

Thanks!

version missmatch

we are running 0.6.2 of grunt-karma. today there was a release of 0.10.3 of Karma that breaks are builds. According to your docs the 6.x should match the karma version of 10.x. Since 6.2 is always getting the latest version of karma we don't have a graceful way of rolling back karma. If the even number is the stable build, but you are pulling the odd number unstable build this is an issue.

npm ERR! peerinvalid Peer [email protected] wants karma@~0.10.0

I try to use grunt-karma@~0.7.0 next to karma@~0.11.0 but npm finds that it does not satisfy peer dependencies:

npm ERR! peerinvalid Peer [email protected] wants karma@~0.10.0

This is not what the Readme says:

..while [email protected] goes with [email protected]

My guess is that:

  1. [email protected] was effectively published to npm with karma@~0.10.0 as peer dependency
  2. the karma peer dependency was bumped later
  3. but no npm publish was done to propagate this change.

To correct that, either do a force publish to npm for [email protected] โ€“ but force publish is never/never a good idea โ€“ either bump grunt-karma to an upper version (0.7.2 or 0.8.0?), update the readme and publish it.

No server on port 9100

Hi! I'm getting this error while trying to run karma with grunt-karma:

Running tasks: karma:unit:run

Running "karma:unit:run" (karma) task
Verifying property karma.unit exists in config...OK
File: [no files]
There is no server listening on port 9100

Seems like grunt-karma doesn't start server. While default command does:

karma start karma.conf.coffee 

Here is part of grunt config:

    karma:
      options:
        configFile: 'karma.conf.coffee'
        background: true
      unit: {}
      unit_all:
        browsers: ['PhantomJS', 'Chrome', 'Firefox']

I'm 0.9.5

Karma autoWatch blocks grunt watch

The main problem now that if i run Karma not in singleRun it blocks grunt watch.
But if i run in singleRun it starts and stops browsers after each file change.

In 0.6.x versions Testacular / grunt-testacular plugin allows run watch mode for grunt and watch for Testacular so browsers are not stopping.

Thanks!

grunt-contrib-watch doesn't detect file changes for 30 seconds after start when use grunt-karma

When I start grunt-karma via grunt watch it takes 30 seconds before grunt will start detecting any file changes.

If I use karma's built-in watch system: grunt karma:watch, then files changes are detected right after launch without any delay.

Such delay on start of grunt-contrib-watch doesn't happen with other grunt plugins: grunt-contrib-less, grunt-contrib-concat, grunt-typescript, only happens with grunt-karma.

My OS is Windows 8.

Here's my gruntfile:

module.exports = function(grunt) {    
    grunt.loadNpmTasks('grunt-karma');    
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.initConfig({
        karma: {
            watch: {
                configFile: '../../src/Tests/Config/karma.conf.js',
                singleRun: false,
                autoWatch: true,
            },
            once: {
                configFile: '../../src/Tests/Config/karma.conf.js',
                singleRun: true,
                autoWatch: false,
            },
            teamcity: {
                configFile: '../../src/Tests/Config/karma.conf.js',
                singleRun: true,
                reporters: 'teamcity'
            }
        },
        watch: {
            unitTests: {
                files: ['../../src/**/*.js'],
                tasks: ['karma:once']
            }
        }
    });

    grunt.registerTask('default', ['karma:once']);
}

grunt + karma + jasmine issue ?

Hi,

I have exactly the same problem as #32 . This was apparently caused by version issues, however I'm using newer versions of all tools :

  • "grunt-karma": "~0.6.2",
  • "karma": "~0.10.9",

karma runs perfecly when I launch it manually, but doesn't include jasmine when is goes through grunt.

I guess I miss something and I spend hours already looking for it :( The closest I found was the #32 ... Ideas, anyone ?

Thanks in advance !

grunt-karma not running with grunt-regarde

Hi,

I am trying to set up grunt-karma with grunt-regarde. I have the following configuration.

Gruntfile.js

    watch: {
      test: {
        files: [
          '<%= yeoman.app %>/**/*.js',
          '<%= yeoman.test %>/unit/**/*.js',
          '<%= yeoman.test %>/support/**/*.js'
        ],
        tasks: ['karma:unitd:run']
      }

    karma: {
      unitd: {
        configFile: 'test/config/testacular.conf.js',
        background: true
      }

I tried the following steps

  1. karma start test/config/testacular.conf.js (assuming this is what is meant by server should be running https://github.com/karma-runner/grunt-karma#karma-server-with-grunt-watchregarde
  2. grunt karma:unitd watch:test

I get the following output from the second command - watch:test doesn't start until karma:unitd is killed. Even when karma:unitd starts on interrupting the shell, it gets killed the first time a test fails.

Running "karma:unitd" (karma) task
WARN [karma]: Port 9876 in use
WARN [karma]: Port 9100 in use
INFO [karma]: Karma server started at http://localhost:9877/
INFO [launcher]: Starting browser Chrome
INFO [karma]: To run via this server, use "karma run --runner-port 9101"
INFO [Chrome 27.0 (Mac)]: Connected on socket id w3DRWc21RMtGlEjDEwkX
^C
Running "watch:test" (watch) task
Watching app/**/*.js,test/unit/**/*.js,test/support/**/*.js

Running "karma:unitd:run" (karma) task
Chrome 27.0 (Mac) bmi calculateBmi should calculate bmi as weight by height square FAILED
    Expected 19.53 to be 9.53.
    Error: Expected 19.53 to be 9.53.
        at null.<anonymous> (/Users/pulkitb/work/code/jss/registration/test/unit/medical-concepts/bmi.spec.js:10:31)
        at Object.invoke (/Users/pulkitb/work/code/jss/registration/app/components/angular/angular.js:2850:28)
        at workFn (/Users/pulkitb/work/code/jss/registration/app/components/angular-mocks/angular-mocks.js:1754:20)
................................................................................
...........
Chrome 27.0 (Mac): Executed 92 of 92 (1 FAILED) (0.742 secs / 0.338 secs)
Warning: Task "karma:unitd:run" failed. Use --force to continue.

Aborted due to warnings.

In case I try it without starting the karma server via karma start, I get the following

pulkitb-15:49:20: registration$ grunt watch:test

Running "watch:test" (watch) task
Watching app/**/*.js,test/unit/**/*.js,test/support/**/*.js

Running "karma:unitd:run" (karma) task
There is no server listening on port 9100
Warning: Task "karma:unitd:run" failed. Use --force to continue.

Aborted due to warnings.

Also, I wanted to understand that if I need to run karma start anyway I can start it with autowatch = true. I wanted to be able to grunt watch:test and have karma run in the background.

Thanks

Gruntfile docs appear to be wrong

Not sure if it's just me, but any options specific to a task like karma:unit or karma:continuous have to be specified within an "options" property inside the task property, and not at the root level of the task itself. e.g.:

This does nothing:

karma: {
  unit: {
    configFile: 'config/karma.conf.js',
    background: true
  }
},  

But this works:

karma: {
  unit: {
    options: {
        configFile: 'config/karma.conf.js',
        background: true
    }
  }
},  

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.