Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a simple test runner

  • Loading branch information...
commit e56bdaa29989c52ce70b8757dd2e0014dd27f91c 1 parent 2cb4de9
Harry Love authored
Showing with 32 additions and 12 deletions.
  1. +8 −1 tests/index.html
  2. +24 −11 tests/runner.js
View
9 tests/index.html
@@ -3,6 +3,10 @@
<head>
<meta charset="UTF-8">
<title>Test index</title>
+ <style>
+ .true_result { background-color: lightGreen; }
+ .false_result { background-color: lightPink; }
+ </style>
</head>
<body>
<header>
@@ -11,7 +15,10 @@
</nav>
<h1>Test index</h1>
</header>
- <section>Loading</section>
+ <section>
+ <p id="count">Loading</p>
+ <ol id="test_results"></ol>
+ </section>
<!-- See runner.js (the "data-main" js file loaded by require.js) -->
<script data-main="runner" src="../js/require.js"></script>
</body>
View
35 tests/runner.js
@@ -1,23 +1,36 @@
require([
- '../js/underscore',
- '../js/zepto.js',
- '../js/backbone',
'simpletest'
- ], function() {
+ ], function(simpletest) {
require.ready(function() {
- TestRunner();
+ TestRunner(simpletest);
});
});
-var TestRunner = function() {
- var test = require('simpletest');
+var TestRunner = function(test) {
- var numTests = 0;
-
- var trueTest = function() { return true; }
+ var updateResults = function(result) {
+ document.getElementById('count').innerHTML = test.testCount + ' tests, ' + test.passCount + ' passing, ' + test.failCount + ' failing';
+ var item = document.createElement('li');
+ item.setAttribute('class', result + '_result');
+ item.appendChild(document.createTextNode(result));
+ document.getElementById('test_results').appendChild(item);
+ }
+
+ var trueTest = function trueTest() { return true; }
var result = test.assert(trueTest);
+ updateResults(result);
+
+ result = test.assertEqual(1, test.testCount);
+ updateResults(result);
+
+ result = test.assertEqual(2, test.testCount);
+ updateResults(result);
+
+ result = test.assertEqual(true, trueTest);
+ updateResults(result);
- $('section').html(result);
+ result = test.assertEqual(false, trueTest);
+ updateResults(result); // should be false
};
Please sign in to comment.
Something went wrong with that request. Please try again.