craigburke / karma-gradle

Gradle Plugin for Running tests with Karma
Other
21 stars 11 forks source link

:version: 1.4.4

= Karma Gradle Plugin

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

== Getting Started

[source,gradle,subs='attributes']

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

== Tasks

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

|===

== Configuration

=== Properties

You can use the same properties you'd set in your http://karma-runner.github.io/0.13/config/configuration-file.html[karma.config.js file] directly in build.gradle

[source,gradle,subs='attributes']

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

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` NOTE: if *basePath* is not set, it defaults the project root. === Profiles 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. [source,gradle,subs='attributes'] ---- plugins { id 'com.craigburke.karma' version '{version}' } 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. [source,gradle,subs='attributes'] ---- 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. NOTE: you can always build your own files list by setting the `files` property directly (see Advanced Configuration). === Dependencies 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. [source,gradle,subs='attributes'] ---- karma { dependencies(['karma-sinon']) } ---- You can also lock any dependency to a specific version by adding it this way with @ version syntax: [source,gradle,subs='attributes'] ---- karma { dependencies(['phantomjs@1.9.7-14']) } ---- === Advanced Configuration In addition to the properties listed above, you can also include set other Karma properties through the DSL. [source,gradle,subs='attributes'] ---- karma { files = [ 'bower/angular/angular.js', '**/!(*.spec).js', '**/*.spec.js' ] exclude = ['jquery.js'] junitReporter = [outputDir: 'test-dir' ] } ----