8e6671ed961bb7b97fe7df4d549ef9a58a3e9e3c
[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 * Configuration
15 */
16 QUnit.config.testTimeout = 5000;
17
18 /**
19 * Load TestSwarm agent
20 */
21 if ( QUnit.urlParams.swarmURL ) {
22 document.write("<scr" + "ipt src='" + QUnit.fixurl( mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/testwarm.inject.js' ) + "'></scr" + "ipt>");
23 }
24
25 /**
26 * Load completenesstest
27 */
28 if ( QUnit.urlParams.completenesstest ) {
29
30 // Return true to ignore
31 var mwTestIgnore = function( val, tester, funcPath ) {
32
33 // Don't record methods of the properties of constructors,
34 // to avoid getting into a loop (prototype.constructor.prototype..).
35 // Since we're therefor skipping any injection for
36 // "new mw.Foo()", manually set it to true here.
37 if ( val instanceof mw.Map ) {
38 tester.methodCallTracker['Map'] = true;
39 return true;
40 }
41 if ( val instanceof mw.Title ) {
42 tester.methodCallTracker['Title'] = true;
43 return true;
44 }
45
46 // Don't record methods of the properties of a jQuery object
47 if ( val instanceof $ ) {
48 return true;
49 }
50
51 return false;
52 };
53
54 var mwTester = new CompletenessTest( mw, mwTestIgnore );
55 }
56
57 /**
58 * Add-on assertion helpers
59 */
60 // Define the add-ons
61 var addons = {
62
63 // Expect boolean true
64 assertTrue: function( actual, message ) {
65 strictEqual( actual, true, message );
66 },
67
68 // Expect boolean false
69 assertFalse: function( actual, message ) {
70 strictEqual( actual, false, message );
71 },
72
73 // Expect numerical value less than X
74 lt: function( actual, expected, message ) {
75 QUnit.push( actual < expected, actual, 'less than ' + expected, message );
76 },
77
78 // Expect numerical value less than or equal to X
79 ltOrEq: function( actual, expected, message ) {
80 QUnit.push( actual <= expected, actual, 'less than or equal to ' + expected, message );
81 },
82
83 // Expect numerical value greater than X
84 gt: function( actual, expected, message ) {
85 QUnit.push( actual > expected, actual, 'greater than ' + expected, message );
86 },
87
88 // Expect numerical value greater than or equal to X
89 gtOrEq: function( actual, expected, message ) {
90 QUnit.push( actual >= expected, actual, 'greater than or equal to ' + expected, message );
91 },
92
93 // Backwards compatible with new verions of QUnit
94 equals: window.equal,
95 same: window.deepEqual
96 };
97
98 $.extend( QUnit, addons );
99 $.extend( window, addons );
100
101 })( jQuery );