diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/.eslintrc.json | 10 | ||||
-rw-r--r-- | test/data/testinit.js | 2 | ||||
-rw-r--r-- | test/index.html | 4 | ||||
-rw-r--r-- | test/jquery.js | 37 |
4 files changed, 34 insertions, 19 deletions
diff --git a/test/.eslintrc.json b/test/.eslintrc.json index a6d8fc872..f5a3fa591 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -63,6 +63,16 @@ "parserOptions": { "ecmaVersion": 2015 } + }, + + { + "files": [ + "jquery.js", + "data/testinit.js" + ], + "parserOptions": { + "ecmaVersion": 2020 + } } ] } diff --git a/test/data/testinit.js b/test/data/testinit.js index a597ccb35..7a8697189 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -300,7 +300,7 @@ QUnit.testUnlessIE = QUnit.isIE ? QUnit.skip : QUnit.test; this.loadTests = function() { // Directly load tests that need synchronous evaluation - if ( !QUnit.urlParams.amd || document.readyState === "loading" ) { + if ( !QUnit.urlParams.esmodules || document.readyState === "loading" ) { document.write( "<script src='" + parentUrl + "test/unit/ready.js'><\x2Fscript>" ); } else { QUnit.module( "ready", function() { diff --git a/test/index.html b/test/index.html index 7e5d8aa01..632275bb3 100644 --- a/test/index.html +++ b/test/index.html @@ -19,7 +19,7 @@ <!-- See testinit for the list of tests --> <script src="data/testinit.js"></script> - <!-- A script that includes jQuery min, dev, or AMD --> + <!-- A script that includes jQuery min, dev, or ES modules --> <!-- Adds "basic" URL option, even to iframes --> <!-- iframes will not load AMD as loading needs to be synchronous for some tests --> <!-- Also executes the function above to load tests --> @@ -29,7 +29,7 @@ // Load tests if they have not been loaded // This is in a different script tag to ensure that // jQuery is on the page when the testrunner executes - if ( !QUnit.urlParams.amd ) { + if ( !QUnit.urlParams.esmodules ) { loadTests(); } </script> diff --git a/test/jquery.js b/test/jquery.js index 6b1aef42f..d6d53fb26 100644 --- a/test/jquery.js +++ b/test/jquery.js @@ -2,7 +2,8 @@ ( function() { /* global loadTests: false */ - var FILEPATH = "/test/jquery.js", + var dynamicImportSource, + FILEPATH = "/test/jquery.js", activeScript = [].slice.call( document.getElementsByTagName( "script" ), -1 )[ 0 ], parentUrl = activeScript && activeScript.src ? activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" : @@ -21,12 +22,13 @@ // Define configuration parameters controlling how jQuery is loaded if ( QUnit ) { - // AMD loading is asynchronous and incompatible with synchronous test loading in Karma + // ES modules loading is asynchronous and incompatible with synchronous + // test loading in Karma. if ( !window.__karma__ ) { QUnit.config.urlConfig.push( { - id: "amd", - label: "Load with AMD", - tooltip: "Load the AMD jQuery file (and its dependencies)" + id: "esmodules", + label: "Load as modules", + tooltip: "Load a relevant jQuery module file (and its dependencies)" } ); } @@ -39,18 +41,21 @@ // Honor AMD loading on the main window (detected by seeing QUnit on it). // This doesn't apply to iframes because they synchronously expect jQuery to be there. - if ( urlParams.amd && window.QUnit ) { - require.config( { - baseUrl: parentUrl - } ); - src = "src/jquery"; + if ( urlParams.esmodules && window.QUnit ) { - // Include tests if specified - if ( typeof loadTests !== "undefined" ) { - require( [ src ], loadTests ); - } else { - require( [ src ] ); - } + // Support: IE 11+, Edge 12 - 18+ + // IE/Edge don't support the dynamic import syntax so they'd crash + // with a SyntaxError here. + dynamicImportSource = "" + + "import( `${ parentUrl }src/jquery.js` ).then( ( { default: jQuery } ) => {\n" + + " window.jQuery = jQuery;\n" + + " if ( typeof loadTests === \"function\" ) {\n" + + " // Include tests if specified\n" + + " loadTests();\n" + + " }\n" + + "} );"; + + eval( dynamicImportSource ); // Otherwise, load synchronously } else { |