Core: Preserve CSP nonce on scripts in DOM manipulation
[jquery.git] / test / jquery.js
blob6b1aef42f6c8bda2f0435900ce9613a1d149b515
1 // Use the right jQuery source on the test page (and iframes)
2 ( function() {
3         /* global loadTests: false */
5         var FILEPATH = "/test/jquery.js",
6                 activeScript = [].slice.call( document.getElementsByTagName( "script" ), -1 )[ 0 ],
7                 parentUrl = activeScript && activeScript.src ?
8                         activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" :
9                         "../",
10                 QUnit = window.QUnit || parent.QUnit,
11                 require = window.require || parent.require,
13                 // Default to unminified jQuery for directly-opened iframes
14                 urlParams = QUnit ?
15                         QUnit.urlParams :
16                         { dev: true },
17                 src = urlParams.dev ?
18                         "dist/jquery.js" :
19                         "dist/jquery.min.js";
21         // Define configuration parameters controlling how jQuery is loaded
22         if ( QUnit ) {
24                 // AMD loading is asynchronous and incompatible with synchronous test loading in Karma
25                 if ( !window.__karma__ ) {
26                         QUnit.config.urlConfig.push( {
27                                 id: "amd",
28                                 label: "Load with AMD",
29                                 tooltip: "Load the AMD jQuery file (and its dependencies)"
30                         } );
31                 }
33                 QUnit.config.urlConfig.push( {
34                         id: "dev",
35                         label: "Load unminified",
36                         tooltip: "Load the development (unminified) jQuery file"
37                 } );
38         }
40         // Honor AMD loading on the main window (detected by seeing QUnit on it).
41         // This doesn't apply to iframes because they synchronously expect jQuery to be there.
42         if ( urlParams.amd && window.QUnit ) {
43                 require.config( {
44                         baseUrl: parentUrl
45                 } );
46                 src = "src/jquery";
48                 // Include tests if specified
49                 if ( typeof loadTests !== "undefined" ) {
50                         require( [ src ], loadTests );
51                 } else {
52                         require( [ src ] );
53                 }
55         // Otherwise, load synchronously
56         } else {
57                 document.write( "<script id='jquery-js' nonce='jquery+hardcoded+nonce' src='" + parentUrl + src + "'><\x2Fscript>" );
58         }
60 } )();