Skip to content

Commit 8fe87e2

Browse files
Wesley Walserscottgonzalez
Wesley Walser
authored andcommitted
Tests: Modified testsuites.js into a subsuiteRunner extension for QUnit.
1 parent 70687f7 commit 8fe87e2

File tree

5 files changed

+98
-79
lines changed

5 files changed

+98
-79
lines changed

external/qunit.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ extend(QUnit, {
625625
var source = sourceFromStacktrace();
626626
if (source) {
627627
details.source = source;
628-
output += '<tr class="test-source"><th>Source: </th><td><pre>' + source +'</pre></td></tr>';
628+
output += '<tr class="test-source"><th>Source: </th><td><pre>' + escapeHtml(source) + '</pre></td></tr>';
629629
}
630630
}
631631
output += "</table>";
@@ -649,6 +649,10 @@ extend(QUnit, {
649649
return window.location.pathname + querystring.slice( 0, -1 );
650650
},
651651

652+
extend: extend,
653+
id: id,
654+
addEvent: addEvent,
655+
652656
// Logging callbacks; all receive a single argument with the listed properties
653657
// run test/logs.html for any related changes
654658
begin: function() {},
@@ -779,7 +783,7 @@ function done() {
779783
}
780784

781785
if ( typeof document !== "undefined" && document.title ) {
782-
// show ✖ for good, ✔ for bad suite result in title
786+
// show ✖ for bad, ✔ for good suite result in title
783787
// use escape sequences in case file gets loaded with non-utf-8-charset
784788
document.title = (config.stats.bad ? "\u2716" : "\u2714") + " " + document.title;
785789
}

tests/unit/all.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<script src="../../jquery-1.6.2.js"></script>
88

99
<link rel="stylesheet" href="../../external/qunit.css">
10+
<link rel="stylesheet" href="subsuiteRunner.css">
1011
<script src="../../external/qunit.js"></script>
11-
<script src="testsuites.js"></script>
12+
<script src="subsuiteRunner.js"></script>
1213

1314
<script>
1415
(function() {

tests/unit/subsuiteRunner.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
iframe.qunit-subsuite {
2+
margin: 0;
3+
padding: 0;
4+
border-width: 1px 0 0;
5+
height: 600px;
6+
width: 100%;
7+
background: #fff;
8+
}

tests/unit/subsuiteRunner.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
(function( QUnit ) {
2+
3+
var subsuiteFrame;
4+
5+
QUnit.extend( QUnit, {
6+
testSuites: function( suites ) {
7+
for ( var i = 0; i < suites.length; i++ ) {
8+
(function( suite ) {
9+
asyncTest( suite, function() {
10+
QUnit.runSuite( suite );
11+
});
12+
}( suites[i] ) );
13+
}
14+
QUnit.done = function() {
15+
subsuiteFrame.style.display = "none";
16+
};
17+
},
18+
19+
testStart: function( data ) {
20+
// update the test status to show which test suite is running
21+
QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...<br>&nbsp;";
22+
},
23+
24+
testDone: function() {
25+
var current = QUnit.id( this.config.current.id ),
26+
children = current.children;
27+
28+
// undo the auto-expansion of failed tests
29+
for ( var i = 0; i < children.length; i++ ) {
30+
if ( children[i].nodeName === "OL" ) {
31+
children[i].style.display = "none";
32+
}
33+
}
34+
},
35+
36+
runSuite: function( suite ) {
37+
var body = document.getElementsByTagName( "body" )[0],
38+
iframe = subsuiteFrame = document.createElement( "iframe" ),
39+
iframeWin;
40+
41+
iframe.className = "qunit-subsuite";
42+
body.appendChild( iframe );
43+
44+
function onIframeLoad() {
45+
var module, test,
46+
count = 0;
47+
48+
QUnit.extend( iframeWin.QUnit, {
49+
moduleStart: function( data ) {
50+
// capture module name for messages
51+
module = data.name;
52+
},
53+
54+
testStart: function( data ) {
55+
// capture test name for messages
56+
test = data.name;
57+
},
58+
59+
log: function( data ) {
60+
// pass all test details through to the main page
61+
var message = module + ": " + test + ": " + data.message;
62+
expect( ++count );
63+
QUnit.push( data.result, data.actual, data.expected, message );
64+
},
65+
66+
done: function() {
67+
// start the wrapper test from the main page
68+
start();
69+
}
70+
});
71+
}
72+
QUnit.addEvent( iframe, "load", onIframeLoad );
73+
74+
iframeWin = iframe.contentWindow;
75+
iframe.setAttribute( "src", suite );
76+
77+
this.runSuite = function( suite ) {
78+
iframe.setAttribute( "src", suite );
79+
};
80+
}
81+
});
82+
}( QUnit ) );

tests/unit/testsuites.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)