Permalink
Browse files

Using QUnit for unit tests

  • Loading branch information...
jbrantly committed Apr 14, 2010
1 parent ac1eeb2 commit 47afa94936ad3fc0a7973dd5aae0aabfde6c55a4
Showing with 1,267 additions and 140 deletions.
  1. +37 −53 tests/modules1.0/index.html
  2. +39 −54 tests/modules1.0/wrappedIndex.html
  3. +3 −33 tests/print.js
  4. +119 −0 tests/qunit.css
  5. +1,069 −0 tests/qunit.js
@@ -3,65 +3,49 @@
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <script type="text/javascript" src="../print.js"></script>
+
<script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../print.js"></script>
+
<script type="text/javascript">
- require.setModuleRoot('tests/absolute');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('tests/cyclic');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('tests/determinism');
- require.run('program', function() {
-
+ var tests = [
+ ['absolute', 2],
+ ['cyclic', 5],
+ ['determinism', 2],
+ ['exactExports', 2],
+ ['hasOwnProperty', 1],
+ ['method', 4],
+ ['missing', 2],
+ ['monkeys', 2],
+ ['nested', 2],
+ ['relative', 2],
+ ['transitive', 2]
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ var testName = tests[i][0],
+ expected = tests[i][1];
+ test(testName, expected, (function(testName) {
+ return function() {
+ stop();
require.reset();
- require.setModuleRoot('tests/exactExports');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('tests/hasOwnProperty');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('tests/method');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('tests/missing');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('tests/monkeys');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('tests/nested');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('tests/relative');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('tests/transitive');
- require.run('program', function() {
+ require.setModuleRoot('tests/' + testName);
+ require.run('program', function() {
+ start();
+ });
+ };
+ })(testName));
- });
- });
- });
- });
- });
- });
- });
- });
- });
- });
- });
+ }
</script>
</head>
<body>
+ <h1 id="qunit-header">Yabble Modules/1.0 Unit Tests</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
</body>
</html>
@@ -3,66 +3,51 @@
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <script type="text/javascript" src="../print.js"></script>
+
<script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../print.js"></script>
+
<script type="text/javascript">
require.useScriptTags();
- require.setModuleRoot('wrappedTests/absolute');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('wrappedTests/cyclic');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('wrappedTests/determinism');
- require.run('program', function() {
-
+
+ var tests = [
+ ['absolute', 2],
+ ['cyclic', 5],
+ ['determinism', 2],
+ ['exactExports', 2],
+ ['hasOwnProperty', 1],
+ ['method', 4],
+ ['missing', 2],
+ ['monkeys', 2],
+ ['nested', 2],
+ ['relative', 2],
+ ['transitive', 2]
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ var testName = tests[i][0],
+ expected = tests[i][1];
+ test(testName, expected, (function(testName) {
+ return function() {
+ stop();
require.reset();
- require.setModuleRoot('wrappedTests/exactExports');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('wrappedTests/hasOwnProperty');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('wrappedTests/method');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('wrappedTests/missing');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('wrappedTests/monkeys');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('wrappedTests/nested');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('wrappedTests/relative');
- require.run('program', function() {
-
- require.reset();
- require.setModuleRoot('wrappedTests/transitive');
- require.run('program', function() {
-
- });
- });
- });
- });
- });
- });
- });
- });
- });
- });
- });
+ require.setModuleRoot('wrappedTests/' + testName);
+ require.run('program', function() {
+ start();
+ });
+ };
+ })(testName));
+
+ }
</script>
</head>
<body>
+ <h1 id="qunit-header">Yabble Modules/1.0 Unit Tests (Wrapped Modules)</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
</body>
</html>
View
@@ -1,33 +1,3 @@
-(function() {
-
- var messages = [];
- var outputDiv;
-
- window.onload = function() {
- //console.log('onload', messages.length);
- var body = document.getElementsByTagName('body')[0];
- outputDiv = document.createElement('div');
- body.appendChild(outputDiv);
-
- for (var i = 0, n = messages.length; i<n; i++) {
- print(messages[i]);
- }
- };
-
-
- window.print = function() {
- if (outputDiv) {
- var div = document.createElement('div');
- for (var i = 0, n = arguments.length; i<n; i++) {
- var span = document.createElement('span');
- span.appendChild(document.createTextNode(arguments[i]));
- div.appendChild(span);
- }
- outputDiv.appendChild(div);
- }
- else {
- messages.push(Array.prototype.slice(arguments, 0));
- }
- }
-
-})();
+window.print = function(message, type) {
+ ok(type == 'info' || type == 'pass', message);
+}
View
@@ -0,0 +1,119 @@
+
+ol#qunit-tests {
+ font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
+ margin:0;
+ padding:0;
+ list-style-position:inside;
+
+ font-size: smaller;
+}
+ol#qunit-tests li{
+ padding:0.4em 0.5em 0.4em 2.5em;
+ border-bottom:1px solid #fff;
+ font-size:small;
+ list-style-position:inside;
+}
+ol#qunit-tests li ol{
+ box-shadow: inset 0px 2px 13px #999;
+ -moz-box-shadow: inset 0px 2px 13px #999;
+ -webkit-box-shadow: inset 0px 2px 13px #999;
+ margin-top:0.5em;
+ margin-left:0;
+ padding:0.5em;
+ background-color:#fff;
+ border-radius:15px;
+ -moz-border-radius: 15px;
+ -webkit-border-radius: 15px;
+}
+ol#qunit-tests li li{
+ border-bottom:none;
+ margin:0.5em;
+ background-color:#fff;
+ list-style-position: inside;
+ padding:0.4em 0.5em 0.4em 0.5em;
+}
+
+ol#qunit-tests li li.pass{
+ border-left:26px solid #C6E746;
+ background-color:#fff;
+ color:#5E740B;
+ }
+ol#qunit-tests li li.fail{
+ border-left:26px solid #EE5757;
+ background-color:#fff;
+ color:#710909;
+}
+ol#qunit-tests li.pass{
+ background-color:#D2E0E6;
+ color:#528CE0;
+}
+ol#qunit-tests li.fail{
+ background-color:#EE5757;
+ color:#000;
+}
+ol#qunit-tests li strong {
+ cursor:pointer;
+}
+h1#qunit-header{
+ background-color:#0d3349;
+ margin:0;
+ padding:0.5em 0 0.5em 1em;
+ color:#fff;
+ font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
+ border-top-right-radius:15px;
+ border-top-left-radius:15px;
+ -moz-border-radius-topright:15px;
+ -moz-border-radius-topleft:15px;
+ -webkit-border-top-right-radius:15px;
+ -webkit-border-top-left-radius:15px;
+ text-shadow: rgba(0, 0, 0, 0.5) 4px 4px 1px;
+}
+h2#qunit-banner{
+ font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
+ height:5px;
+ margin:0;
+ padding:0;
+}
+h2#qunit-banner.qunit-pass{
+ background-color:#C6E746;
+}
+h2#qunit-banner.qunit-fail, #qunit-testrunner-toolbar {
+ background-color:#EE5757;
+}
+#qunit-testrunner-toolbar {
+ font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
+ padding:0;
+ /*width:80%;*/
+ padding:0em 0 0.5em 2em;
+ font-size: small;
+}
+h2#qunit-userAgent {
+ font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
+ background-color:#2b81af;
+ margin:0;
+ padding:0;
+ color:#fff;
+ font-size: small;
+ padding:0.5em 0 0.5em 2.5em;
+ text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
+}
+p#qunit-testresult{
+ font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
+ margin:0;
+ font-size: small;
+ color:#2b81af;
+ border-bottom-right-radius:15px;
+ border-bottom-left-radius:15px;
+ -moz-border-radius-bottomright:15px;
+ -moz-border-radius-bottomleft:15px;
+ -webkit-border-bottom-right-radius:15px;
+ -webkit-border-bottom-left-radius:15px;
+ background-color:#D2E0E6;
+ padding:0.5em 0.5em 0.5em 2.5em;
+}
+strong b.fail{
+ color:#710909;
+ }
+strong b.pass{
+ color:#5E740B;
+ }
Oops, something went wrong.

0 comments on commit 47afa94

Please sign in to comment.