Browse files

Run all test cases on the overview page.

  • Loading branch information...
1 parent 0c63dfd commit 57b844fab02ef2f78697d89848f91a1428abe281 @bfanger bfanger committed Aug 29, 2012
Showing with 63 additions and 4 deletions.
  1. +19 −0 tests/css/style.css
  2. +37 −1 tests/index.php
  3. +7 −3 tests/js/main.js
View
19 tests/css/style.css
@@ -41,3 +41,22 @@ del {
display: none;
font-weight: bold;
}
+
+.progress {
+ display: inline-block;
+ background: #999999;
+ padding: 1px 4px 2px 4px;
+ border-radius: 4px;
+ font: 10px/10px sans-serif;
+ color: white;
+ margin-left: 10px;
+}
+.progress-pass {
+ background: #468847;
+}
+.progress-fail {
+ background: #b94a48;
+}
+.progress-tokenfail {
+ background: #f89406;
+}
View
38 tests/index.php
@@ -109,8 +109,44 @@
<p>Pick a test case to run. Make sure that you're using a capable browser.</p>
<?php foreach ((array) glob('cases/*.coffee') as $case): ?>
- <a href="?case=<?php echo $case ?>"><?php echo basename($case) ?></a><br />
+ <a class="testcase" href="?case=<?php echo $case ?>"><?php echo basename($case) ?></a><br />
<?php endforeach; ?>
+ <iframe id="testrunner" style="display: none"></iframe>
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
+ <script>
+ (function () {
+ var testcases = $('.testcase');
+ var iframe = document.getElementById('testrunner');
+ var testIndex = -1;
+ var $progress;
+ function runNextTest () {
+ testIndex++;
+ var link = testcases[testIndex];
+ if (typeof link === "undefined") { // no more testcases?
+ return;
+ }
+ $progress = $('<span class="progress">...</span>');
+ $(link).after($progress);
+ iframe.src = link.href;
+ }
+ window.testComplete = function (codeFailed, tokenFailed) {
+ if (codeFailed) {
+ $progress.text('fail');
+ $progress.addClass('progress-fail');
+ } else if (tokenFailed) {
+ $progress.text('fail');
+ $progress.addClass('progress-tokenfail');
+ } else {
+ $progress.text('pass');
+ $progress.addClass('progress-pass');
+ }
+ runNextTest();
+ }
+ runNextTest(); // Start first test.
+ })();
+
+ </script>
+
<?php endif; ?>
View
10 tests/js/main.js
@@ -9,24 +9,28 @@ function init(PHP) {
d = JsDiff.diffLines(formatTokens(JS.tokens), formatTokens(PHP.tokens));
$('#tokens .result').innerHTML = formatDiffLines(d);
- $('#tokens .' + (d.length > 1 || d[0].removed ? 'fail' : 'pass')).style.display = 'block';
+ var tokenFailed = d.length > 1 || d[0].removed;
+ $('#tokens .' + (tokenFailed ? 'fail' : 'pass')).style.display = 'block';
// Compile
JS.js = CoffeeScript.require['./parser'].parse(JS.tokens).compile();
// Code diff
d = JsDiff.diffLines(JS.js, PHP.js);
- var failed = d.length > 1 || d[0].removed;
+ var codeFailed = d.length > 1 || d[0].removed;
$('#code .result').innerHTML = formatDiffLines(d);
- var result = $('#code .' + (d.length > 1 || d[0].removed ? 'fail' : 'pass'));
+ var result = $('#code .' + (codeFailed ? 'fail' : 'pass'));
result.style.display = 'block';
if (PHP.error) {
result.innerHTML += '<br /><span style="font-weight: normal;">' + PHP.error + '</span>';
}
+ if (parent.testComplete) {
+ parent.testComplete(codeFailed, tokenFailed);
+ }
}
function $(elem) {

0 comments on commit 57b844f

Please sign in to comment.