Created
January 16, 2014 20:04
-
-
Save prakhar1989/8462393 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset=utf-8 /> | |
| <title>Test Suite!</title> | |
| <style> | |
| li.pass { background: green; | |
| color: white;} | |
| li.fail { background: red; color: white;} | |
| ul#results ul { margin-bottom: 10px;} | |
| </style> | |
| </head> | |
| <body> | |
| <ul id="results"></ul> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var queue = [], paused = false; | |
| var results; | |
| this.test = function(title, fn) { | |
| queue.push(function() { | |
| results = document.getElementById('results'); | |
| results = assert(true, title).appendChild( | |
| document.createElement("ul")); | |
| fn(); | |
| }); | |
| runTest(); | |
| }; | |
| this.pause = function() { | |
| paused = true; | |
| }; | |
| this.resume = function() { | |
| paused = false; | |
| setTimeout(runTest, 1); | |
| }; | |
| function runTest() { | |
| if (!paused && queue.length) { | |
| queue.shift()(); | |
| if (!paused) { resume(); } | |
| } | |
| } | |
| this.assert = function(value, desc) { | |
| var li = document.createElement('li'); | |
| li.className = value ? "pass" : "fail"; | |
| li.appendChild(document.createTextNode(desc)); | |
| results.appendChild(li); | |
| if (!value) { | |
| li.parentNode.parentNode.className = "fail"; | |
| } | |
| return li; | |
| }; | |
| })(); | |
| // bootstrapper | |
| window.onload = function() { | |
| test("Async test 1", function() { | |
| pause(); | |
| setTimeout(function() { | |
| assert(true, "first test completed"); | |
| resume(); | |
| }, 1000); | |
| }); | |
| test("Async test 2", function() { | |
| pause(); | |
| setTimeout(function() { | |
| assert(false, "second has failed"); | |
| resume(); | |
| }, 1000); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment