aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/testsuites.js
blob: ffe2d3cc096f9347284416abc3bb779e25861cf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(function( $, QUnit ) {

$.extend( QUnit, {
	testSuites: function( suites ) {
		$.each( suites, function( i, suite ) {
			asyncTest( suite, function() {
				runSuite( suite );
			});
		});
	},

	testStart: function( data ) {
		// update the test status to show which test suite is running
		$( "#qunit-testresult" ).html( "Running " + data.name + "...<br>&nbsp;" );
	},

	testDone: function() {
		// undo the auto-expansion of failed tests
		$( "#qunit-tests > li.fail" ).each(function() {
			var test = $( this );
			// avoid collapsing test results that the user manually opened
			if ( test.data( "auto-collapsed" ) ) {
				return;
			}
			test.data( "auto-collapsed", true )
				.children( "ol" ).hide();
		});
	}
});

// generate an iframe to run the test suite and proxy the iframe's QUnit
// to pass all test info to the main page
function runSuite( suite ) {
	var body = $( "body" ),
		iframe = $( "<iframe>", { src: suite } )
			.css({
				width: 1000,
				height: 1000
			})
			.appendTo( body )
			[0],
		iframeWin = iframe.contentWindow;

	$( iframeWin ).bind( "load", function() {
		var module, test,
			count = 0;

		$.extend( iframeWin.QUnit, {
			moduleStart: function( data ) {
				// capture module name for messages
				module = data.name;
			},

			testStart: function( data ) {
				// capture test name for messages
				test = data.name;
			},

			log: function( data ) {
				// pass all test details through to the main page
				var message = module + ": " + test + ": " + data.message;
				expect( ++count );
				QUnit.push( data.result, data.actual, data.expected, message );
			},

			done: function() {
				// hide the iframe from the main page once the tests are done
				// and start the wrapper test from the main page
				$( iframe ).hide();
				start();
			}
		});
	});
}

}( jQuery, QUnit ) );