1 |
(function( QUnit ) { |
2 |
|
3 |
QUnit.extend( QUnit, { |
4 |
testSuites: function( suites ) { |
5 |
QUnit.begin(function() { |
6 |
QUnit.initIframe(); |
7 |
}); |
8 |
|
9 |
for ( var i = 0; i < suites.length; i++ ) { |
10 |
QUnit.runSuite( suites[i] ); |
11 |
} |
12 |
|
13 |
QUnit.done(function() { |
14 |
this.iframe.style.display = "none"; |
15 |
}); |
16 |
}, |
17 |
|
18 |
runSuite: function( suite ) { |
19 |
var path = suite; |
20 |
|
21 |
if ( QUnit.is( "object", suite ) ) { |
22 |
path = suite.path; |
23 |
suite = suite.name; |
24 |
} |
25 |
|
26 |
asyncTest( suite, function() { |
27 |
QUnit.iframe.setAttribute( "src", path ); |
28 |
}); |
29 |
}, |
30 |
|
31 |
initIframe: function() { |
32 |
var body = document.body, |
33 |
iframe = this.iframe = document.createElement( "iframe" ), |
34 |
iframeWin; |
35 |
|
36 |
iframe.className = "qunit-subsuite"; |
37 |
body.appendChild( iframe ); |
38 |
|
39 |
function onIframeLoad() { |
40 |
var module, test, |
41 |
count = 0; |
42 |
|
43 |
if (iframe.src === "") { |
44 |
return; |
45 |
} |
46 |
|
47 |
iframeWin.QUnit.moduleStart(function( data ) { |
48 |
// capture module name for messages |
49 |
module = data.name; |
50 |
}); |
51 |
|
52 |
iframeWin.QUnit.testStart(function( data ) { |
53 |
// capture test name for messages |
54 |
test = data.name; |
55 |
}); |
56 |
iframeWin.QUnit.testDone(function() { |
57 |
test = null; |
58 |
}); |
59 |
|
60 |
iframeWin.QUnit.log(function( data ) { |
61 |
if (test === null) { |
62 |
return; |
63 |
} |
64 |
// pass all test details through to the main page |
65 |
var message = module + ": " + test + ": " + data.message; |
66 |
expect( ++count ); |
67 |
QUnit.push( data.result, data.actual, data.expected, message ); |
68 |
}); |
69 |
|
70 |
iframeWin.QUnit.done(function() { |
71 |
// start the wrapper test from the main page |
72 |
start(); |
73 |
}); |
74 |
} |
75 |
QUnit.addEvent( iframe, "load", onIframeLoad ); |
76 |
|
77 |
iframeWin = iframe.contentWindow; |
78 |
} |
79 |
}); |
80 |
|
81 |
QUnit.testStart(function( data ) { |
82 |
// update the test status to show which test suite is running |
83 |
QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...<br> "; |
84 |
}); |
85 |
|
86 |
QUnit.testDone(function() { |
87 |
var i, |
88 |
current = QUnit.id( this.config.current.id ), |
89 |
children = current.children, |
90 |
src = this.iframe.src; |
91 |
|
92 |
// undo the auto-expansion of failed tests |
93 |
for ( i = 0; i < children.length; i++ ) { |
94 |
if ( children[i].nodeName === "OL" ) { |
95 |
children[i].style.display = "none"; |
96 |
} |
97 |
} |
98 |
|
99 |
QUnit.addEvent(current, "dblclick", function( e ) { |
100 |
var target = e && e.target ? e.target : window.event.srcElement; |
101 |
if ( target.nodeName.toLowerCase() === "span" || target.nodeName.toLowerCase() === "b" ) { |
102 |
target = target.parentNode; |
103 |
} |
104 |
if ( window.location && target.nodeName.toLowerCase() === "strong" ) { |
105 |
window.location = src; |
106 |
} |
107 |
}); |
108 |
|
109 |
current.getElementsByTagName("a")[0].href = src; |
110 |
}); |
111 |
|
112 |
}( QUnit ) ); |