Continuous integration setup for Apache Cordova
Apache 2.0 License!
./config.json
file.(sudo) npm install
to get the dependencies sorted.node build.js
to run builds of the cordova test suite (mobile-spec), listening to latest commits for all supported cordova platforms. Lots of customization available. For custimzation, see usage section below.node dashboard.js
to run the dashboard server summarizing test resultsOnly tested on Mac OS 10.7.5.
There are three components in this system: a build process, a web server acting as dashboard, and a couchdb.
mobilespec_results
and build_errors
bind_address = 0.0.0.0
{ "_id": "_design/results", "views": { "android": { "map": "function(doc){if (doc.platform == 'android' && doc.mobilespec) {emit(doc.sha, {\"total\":doc.mobilespec.total,\"passed\":(doc.mobilespec.total - doc.mobilespec.failed),\"version\":doc.version,\"model\":doc.model,\"fails\":doc.mobilespec.failures});}}" }, "blackberry": { "map": "function(doc){if (doc.platform == 'blackberry' && doc.mobilespec) {emit(doc.sha, {\"total\":doc.mobilespec.total,\"passed\":(doc.mobilespec.total - doc.mobilespec.failed),\"version\":doc.version,\"model\":doc.model,\"fails\":doc.mobilespec.failures});}}" }, "ios": { "map": "function(doc){if (doc.platform == 'ios' && doc.mobilespec) {emit(doc.sha, {\"total\":doc.mobilespec.total,\"passed\":(doc.mobilespec.total - doc.mobilespec.failed),\"version\":doc.version,\"model\":doc.model,\"fails\":doc.mobilespec.failures});}}" } } }
{ "_id": "_design/errors", "views": { "android": { "map": "function(doc){if (doc.platform == 'android' && doc.failure) {emit(doc.sha, {\"timestamp\":doc.timestamp,\"failure\":doc.failure,\"details\":doc.details,\"version\":doc.version,\"model\":doc.model});}}" }, "blackberry": { "map": "function(doc){if (doc.platform == 'blackberry' && doc.failure) {emit(doc.sha, {\"timestamp\":doc.timestamp,\"failure\":doc.failure,\"details\":doc.details,\"version\":doc.version,\"model\":doc.model});}}" }, "ios": { "map": "function(doc){if (doc.platform == 'ios' && doc.failure) {emit(doc.sha, {\"timestamp\":doc.timestamp,\"failure\":doc.failure,\"details\":doc.details,\"version\":doc.version,\"model\":doc.model});}}" } } }
Run node build.js
without parameters to listen to new commits coming into the Apache Cordova project and build tests for these new commits. You can customize various parameters by either providing them as parameters to the CLI, or by filling out the corresponding sections in config.json
.
--app, -a <path>
: Relative path from root of this project to a static application you want to deploy to devices. config.json
parameter: app.static.path
. Defaults to null
as Cordova uses a dynamic application for testing.--entry, -e <path>
: The entry page for the test application, relative to app bundle root. Most applications use index.html
, but Cordova test suite has a page for all tests located at autotest/pages/all.html
. config.json
parameter: app.entry
.--builder, -b <path>
: Relative path from root of this project to a compatible module capable of building the test application. See below for more information, or src/build/makers/mobile_spec.js
for an example.--hook, -h <path>
: Relative path from root of this project to a compatible module capable of notifying medic when commits for your custom test suite get pushed. See below for more information. Only applies to dynamic testing applications.--platforms, -p [platform(s)]
: A comma-separated list of supported platforms. A supported platform string can be followed by an @
and then either a tag or SHA. If a tag or SHA is provided, versions of the app will only be built against that tag or SHA for the specified platform. If not specified, medic will listen for new commits to Cordova for the provided platforms and queue builds of the app for platforms as new commits come in.This module should be defined as a function that takes five parameters:
module.exports = function(output_location, sha, devices, entry_point, callback) { }
The parameters:
output_location
: A full path string to the location of where the test application should be built. It should compose a directory full of HTML, CSS and JavaScript assets that make up your test application.sha
: The SHA or tag that should be built. For dynamic test app generation, this string is useful for identifying and keeping track of results.devices
: not applicableentry_point
: the entry point into the app as defined by configuration. not applicable to authors of dynamic test application builders, really. Dun worry 'bout it.callback
: This one you should worry about! Fire this callback off once you are done building the app. Optionally, pass a truthy value as first parameter to let medic know some bad shit happened.For a real-world example, check out the mobile-spec builder (right here: src/build/makers/mobile_spec.js
).
This module should be defined as a function that takes a single callback. The callback should be fired whenever your test application receives a new commit. How this is done is up to.
A short example:
module.exports = function(callback) { setTimeout(callback, 2000); };
The above will fire the callback after 2 seconds - it is trivial for example purposes.
For a real-world example of how Cordova implements its commit hook for medic, look at src/build/makers/mobile_spec/commit_hook.js
.
$ node build.js
In this example I am using Pivotal's Jasmine BDD JavaScript test framework's test suite, cloned locally under ../jasmine
, telling medic to launch the page located at ../jasmine/spec/runner.html
on application run.
$ node build.js -a ../jasmine -e spec/runner.html
In this example, I tell medic to use a test suite located online (Backbone's test suite) and deploy it to devices.
$ node build.js -e http://backbonejs.org/test/index.html