Created
August 18, 2010 21:04
-
-
Save FND/536188 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qunit.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
// | |
// environment | |
// | |
navigator = { | |
userAgent: "" | |
}; | |
window = { | |
location: {} | |
}; | |
location = window.location; | |
// | |
// DOM | |
// | |
var NOP = function() {}; | |
var Node = function() { | |
this.style = ""; | |
}; | |
Node.prototype.getElementsByTagName = function() { | |
return []; | |
}; | |
Node.prototype.insertBefore = NOP; | |
Node.prototype.appendChild = NOP; | |
Node.prototype.removeChild = NOP; | |
document = window.document = { | |
documentElement: new Node(), | |
createElement: function() { | |
return new Node(); | |
}, | |
createComment: function() { | |
return new Node(); | |
}, | |
getElementById: function() { | |
return null; | |
} | |
}; | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var currentTest; | |
QUnit.config.headless = { | |
abortOnFail: false, | |
verbose: false | |
}; | |
QUnit.testStart = function(name, testEnvironment) { | |
currentTest = name; | |
}; | |
QUnit.log = function(result, message) { | |
var prefix = QUnit.config.currentModule + "::" + currentTest; | |
var msg = message. | |
replace(/<span.*?>(.*?)<\/span>/g, "$1"). // remove spurious markup -- XXX: might affect tests' actual/expected data | |
replace(/^undefined, /, ""); // ignore missing descriptions | |
if(!result) { | |
console.log("ERROR (" + prefix + ")", msg); | |
if(QUnit.config.headless.abortOnFail) { | |
console.log("aborting"); | |
quit(1); // XXX: inelegant; should use QUnit facilities (if any) | |
} | |
} else if(QUnit.config.headless.verbose) { | |
console.log("PASS (" + prefix + ")", msg); | |
} | |
}; | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: lib | |
lib: | |
curl -s -o lib/qunit.js \ | |
http://github.com/jquery/qunit/raw/master/qunit/qunit.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var stats = QUnit.config.stats; | |
console.log("passed:", stats.all - stats.bad, "/", stats.all); | |
quit(stats.bad ? 1 : 0); | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# QUnit for Spidermonkey | |
# | |
# Usage: | |
# $ run.sh [-v] [-x] <testfiles> | |
set -e | |
die() { | |
echo "$*" | |
exit 1 | |
} | |
while getopts "vx" opt; do | |
case "$opt" in | |
"v" ) | |
verbose=true | |
;; | |
"x" ) | |
abort=true | |
;; | |
esac | |
done | |
shift $(( $OPTIND - 1 )) | |
if [ -z "$1" ]; then | |
die "no test files specified" | |
fi | |
testfiles="" | |
for filename in $@; do | |
testfiles="$testfiles -f $filename" | |
done | |
cfg='' # TODO: use array to allow for spaces in expressions? generate temporary file? | |
if [ "$verbose" = "true" ]; then | |
cfg="$cfg -e QUnit.config.headless.verbose=true;" | |
fi | |
if [ "$abort" = "true" ]; then | |
cfg="$cfg -e QUnit.config.headless.abortOnFail=true;" | |
fi | |
js -f fixtures/spidermonkey.js -f lib/qunit.js -f lib/headless.js \ | |
$cfg $testfiles \ | |
-f lib/report.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(module, test) { | |
module("Omega"); | |
test("Alpha", function() { | |
strictEqual("foo", "foo", "testA"); | |
strictEqual("foo", "bar", "testB"); | |
strictEqual("foo", "baz"); | |
}); | |
test("Bravo", function() { | |
strictEqual("foo", "foo"); | |
strictEqual("foo", "bar", "test2"); | |
strictEqual("foo", "baz"); | |
}); | |
})(QUnit.module, QUnit.test); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console = { | |
log: print | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment