Skip to content

Commit 9e9bef0

Browse files
committed
[fixup]: Reorganize a bunch of stuff
1 parent 3cdac75 commit 9e9bef0

File tree

8 files changed

+192
-132
lines changed

8 files changed

+192
-132
lines changed

external/qunit/qunit.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,13 +2863,19 @@ QUnit.testDone(function( details ) {
28632863
}
28642864
});
28652865

2866-
if ( !defined.document || document.readyState === "complete" ) {
2866+
if ( defined.document ) {
2867+
if ( document.readyState === "complete" ) {
2868+
if ( window.define && window.define.amd ) {
2869+
QUnit.config.autostart = false;
2870+
}
2871+
2872+
QUnit.load();
2873+
} else {
2874+
addEvent( window, "load", QUnit.load );
2875+
}
2876+
} else {
28672877
config.pageLoaded = true;
28682878
config.autorun = true;
28692879
}
28702880

2871-
if ( defined.document ) {
2872-
addEvent( window, "load", QUnit.load );
2873-
}
2874-
28752881
})();

tests/unit/accordion/accordion.html

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
<title>jQuery UI Accordion Test Suite</title>
66

77
<script src="../helper/css.js" data-modules="core accordion"></script>
8-
9-
<link rel="stylesheet" href="../../../external/qunit/qunit.css">
8+
<script src="../testsuite-require.js" data-widget="accordion"></script>
109
<style>
1110
#list, #list1 *, #navigation, #navigation * {
1211
margin: 0;
@@ -110,25 +109,5 @@ <h2><a href="?p=1.1.3">Drums</a></h2>
110109
</dl>
111110

112111
</div>
113-
114-
<script src="../../../external/requirejs/require.js"></script>
115-
<script src="../../../external/qunit/qunit.js"></script>
116-
<script src="../../../external/qunit-assert-classes/qunit-assert-classes.js"></script>
117-
<script src="../swarminject.js"></script>
118-
<script src="../helper/jquery.js"></script>
119-
<script src="../helper/require.js"></script>
120-
<script>
121-
QUnit.config.autostart = false;
122-
require_series([
123-
"./accordion_common",
124-
"./accordion_core",
125-
"./accordion_events" ,
126-
"./accordion_methods",
127-
"./accordion_options"
128-
], function() {
129-
QUnit.start();
130-
});
131-
</script>
132-
133112
</body>
134113
</html>

tests/unit/helper/css.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ function includeStyle( url ) {
44
document.write( "<link rel='stylesheet' href='../../../" + url + "'>" );
55
}
66

7+
// Find the script element
78
var scripts = document.getElementsByTagName( "script" );
89
var script = scripts[ scripts.length - 1 ];
9-
var modules = script.getAttribute( "data-modules" ).split( /\s+/ );
10-
var i = 0;
1110

12-
for ( ; i < modules.length; i++ ) {
13-
document.write( "<link rel='stylesheet' href='../../../themes/base/" + modules[ i ] + ".css'>" );
11+
// Load the modules
12+
var modules = script.getAttribute( "data-modules" ).split( /\s+/ );
13+
for ( var i = 0; i < modules.length; i++ ) {
14+
includeStyle( "themes/base/" + modules[ i ] + ".css" );
1415
}
1516

17+
// Load the QUnit stylesheet
18+
includeStyle( "external/qunit/qunit.css" );
19+
1620
} )();

tests/unit/helper/jquery.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/unit/helper/require.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/unit/helper/testsuite.js

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -65,47 +65,6 @@ function testBasicUsage( widget ) {
6565
});
6666
}
6767

