|
8 | 8 | parentUrl = activeScript && activeScript.src ? |
9 | 9 | activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" : |
10 | 10 | "../", |
11 | | - QUnit = window.QUnit || parent.QUnit, |
12 | | - require = window.require || parent.require, |
| 11 | + QUnit = window.QUnit, |
| 12 | + require = window.require, |
13 | 13 |
|
14 | 14 | // Default to unminified jQuery for directly-opened iframes |
15 | | - urlParams = QUnit ? |
16 | | - QUnit.urlParams : |
| 15 | + config = QUnit ? |
| 16 | + |
| 17 | + // QUnit.config is populated from QUnit.urlParams but only at the beginning |
| 18 | + // of the test run. We need to read both. |
| 19 | + { |
| 20 | + esmodules: !!( QUnit.config.esmodules || QUnit.urlParams.esmodules ), |
| 21 | + amd: !!( QUnit.config.amd || QUnit.urlParams.amd ) |
| 22 | + } : |
| 23 | + |
17 | 24 | { dev: true }, |
18 | | - src = urlParams.dev ? |
| 25 | + src = config.dev ? |
19 | 26 | "dist/jquery.js" : |
20 | 27 | "dist/jquery.min.js"; |
21 | 28 |
|
22 | 29 | // Define configuration parameters controlling how jQuery is loaded |
23 | 30 | if ( QUnit ) { |
24 | | - |
25 | | - // ES modules loading is asynchronous and incompatible with synchronous |
26 | | - // test loading in Karma. |
27 | | - if ( !window.__karma__ ) { |
28 | | - QUnit.config.urlConfig.push( { |
29 | | - id: "esmodules", |
30 | | - label: "Load as modules", |
31 | | - tooltip: "Load the jQuery module file (and its dependencies)" |
32 | | - } ); |
33 | | - QUnit.config.urlConfig.push( { |
34 | | - id: "amd", |
35 | | - label: "Load with AMD", |
36 | | - tooltip: "Load the AMD jQuery file (and its dependencies)" |
37 | | - } ); |
38 | | - } |
39 | | - |
40 | 31 | QUnit.config.urlConfig.push( { |
| 32 | + id: "esmodules", |
| 33 | + label: "Load as modules", |
| 34 | + tooltip: "Load the jQuery module file (and its dependencies)" |
| 35 | + }, { |
| 36 | + id: "amd", |
| 37 | + label: "Load with AMD", |
| 38 | + tooltip: "Load the AMD jQuery file (and its dependencies)" |
| 39 | + }, { |
41 | 40 | id: "dev", |
42 | 41 | label: "Load unminified", |
43 | 42 | tooltip: "Load the development (unminified) jQuery file" |
|
46 | 45 |
|
47 | 46 | // Honor ES modules loading on the main window (detected by seeing QUnit on it). |
48 | 47 | // This doesn't apply to iframes because they synchronously expect jQuery to be there. |
49 | | - if ( urlParams.esmodules && window.QUnit ) { |
| 48 | + if ( config.esmodules && QUnit ) { |
50 | 49 |
|
51 | 50 | // Support: IE 11+, Edge 12 - 18+ |
52 | 51 | // IE/Edge don't support the dynamic import syntax so they'd crash |
53 | 52 | // with a SyntaxError here. |
54 | 53 | dynamicImportSource = "" + |
55 | | - "import( `${ parentUrl }src/jquery.js` ).then( ( { default: jQuery } ) => {\n" + |
56 | | - " window.jQuery = jQuery;\n" + |
57 | | - " if ( typeof loadTests === \"function\" ) {\n" + |
58 | | - " // Include tests if specified\n" + |
59 | | - " loadTests();\n" + |
60 | | - " }\n" + |
61 | | - "} );"; |
| 54 | + "import( `${ parentUrl }src/jquery.js` )\n" + |
| 55 | + " .then( ( { default: jQuery } ) => {\n" + |
| 56 | + " window.jQuery = jQuery;\n" + |
| 57 | + " if ( typeof loadTests === \"function\" ) {\n" + |
| 58 | + " // Include tests if specified\n" + |
| 59 | + " loadTests();\n" + |
| 60 | + " }\n" + |
| 61 | + " } )\n" + |
| 62 | + " .catch( error => {\n" + |
| 63 | + " console.error( error );\n" + |
| 64 | + " QUnit.done();\n" + |
| 65 | + " } );"; |
62 | 66 |
|
63 | 67 | eval( dynamicImportSource ); |
64 | 68 |
|
65 | 69 | // Apply similar treatment for AMD modules |
66 | | - } else if ( urlParams.amd && window.QUnit ) { |
| 70 | + } else if ( config.amd && QUnit ) { |
67 | 71 | require.config( { |
68 | 72 | baseUrl: parentUrl |
69 | 73 | } ); |
|
0 commit comments