Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding a simple test runner

  • Loading branch information...
commit e56bdaa29989c52ce70b8757dd2e0014dd27f91c 1 parent 2cb4de9
Harry Love authored

Showing 2 changed files with 32 additions and 12 deletions. Show diff stats Hide diff stats

  1. +8 1 tests/index.html
  2. +24 11 tests/runner.js
9 tests/index.html
@@ -3,6 +3,10 @@
3 3 <head>
4 4 <meta charset="UTF-8">
5 5 <title>Test index</title>
  6 + <style>
  7 + .true_result { background-color: lightGreen; }
  8 + .false_result { background-color: lightPink; }
  9 + </style>
6 10 </head>
7 11 <body>
8 12 <header>
@@ -11,7 +15,10 @@
11 15 </nav>
12 16 <h1>Test index</h1>
13 17 </header>
14   - <section>Loading</section>
  18 + <section>
  19 + <p id="count">Loading</p>
  20 + <ol id="test_results"></ol>
  21 + </section>
15 22 <!-- See runner.js (the "data-main" js file loaded by require.js) -->
16 23 <script data-main="runner" src="../js/require.js"></script>
17 24 </body>
35 tests/runner.js
... ... @@ -1,23 +1,36 @@
1 1 require([
2   - '../js/underscore',
3   - '../js/zepto.js',
4   - '../js/backbone',
5 2 'simpletest'
6   - ], function() {
  3 + ], function(simpletest) {
7 4 require.ready(function() {
8   - TestRunner();
  5 + TestRunner(simpletest);
9 6 });
10 7 });
11 8
12   -var TestRunner = function() {
13   - var test = require('simpletest');
  9 +var TestRunner = function(test) {
14 10
15   - var numTests = 0;
16   -
17   - var trueTest = function() { return true; }
  11 + var updateResults = function(result) {
  12 + document.getElementById('count').innerHTML = test.testCount + ' tests, ' + test.passCount + ' passing, ' + test.failCount + ' failing';
  13 + var item = document.createElement('li');
  14 + item.setAttribute('class', result + '_result');
  15 + item.appendChild(document.createTextNode(result));
  16 + document.getElementById('test_results').appendChild(item);
  17 + }
  18 +
  19 + var trueTest = function trueTest() { return true; }
18 20
19 21 var result = test.assert(trueTest);
  22 + updateResults(result);
  23 +
  24 + result = test.assertEqual(1, test.testCount);
  25 + updateResults(result);
  26 +
  27 + result = test.assertEqual(2, test.testCount);
  28 + updateResults(result);
  29 +
  30 + result = test.assertEqual(true, trueTest);
  31 + updateResults(result);
20 32
21   - $('section').html(result);
  33 + result = test.assertEqual(false, trueTest);
  34 + updateResults(result); // should be false
22 35
23 36 };

0 comments on commit e56bdaa

Please sign in to comment.
Something went wrong with that request. Please try again.