446add18313d7010c04eed60bf4db714ab46ee05
[lhc/web/wiklou.git] / tests / qunit / data / testrunner.js
1 ( function( $ ) {
2
3 /**
4 * Add bogus to url to prevent IE crazy caching
5 *
6 * @param value {String} a relative path (eg. 'data/defineTestCallback.js' or 'data/test.php?foo=bar')
7 * @return {String} Such as 'data/defineTestCallback.js?131031765087663960'
8 */
9 QUnit.fixurl = function(value) {
10 return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000);
11 };
12
13 /**
14 * Load TestSwarm agent
15 */
16 if ( QUnit.urlParams.swarmURL ) {
17 document.write("<scr" + "ipt src='" + QUnit.fixurl( 'data/testwarm.inject.js' ) + "'></scr" + "ipt>");
18 }
19
20 /**
21 * Load completenesstest
22 */
23 if ( QUnit.urlParams.completenesstest ) {
24
25 // Return true to ignore
26 var mwTestIgnore = function( val, tester, funcPath ) {
27
28 // Don't record methods of the properties of constructors,
29 // to avoid getting into a loop (prototype.constructor.prototype..).
30 // Since we're therefor skipping any injection for
31 // "new mw.Foo()", manually set it to true here.
32 if ( val instanceof mw.Map ) {
33 tester.methodCallTracker['Map'] = true;
34 return true;
35 }
36 if ( val instanceof mw.Title ) {
37 tester.methodCallTracker['Title'] = true;
38 return true;
39 }
40
41 // Don't record methods of the properties of a jQuery object
42 if ( val instanceof $ ) {
43 return true;
44 }
45
46 return false;
47 };
48
49 var mwTester = new CompletenessTest( mw, mwTestIgnore );
50 }
51
52 /**
53 * Add-on assertion helpers
54 */
55 // Define the add-ons
56 var addons = {
57
58 // Expect boolean true
59 assertTrue: function( actual, message ) {
60 strictEqual( actual, true, message );
61 },
62
63 // Expect boolean false
64 assertFalse: function( actual, message ) {
65 strictEqual( actual, false, message );
66 },
67
68 // Expect numerical value less than X
69 lt: function( actual, expected, message ) {
70 QUnit.push( actual < expected, actual, 'less than ' + expected, message );
71 },
72
73 // Expect numerical value less than or equal to X
74 ltOrEq: function( actual, expected, message ) {
75 QUnit.push( actual <= expected, actual, 'less than or equal to ' + expected, message );
76 },
77
78 // Expect numerical value greater than X
79 gt: function( actual, expected, message ) {
80 QUnit.push( actual > expected, actual, 'greater than ' + expected, message );
81 },
82
83 // Expect numerical value greater than or equal to X
84 gtOrEq: function( actual, expected, message ) {
85 QUnit.push( actual >= expected, actual, 'greater than or equal to ' + expected, message );
86 },
87
88 // Backwards compatible with new verions of QUnit
89 equals: window.equal,
90 same: window.deepEqual
91 };
92
93 $.extend( QUnit, addons );
94 $.extend( window, addons );
95
96 })( jQuery );