1 // Use the right jQuery source on the test page (and iframes)
3 /* global loadTests: false */
5 var dynamicImportSource, 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, ".." ) + "/" :
12 require = window.require;
14 function getQUnitConfig() {
15 var config = Object.create( null );
17 // Default to unminified jQuery for directly-opened iframes
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 ];
34 // Define configuration parameters controlling how jQuery is loaded
36 QUnit.config.urlConfig.push( {
38 label: "Load as modules",
39 tooltip: "Load the jQuery module file (and its dependencies)"
42 label: "Load unminified",
43 tooltip: "Load the development (unminified) jQuery file"
47 config = getQUnitConfig();
53 // Honor ES modules 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.esmodules && QUnit ) {
58 // IE doesn't support the dynamic import syntax so it would crash
59 // with a SyntaxError here.
60 dynamicImportSource = "" +
61 "import( `${ parentUrl }src/jquery.js` )\n" +
62 " .then( ( { jQuery } ) => {\n" +
63 " window.jQuery = jQuery;\n" +
64 " if ( typeof loadTests === \"function\" ) {\n" +
65 " // Include tests if specified\n" +
69 " .catch( error => {\n" +
70 " console.error( error );\n" +
74 eval( dynamicImportSource );
76 // Otherwise, load synchronously
78 document.write( "<script id='jquery-js' nonce='jquery+hardcoded+nonce' src='" + parentUrl + src + "'><\x2Fscript>" );