3.6.4
[jquery.git] / test / jquery.js
blobbb4ae6fe4b182115c773d6de9396094f4dc26104
1 // Use the right jQuery source on the test page (and iframes)
2 ( function() {
3         /* global loadTests: false */
5         var config, src,
6                 FILEPATH = "/test/jquery.js",
7                 activeScript = [].slice.call( document.getElementsByTagName( "script" ), -1 )[ 0 ],
8                 parentUrl = activeScript && activeScript.src ?
9                         activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" :
10                         "../",
11                 QUnit = window.QUnit,
12                 require = window.require;
14         function getQUnitConfig() {
15                 var config = Object.create( null );
17                 // Default to unminified jQuery for directly-opened iframes
18                 if ( !QUnit ) {
19                         config.dev = true;
20                 } else {
22                         // QUnit.config is populated from QUnit.urlParams but only at the beginning
23                         // of the test run. We need to read both.
24                         QUnit.config.urlConfig.forEach( function( entry ) {
25                                 config[ entry.id ] = QUnit.config[ entry.id ] != null ?
26                                         QUnit.config[ entry.id ] :
27                                         QUnit.urlParams[ entry.id ];
28                         } );
29                 }
31                 return config;
32         }
34         // Define configuration parameters controlling how jQuery is loaded
35         if ( QUnit ) {
36                 QUnit.config.urlConfig.push( {
37                         id: "amd",
38                         label: "Load with AMD",
39                         tooltip: "Load the AMD jQuery file (and its dependencies)"
40                 }, {
41                         id: "dev",
42                         label: "Load unminified",
43                         tooltip: "Load the development (unminified) jQuery file"
44                 } );
45         }
47         config = getQUnitConfig();
49         src = config.dev ?
50                 "dist/jquery.js" :
51                 "dist/jquery.min.js";
53         // Honor AMD loading on the main window (detected by seeing QUnit on it).
54         // This doesn't apply to iframes because they synchronously expect jQuery to be there.
55         if ( config.amd && QUnit ) {
56                 require.config( {
57                         baseUrl: parentUrl
58                 } );
59                 src = "src/jquery";
61                 // Include tests if specified
62                 if ( typeof loadTests !== "undefined" ) {
63                         require( [ src ], loadTests );
64                 } else {
65                         require( [ src ] );
66                 }
68         // Otherwise, load synchronously
69         } else {
70                 document.write( "<script id='jquery-js' nonce='jquery+hardcoded+nonce' src='" + parentUrl + src + "'><\x2Fscript>" );
71         }
73 } )();