This Gradle plugin allows you to run Jasmine, Qunit, or Mocha tests using the Karma test runner.
The plugin adds the following tasks to your build:
Task |
Description |
karmaRun |
Runs your tests |
karmaWatch |
Runs your tests in watch mode |
karmaRefresh |
Refresh the generated karma config file |
karmaClean |
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>
}
-
Optional base path for resolving relative paths
-
Whether to show colors on the screen (default is true)
-
File pattern profile to use. Possible values:
default, angularJS
-
Runs tests in the browsers listed here and installs the launcher dependencies. Possible values:
PhantomJS, Firefox, Chrome, ChromeCanary, Opera, Internet Explorer, Safari
-
Uses the listed frameworks and installs their dependencies. Possible values:
jasmine, mocha, qunit
. -
Uses additional reporters and installs their dependencies. Possible values:
progress, junit, coverage, growl, teamcity
Note
|
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>
}
-
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>
}
}
-
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 -
Overriding both the base path and list of source files. This will add
src/source1.js
,app/source1.js
,src/**/*.js
andapp/**/*.js
to the files list after the library files. -
Overriding both the base path and list of test files. This will add
/tests/**/*test.js
to the files list after the source files.
Note
|
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 {
dependencies(['karma-sinon'])
}
You can also lock any dependency to a specific version by adding it this way with @ version syntax:
karma {
dependencies(['[email protected]'])
}