Skip to content

Commit 1b844dc

Browse files
committed
Merge pull request #31 from mislav/headless-tests
Add headless testing & Travis CI support for QUnit
2 parents 8e96a4e + 70090d8 commit 1b844dc

File tree

6 files changed

+84
-30
lines changed

6 files changed

+84
-30
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
script: script/test
2+
language: node_js
3+
node_js:
4+
- '0.10'

script/test

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ -t 1 ]; then
5+
red="$(printf "\033[31m")"
6+
brightred="$(printf "\033[31;1m")"
7+
green="$(printf "\033[32m")"
8+
reset="$(printf "\033[m")"
9+
else
10+
red=
11+
brightred=
12+
green=
13+
reset=
14+
fi
15+
16+
phantomjs tests/runner.coffee tests/qunit.html | sed -E "
17+
# failure line:
18+
s/^(✘.+)/${red}\\1${reset}/
19+
# failure details:
20+
s/^( .+)/${brightred}\\1${reset}/
21+
# success marker:
22+
s/(✔︎)/${green}\\1${reset}/
23+
"

tests/duplicationTest.html

-30
This file was deleted.

tests/qunit.html

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
1212
<script src="../classList.js"></script>
1313
<script src="tests.js"></script>
14+
<script src="remove.js"></script>
1415
</body>
1516
</html>

tests/remove.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
QUnit.module("classList.remove");
2+
3+
QUnit.test("Removes duplicated instances of class", function(assert) {
4+
var el = document.createElement("p"), cList = el.classList;
5+
el.className = "ho ho ho"
6+
7+
cList.remove("ho");
8+
assert.ok(!cList.contains("ho"), "Should remove all instances of 'ho'");
9+
assert.strictEqual(el.className, "")
10+
});

tests/runner.coffee

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
urls = require('system').args.slice(1)
2+
page = require('webpage').create()
3+
timeout = 3000
4+
5+
qunitHooks = ->
6+
window.document.addEventListener 'DOMContentLoaded', ->
7+
for callback in ['log', 'testDone', 'done']
8+
do (callback) ->
9+
QUnit[callback] (result) ->
10+
window.callPhantom
11+
name: "QUnit.#{callback}"
12+
data: result
13+
14+
page.onInitialized = -> page.evaluate qunitHooks
15+
16+
page.onConsoleMessage = (msg) -> console.log msg
17+
18+
page.onCallback = (event) ->
19+
if event.name is 'QUnit.log'
20+
details = event.data
21+
if details.result is false
22+
console.log "#{details.module}: #{details.name}"
23+
if details.message and details.message isnt "failed"
24+
console.log " #{details.message}"
25+
if "actual" of details
26+
console.log " expected: #{details.expected}"
27+
console.log " actual: #{details.actual}"
28+
else if event.name is 'QUnit.testDone'
29+
result = event.data
30+
unless result.failed
31+
console.log "✔︎ #{result.module}: #{result.name}"
32+
else if event.name is 'QUnit.done'
33+
res = event.data
34+
console.log "#{res.total} tests, #{res.failed} failed. Done in #{res.runtime} ms"
35+
phantom.exit if !res.total or res.failed then 1 else 0
36+
37+
for url in urls
38+
page.open url, (status) ->
39+
if status isnt 'success'
40+
console.error "failed opening #{url}: #{status}"
41+
phantom.exit 1
42+
else
43+
setTimeout ->
44+
console.error "ERROR: Test execution has timed out"
45+
phantom.exit 1
46+
, timeout

0 commit comments

Comments
 (0)