Gradle Plugin for Running tests with Karma
Switch branches/tags
Nothing to show
Clone or download
craigburke Merge pull request #26 from iainduncani/patch-1
Set clean task name to karmaClean
Latest commit 9ad6945 Dec 15, 2016


Karma Gradle Plugin

This Gradle plugin allows you to run Jasmine, Qunit, or Mocha tests using the Karma test runner.

Getting Started

plugins {
    id 'com.craigburke.karma' version '1.4.4'


The plugin adds the following tasks to your build:




Runs your tests


Runs your tests in watch mode


Refresh the generated karma config file


Deletes the karma config file and removes the dependencies



You can use the same properties you’d set in your karma.config.js file directly in build.gradle

plugins {
    id 'com.craigburke.karma' version '1.4.4'

karma {
    basePath = 'src/assets' // <1>
    colors = true // <2>
    profile 'angularJS' // <3>

    browsers = ['PhantomJS'] // <4>
    frameworks = ['jasmine'] // <5>
    reporters = ['junit'] // <6>
  1. Optional base path for resolving relative paths

  2. Whether to show colors on the screen (default is true)

  3. File pattern profile to use. Possible values: default, angularJS

  4. Runs tests in the browsers listed here and installs the launcher dependencies. Possible values: PhantomJS, Firefox, Chrome, ChromeCanary, Opera, Internet Explorer, Safari

  5. Uses the listed frameworks and installs their dependencies. Possible values: jasmine, mocha, qunit.

  6. Uses additional reporters and installs their dependencies. Possible values: progress, junit, coverage, growl, teamcity

if basePath is not set, it defaults the project root.


Profiles allow you to use commonly used file patterns and sensible defaults for the files list. Currently there is a default and an angularJS profile.

plugins {
    id 'com.craigburke.karma' version '1.4.4'

karma {
    profile 'angularJS'  // <1>
  1. Applying the angularJS profile

For any profile, the files to be loaded are broken into three groups (libraries, source and tests). You can override the base path and file pattern list for any of these groups within a profile. This can be useful if the order that the files are loaded in matters.

karma {
    profile('default')  {
        libraryBases = ['**/libs/']
        libraryFiles = ['jquery.js', 'lib1.js'] // <1>

        sourceBases = ['src/', 'app/']
        sourceFiles = ['source1.js', '**/*.js'] // <2>

        testBases = ['tests/']
        testFiles = ['**/*test.js'] // <3>
  1. Overriding both the base path and list of library files. This will add /libs/**/jquery.js and /libs/**/lib1.js to the start of the karma files list

  2. Overriding both the base path and list of source files. This will add src/source1.js, app/source1.js, src/**/*.js and app/**/*.js to the files list after the library files.

  3. Overriding both the base path and list of test files. This will add /tests/**/*test.js to the files list after the source files.

you can always build your own files list by setting the files property directly (see Advanced Configuration).


By default the plugin will automatically install all needed browser, framework and reporter dependencies. If you need to add an additional npm dependency you can set it using the dependencies method.

karma {

You can also lock any dependency to a specific version by adding it this way with @ version syntax:

karma {

Advanced Configuration

In addition to the properties listed above, you can also include set other Karma properties through the DSL.

karma {
    files = [

    exclude = ['jquery.js']
    junitReporter = [outputDir: 'test-dir' ]