68-
// Asset revisioning through time and random hashing
69-
function revStamp( value ) {
70-
return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" +
71-
parseInt(Math.random() * 100000, 10);
72-
}
73-
74-
QUnit.reset = ( function( reset ) {
75-
return function() {
76-
77-
// Ensure jQuery events and data on the fixture are properly removed
78-
jQuery( "#qunit-fixture" ).empty();
79-
80-
// Let QUnit reset the fixture
81-
reset.apply( this, arguments );
82-
};
83-
} )( QUnit.reset );
84-
85-
QUnit.config.requireExpects = true;
86-
87-
QUnit.config.urlConfig.push({
88-
id: "nojshint",
89-
label: "Skip JSHint",
90-
tooltip: "Skip running JSHint, e.g., within TestSwarm, where Jenkins runs it already"
91-
});
92-
93-
QUnit.config.urlConfig.push({
94-
id: "jquery",
95-
label: "jQuery version",
96-
value: [
97-
"1.7.0", "1.7.1", "1.7.2",
98-
"1.8.0", "1.8.1", "1.8.2", "1.8.3",
99-
"1.9.0", "1.9.1",
100-
"1.10.0", "1.10.1", "1.10.2",
101-
"1.11.0", "1.11.1", "1.11.2",
102-
"2.0.0", "2.0.1", "2.0.2", "2.0.3",
103-
"2.1.0", "2.1.1", "2.1.2", "2.1.3",
104-
"git1", "git"
105-
],
106-
tooltip: "Which jQuery Core version to test against"
107-
});
108-
10968
/**
11069
* Exports
11170
*/
@@ -277,11 +236,11 @@ exports.testJshint = function( module ) {
277236

278237
$.when(
279238
$.ajax({
280-
url: revStamp( "../../../ui/.jshintrc" ),
239+
url: "../../../ui/.jshintrc",
281240
dataType: "json"
282241
}),
283242
$.ajax({
284-
url: revStamp( "../../../ui/" + module + ".js" ),
243+
url: "../../../ui/" + module + ".js",
285244
dataType: "text"
286245
})
287246
).done(function( hintArgs, srcArgs ) {

tests/unit/qunit.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require( [
2+
"jquery",
3+
"qunit-core",
4+
"qunit-assert-classes"
5+
], function( $ ) {
6+
7+
QUnit.config.autostart = false;
8+
QUnit.config.requireExpects = true;
9+
10+
QUnit.config.urlConfig.push({
11+
id: "nojshint",
12+
label: "Skip JSHint",
13+
tooltip: "Skip running JSHint, e.g., within TestSwarm, where Jenkins runs it already"
14+
});
15+
16+
QUnit.config.urlConfig.push({
17+
id: "jquery",
18+
label: "jQuery version",
19+
value: [
20+
"1.7.0", "1.7.1", "1.7.2",
21+
"1.8.0", "1.8.1", "1.8.2", "1.8.3",
22+
"1.9.0", "1.9.1",
23+
"1.10.0", "1.10.1", "1.10.2",
24+
"1.11.0", "1.11.1", "1.11.2",
25+
"2.0.0", "2.0.1", "2.0.2", "2.0.3",
26+
"2.1.0", "2.1.1", "2.1.2", "2.1.3",
27+
"git1", "git"
28+
],
29+
tooltip: "Which jQuery Core version to test against"
30+
});
31+
32+
QUnit.reset = ( function( reset ) {
33+
return function() {
34+
35+
// Ensure jQuery events and data on the fixture are properly removed
36+
$( "#qunit-fixture" ).empty();
37+
38+
// Let QUnit reset the fixture
39+
reset.apply( this, arguments );
40+
};
41+
} )( QUnit.reset );
42+
43+
44+
return QUnit;
45+
46+
} );

tests/unit/testsuite-require.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
( function() {
2+
3+
window.requirejs = {
4+
paths: {
5+
"helper": "../helper",
6+
"jquery": jqueryUrl(),
7+
"jquery.simulate": "../../../external/jquery-simulate/jquery.simulate",
8+
"jshint": "../../../external/jshint/jshint",
9+
"qunit": "../qunit",
10+
"qunit-assert-classes": "../../../external/qunit-assert-classes/qunit-assert-classes",
11+
"qunit-core": "../../../external/qunit/qunit",
12+
"ui": "../../../ui"
13+
},
14+
shim: {
15+
"jquery.simulate": [ "jquery" ],
16+
"qunit-assert-classes": [ "qunit-core" ]
17+
}
18+
};
19+
20+
function requireModules( dependencies, callback, modules ) {
21+
if ( !dependencies.length ) {
22+
if ( callback ) {
23+
callback.apply( null, modules );
24+
}
25+
return;
26+
}
27+
28+
if ( !modules ) {
29+
modules = [];
30+
}
31+
32+
var dependency = dependencies.shift();
33+
require( [ dependency ], function( module ) {
34+
modules.push( module );
35+
requireModules( dependencies, callback, modules );
36+
} );
37+
}
38+
39+
window.requireTests = function( dependencies, callback ) {
40+
dependencies = [
41+
"qunit",
42+
"jquery"
43+
].concat( dependencies );
44+
45+
requireModules( dependencies, function() {
46+
swarmInject();
47+
QUnit.start();
48+
} );
49+
}
50+
51+
function parseUrl() {
52+
var data = {};
53+
var parts = document.location.search.slice( 1 ).split( "&" );
54+
var length = parts.length;
55+
var i = 0;
56+
var current;
57+
58+
for ( ; i < length; i++ ) {
59+
current = parts[ i ].split( "=" );
60+
data[ current[ 0 ] ] = current[ 1 ];
61+
}
62+
63+
return data;
64+
}
65+
66+
function jqueryUrl() {
67+
var version = parseUrl().jquery;
68+
var url;
69+
70+
if ( version === "git" ) {
71+
url = "http://code.jquery.com/jquery-git.js";
72+
} else {
73+
url = "../../../external/jquery-" + ( version || "1.10.2" ) + "/jquery";
74+
}
75+
76+
return url;
77+
};
78+
79+
function swarmInject() {
80+
var url = parseUrl().swarmURL;
81+
82+
if ( !url || url.indexOf( "http" ) !== 0 ) {
83+
return;
84+
}
85+
86+
document.write( "<script src='http://swarm.jquery.org/js/inject.js?" +
87+
(new Date()).getTime() + "'></script>" );
88+
}
89+
90+
(function() {
91+
92+
// Find the script element
93+
var scripts = document.getElementsByTagName( "script" );
94+
var script = scripts[ scripts.length - 1 ];
95+
96+
// Read the modules
97+
var modules = ( script.getAttribute( "data-modules" ) || "" )
98+
.replace( /^\s+|\s+$/g, "" )
99+
.split( /\s+/ );
100+
var widget = script.getAttribute( "data-widget" );
101+
var deprecated = script.getAttribute( "data-deprecated" );
102+
if ( widget ) {
103+
modules = modules.concat([
104+
widget + ( deprecated ? "_common_deprecated" : "_common" ),
105+
widget + "_core",
106+
widget + "_events",
107+
widget + "_methods",
108+
widget + "_options"
109+
]);
110+
if ( deprecated ) {
111+
modules = modules.concat( widget + "_deprecated" );
112+
}
113+
}
114+
115+
// Load requirejs, then load the tests
116+
script = document.createElement( "script" );
117+
script.src = "../../../external/requirejs/require.js";
118+
script.onload = function() {
119+
requireTests( modules );
120+
};
121+
document.documentElement.appendChild( script );
122+
} )();
123+
124+
} )();

0 commit comments

Comments
 (0)