Revert "Export"
[framework/web/web-ui-fw.git] / tests / unit-tests / runner.js
1 $(document).ready(function() {
2         var Runner = function( ) {
3                 var self = this;
4
5                 $.extend( self, {
6                         frame: window.frames[ "testFrame" ],
7
8                         testTimeout: 3 * 60 * 1000,
9
10                         $frameElem: $( "#testFrame" ),
11
12                         assertionResultPrefix: "assertion result for test:",
13
14                         onTimeout: QUnit.start,
15
16                         onFrameLoad: function() {
17                                 // establish a timeout for a given suite in case of async tests hanging
18                                 self.testTimer = setTimeout( self.onTimeout, self.testTimeout );
19
20                                 // it might be a redirect with query params for push state
21                                 // tests skip this call and expect another
22                                 if( !self.frame.QUnit ) {
23                                         self.$frameElem.one( "load", self.onFrameLoad );
24                                         return;
25                                 }
26
27                                 // when the QUnit object reports done in the iframe
28                                 // run the onFrameDone method
29                                 self.frame.QUnit.done = self.onFrameDone;
30                                 self.frame.QUnit.testDone = self.onTestDone;
31                         },
32
33                         onTestDone: function( result ) {
34                                 QUnit.ok( !(result.failed > 0), result.name );
35                                 self.recordAssertions( result.total - result.failed, result.name );
36                         },
37
38                         onFrameDone: function( failed, passed, total, runtime ){
39                                 // make sure we don't time out the tests
40                                 clearTimeout( self.testTimer );
41
42                                 // TODO decipher actual cause of multiple test results firing twice
43                                 // clear the done call to prevent early completion of other test cases
44                                 self.frame.QUnit.done = $.noop;
45                                 self.frame.QUnit.testDone = $.noop;
46
47                                 // hide the extra assertions made to propogate the count
48                                 // to the suite level test
49                                 self.hideAssertionResults();
50
51                                 // continue on to the next suite
52                                 QUnit.start();
53                         },
54
55                         recordAssertions: function( count, parentTest ) {
56                                 for( var i = 0; i < count; i++ ) {
57                                         ok( true, self.assertionResultPrefix + parentTest );
58                                 }
59                         },
60
61                         hideAssertionResults: function() {
62                                 $( "li:not([id]):contains('" + self.assertionResultPrefix + "')" ).hide();
63                         },
64
65                         exec: function( data ) {
66                                 var template = self.$frameElem.attr( "data-src" );
67
68                                 $.each( data.testPages, function(i, dir) {
69                                         QUnit.asyncTest( dir, function() {
70                                                 console.log('Test start: ' + dir);
71                                                 self.dir = dir;
72                                                 self.$frameElem.one( "load", self.onFrameLoad );
73                                                 self.$frameElem.attr( "src", template.replace("{{testfile}}", dir + '/index.html') );
74                                         });
75                                 });
76
77                                 // having defined all suite level tests let QUnit run
78                                 QUnit.start();
79                         }
80                 });
81         };
82
83         // prevent qunit from starting the test suite until all tests are defined
84         QUnit.begin = function(  ) {
85                 this.config.autostart = false;
86         };
87
88         // get the test directories
89         new Runner().exec(TESTS);
90 });