Skip to content

Instantly share code, notes, and snippets.

@FND
Created August 18, 2010 21:04
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save FND/536188 to your computer and use it in GitHub Desktop.
(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;
}
};
})();
(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);
}
};
})();
.PHONY: lib
lib:
curl -s -o lib/qunit.js \
http://github.com/jquery/qunit/raw/master/qunit/qunit.js
(function() {
var stats = QUnit.config.stats;
console.log("passed:", stats.all - stats.bad, "/", stats.all);
quit(stats.bad ? 1 : 0);
})();
#!/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
(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);
console = {
log: print
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment