Skip to content

Instantly share code, notes, and snippets.

@randombits
Created January 3, 2012 02:32
Show Gist options
  • Save randombits/1553193 to your computer and use it in GitHub Desktop.
Save randombits/1553193 to your computer and use it in GitHub Desktop.
Assembling QUnit tests from multiple files.
module("Comment");
test("List", function () {
ok(true, ":-)");
});
test("Add", function () {
ok(true, ":-)");
});
#!/bin/bash
tests="unit-tests.js"
echo Rebuilding $tests ...
rm $tests
echo "// This file was auto-generated by "$(basename $0)", "$(date --iso-8601=seconds) >> $tests
echo "function runTests() {" >> $tests
for test in tests/*.js
do
echo " adding" $test
echo " runTestsFromFile(\""$test\"")" >> $tests
done
echo "}" >> $tests
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test API 1.0</title>
<!-- Load jQuery and QUnit dependencies -->
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen"/>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
<!-- Load the auto-generated unit-tests.js -->
<script type="text/javascript" src="unit-tests.js"></script>
<!-- Run the Unit Tests -->
<script type="text/javascript">
// runTestsFromFile() is used by the auto-generated unit-tests.js to insert modules/tests.
function runTestsFromFile(filename) {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = filename;
var body = document.getElementsByTagName("head").item(0);
body.appendChild(script)
}
// Run the Unit Tests after the document has finished loading.
$(document).ready(function () {
test("API available", function () {
ok(true, ":-)");
});
// runTests() is defined in unit-tests.js.
runTests();
});
</script>
</head>
<body>
<h1 id="qunit-header">
Test API 1.0</h1>
<h2 id="qunit-banner">
</h2>
<div id="qunit-testrunner-toolbar">
</div>
<h2 id="qunit-userAgent">
</h2>
<ol id="qunit-tests">
</ol>
<div id="qunit-fixture">
</div>
</body>
</html>
// This file was auto-generated by unit-tests-rebuild.sh, yyyy-mm-ddThh:mm:ss-oooo.
function runTests() {
runTestsFromFile("tests/comment.js")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment