Running mocha tests on testling-ci is pretty simple.
configuring package.json
First you'll need to add a "harness"
field with the relevant user-interface to
use. The available interfaces are:
"mocha-bdd"
- gives youdescribe()
andit()
"mocha-tdd"
- gives youtest()
"mocha-exports"
- you writeexports.testname = function (done) {}
An interface harness of "mocha"
is the same as "mocha-bdd"
since bdd is
mocha's default ui.
In your package.json "testling"
field, add a "harness"
entry like in this
example:
{
"name": "beep-boop",
"version": "1.2.3",
"main": "index.js",
"devDependencies": {
"mocha": "~1.0.2"
},
"testling": {
"harness": "mocha-tdd",
"files": "test/*.js",
"browsers": [
"ie/8..latest",
"chrome/latest",
"firefox/latest"
]
},
"scripts": {
"test": "mocha --ui tdd"
}
}
Make sure that "mocha"
is listed under "devDependencies"
.
testing locally
It's a good idea to verify your configuration locally before running your tests on testling-ci.
First install the testling
command if you haven't already done so:
npm install -g testling
Now from the project root directory, simply type testling
:
$ testling
1..1
ok 1 integers should square the numbers
# tests 1
# pass 1
# fail 0
The testling
command automatically reads your package.json
and parses the
"testling"
field to figure out how to run your tests. It spins up a real local
browser (chrome or firefox) and launches it headlessly.
You can specify a custom browser command to run with the --bcmd
argument or
you can run testling -u
to simply print a url so you can visit the page
manually.
add a webhook for testling-ci
Now put your repository on github and add a github webhook from the settings/hooks page:
https://github.com/$USERNAME/$REPO/settings/hooks
Under "AVAILABLE SERVICE HOOKS", click "WebHook URLs".
Now add http://git.testling.com
as a WebHook URL.
Now every time you push new code to github, your tests will be run on testling-ci. You can also click the "test hook" button on github to send a hook without pushing new code.