Tests: Add custom attribute getter tests to the selector module
[jquery.git] / test / jquery.js
blobcd9c490b10b358382629dfbd2592bcabfdd70397
1 // Use the right jQuery source on the test page (and iframes)
2 ( function() {
3         var dynamicImportSource, config, src,
4                 parentUrl = window.location.protocol + "//" + window.location.host,
5                 QUnit = window.QUnit;
7         function getQUnitConfig() {
8                 var config = Object.create( null );
10                 // Default to unminified jQuery for directly-opened iframes
11                 if ( !QUnit ) {
12                         config.dev = true;
13                 } else {
15                         // QUnit.config is populated from QUnit.urlParams but only at the beginning
16                         // of the test run. We need to read both.
17                         QUnit.config.urlConfig.forEach( function( entry ) {
18                                 config[ entry.id ] = QUnit.config[ entry.id ] != null ?
19                                         QUnit.config[ entry.id ] :
20                                         QUnit.urlParams[ entry.id ];
21                         } );
22                 }
24                 return config;
25         }
27         // Define configuration parameters controlling how jQuery is loaded
28         if ( QUnit ) {
29                 QUnit.config.urlConfig.push( {
30                         id: "esmodules",
31                         label: "Load as modules",
32                         tooltip: "Load the jQuery module file (and its dependencies)"
33                 }, {
34                         id: "dev",
35                         label: "Load unminified",
36                         tooltip: "Load the development (unminified) jQuery file"
37                 } );
38         }
40         config = getQUnitConfig();
42         src = config.dev ?
43                 "dist/jquery.js" :
44                 "dist/jquery.min.js";
46         // Honor ES modules loading on the main window (detected by seeing QUnit on it).
47         // This doesn't apply to iframes because they synchronously expect jQuery to be there.
48         if ( config.esmodules && QUnit ) {
50                 // Support: IE 11+
51                 // IE doesn't support the dynamic import syntax so it would crash
52                 // with a SyntaxError here.
53                 dynamicImportSource = "" +
54                         "import( `${ parentUrl }/src/jquery.js` )\n" +
55                         "       .then( ( { 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                         "       } );";
67                 eval( dynamicImportSource );
69         // Otherwise, load synchronously
70         } else {
71                 document.write( "<script id='jquery-js' nonce='jquery+hardcoded+nonce' src='" + parentUrl + "/" + src + "'><\x2Fscript>" );
72         }
74 } )();