🌐 AI搜索 & 代理 主页
Skip to content

Commit 14b393d

Browse files
authored
Tests: Update the loader so test pages always get jQuery
Pages used for iframe tests will now successfully load jQuery, even when opened directly in the browser. Closes gh-3489
1 parent 25c6a0a commit 14b393d

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

test/jquery.js

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,35 @@
22
( function() {
33
/* global loadTests: false */
44

5-
var src,
6-
path = window.location.pathname.split( "test" )[ 0 ],
5+
var path = window.location.pathname.split( "test" )[ 0 ],
76
QUnit = window.QUnit || parent.QUnit,
8-
require = window.require || parent.require;
9-
10-
// iFrames won't load AMD (the iframe tests synchronously expect jQuery to be there)
11-
QUnit.config.urlConfig.push( {
12-
id: "amd",
13-
label: "Load with AMD",
14-
tooltip: "Load the AMD jQuery file (and its dependencies)"
15-
} );
16-
17-
// If QUnit is on window, this is the main window
18-
// This detection allows AMD tests to be run in an iframe
19-
if ( QUnit.urlParams.amd && window.QUnit ) {
7+
require = window.require || parent.require,
8+
9+
// Default to unminified jQuery for directly-opened iframes
10+
urlParams = QUnit ?
11+
QUnit.urlParams :
12+
{ dev: true },
13+
src = urlParams.dev ?
14+
"dist/jquery.js" :
15+
"dist/jquery.min.js";
16+
17+
// Define configuration parameters controlling how jQuery is loaded
18+
if ( QUnit ) {
19+
QUnit.config.urlConfig.push( {
20+
id: "amd",
21+
label: "Load with AMD",
22+
tooltip: "Load the AMD jQuery file (and its dependencies)"
23+
} );
24+
QUnit.config.urlConfig.push( {
25+
id: "dev",
26+
label: "Load unminified",
27+
tooltip: "Load the development (unminified) jQuery file"
28+
} );
29+
}
30+
31+
// Honor AMD loading on the main window (detected by seeing QUnit on it).
32+
// This doesn't apply to iframes because they synchronously expect jQuery to be there.
33+
if ( urlParams.amd && window.QUnit ) {
2034
require.config( {
2135
baseUrl: path
2236
} );
@@ -28,28 +42,15 @@
2842
} else {
2943
require( [ src ] );
3044
}
31-
return;
32-
}
3345

34-
// Config parameter to use minified jQuery
35-
QUnit.config.urlConfig.push( {
36-
id: "dev",
37-
label: "Load unminified",
38-
tooltip: "Load the development (unminified) jQuery file"
39-
} );
40-
if ( QUnit.urlParams.dev ) {
41-
src = "dist/jquery.js";
46+
// Otherwise, load synchronously
4247
} else {
43-
src = "dist/jquery.min.js";
44-
}
45-
46-
// Load jQuery
47-
document.write( "<script id='jquery-js' src='" + path + src + "'><\x2Fscript>" );
48+
document.write( "<script id='jquery-js' src='" + path + src + "'><\x2Fscript>" );
4849

49-
// Synchronous-only tests
50-
// Other tests are loaded from the test page
51-
if ( typeof loadTests !== "undefined" ) {
52-
document.write( "<script src='" + path + "test/unit/ready.js'><\x2Fscript>" );
50+
// Synchronous-only tests (other tests are loaded from the test page)
51+
if ( typeof loadTests !== "undefined" ) {
52+
document.write( "<script src='" + path + "test/unit/ready.js'><\x2Fscript>" );
53+
}
5354
}
5455

5556
} )();

0 commit comments

Comments
 (0)