]> source.dussan.org Git - jquery.git/commitdiff
Build: Make dev mode work in Karma again, serve source files from disk
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Tue, 7 Jan 2020 23:35:55 +0000 (00:35 +0100)
committerGitHub <noreply@github.com>
Tue, 7 Jan 2020 23:35:55 +0000 (00:35 +0100)
PR gh-4550 added support for running ES modules & AMD tests via Karma. This
required reading the `esmodules` & `amd` props from both `QUnit.config` &
`QUnit.urlParams`. By picking these two properties manually, the `dev` one
stopped being respected while ones handled directly by QUnit were fine (like
`hidepassed`). Instead of maintaining the full list of options, the code now
iterates over QUnit URL config and handles the fallbacks in a more generic way.

Apart from that, all jQuery source & test files are now read directly from disk
instead of being cached by Karma so that one can run `grunt karma:chrome-debug`
& work on a fix without restarting that Karma run after each change. A similar
effect could have been achieved by setting `autoWatch` to `true` but then the
main Karma page runs tests in an iframe by default when
`grunt karma:chrome-debug` is run instead of relying on the current debug flow.

Closes gh-4574
Ref gh-4550

Gruntfile.js
test/jquery.js

index c966ef99e4e59758aa5725d15fc0158991187bfe..562d286f62082e0f38db288e349bb34510ed4848 100644 (file)
@@ -158,14 +158,31 @@ module.exports = function( grunt ) {
 
                                        "test/jquery.js",
 
-                                       { pattern: "dist/jquery.*", included: false, served: true },
-                                       { pattern: "src/**", type: "module", included: false, served: true },
-                                       { pattern: "amd/**", included: false, served: true },
+                                       {
+                                               pattern: "dist/jquery.*",
+                                               included: false,
+                                               served: true,
+                                               nocache: true
+                                       },
+                                       {
+                                               pattern: "src/**",
+                                               type: "module",
+                                               included: false,
+                                               served: true,
+                                               nocache: true
+                                       },
+                                       {
+                                               pattern: "amd/**",
+                                               included: false,
+                                               served: true,
+                                               nocache: true
+                                       },
                                        { pattern: "node_modules/**", included: false, served: true },
                                        {
                                                pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
                                                included: false,
-                                               served: true
+                                               served: true,
+                                               nocache: true
                                        }
                                ],
                                reporters: [ "dots" ],
index be24453954a7e12145ca21f1dc59578c12aec02d..2d12a5ff305485e4f6058a43f1cc673543e40380 100644 (file)
@@ -2,29 +2,34 @@
 ( function() {
        /* global loadTests: false */
 
-       var dynamicImportSource,
+       var dynamicImportSource, config, src,
                FILEPATH = "/test/jquery.js",
                activeScript = [].slice.call( document.getElementsByTagName( "script" ), -1 )[ 0 ],
                parentUrl = activeScript && activeScript.src ?
                        activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" :
                        "../",
                QUnit = window.QUnit,
-               require = window.require,
+               require = window.require;
+
+       function getQUnitConfig() {
+               var config = Object.create( null );
 
                // Default to unminified jQuery for directly-opened iframes
-               config = QUnit ?
+               if ( !QUnit ) {
+                       config.dev = true;
+               } else {
 
                        // QUnit.config is populated from QUnit.urlParams but only at the beginning
                        // of the test run. We need to read both.
-                       {
-                               esmodules: !!( QUnit.config.esmodules || QUnit.urlParams.esmodules ),
-                               amd: !!( QUnit.config.amd || QUnit.urlParams.amd )
-                       } :
+                       QUnit.config.urlConfig.forEach( function( entry ) {
+                               config[ entry.id ] = QUnit.config[ entry.id ] != null ?
+                                       QUnit.config[ entry.id ] :
+                                       QUnit.urlParams[ entry.id ];
+                       } );
+               }
 
-                       { dev: true },
-               src = config.dev ?
-                       "dist/jquery.js" :
-                       "dist/jquery.min.js";
+               return config;
+       }
 
        // Define configuration parameters controlling how jQuery is loaded
        if ( QUnit ) {
                } );
        }
 
+       config = getQUnitConfig();
+
+       src = config.dev ?
+               "dist/jquery.js" :
+               "dist/jquery.min.js";
+
        // Honor ES modules 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 ( config.esmodules && QUnit ) {