From dfa92ccead70d7dd5735a36c6d0dd1af680271cd Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Fri, 7 Sep 2018 10:14:01 -0400 Subject: [PATCH] Tests: Allow Karma to load unminfied source Closes gh-4128 --- Gruntfile.js | 8 ++++---- test/data/testinit.js | 42 ++++++++++++++++++++++++++++-------------- test/jquery.js | 31 +++++++++++++++++-------------- test/unit/ajax.js | 41 ++++++++++++++++++++++++++++++----------- 4 files changed, 79 insertions(+), 43 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index ed2bd7753..b46b7457f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -177,7 +177,7 @@ module.exports = function( grunt ) { "external/requirejs/require.js", "test/data/testinit.js", - "dist/jquery.min.js", + "test/jquery.js", // Replacement for testinit.js#loadTests() "test/data/testrunner.js", @@ -205,9 +205,9 @@ module.exports = function( grunt ) { "test/unit/tween.js", "test/unit/ready.js", - { pattern: "dist/jquery.js", included: false, served: true }, - { pattern: "dist/*.map", included: false, served: true }, - { pattern: "external/qunit/qunit.css", included: false, served: true }, + { pattern: "dist/jquery.*", included: false, served: true }, + { pattern: "src/**", included: false, served: true }, + { pattern: "external/**", included: false, served: true }, { pattern: "test/**/*.@(js|css|jpg|html|xml|svg)", included: false, diff --git a/test/data/testinit.js b/test/data/testinit.js index a91e59b6a..a87ebf206 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -1,11 +1,17 @@ /* eslint no-multi-str: "off" */ -// baseURL is intentionally set to "data/" instead of "". -// This is not just for convenience (since most files are in data/) -// but also to ensure that urls without prefix fail. -// Otherwise it's easy to write tests that pass on test/index.html -// but fail in Karma runner (where the baseURL is different). -var baseURL = "data/", +var FILEPATH = "/test/data/testinit.js", + activeScript = [].slice.call( document.getElementsByTagName( "script" ), -1 )[ 0 ], + parentUrl = activeScript && activeScript.src ? + activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" : + "../", + + // baseURL is intentionally set to "data/" instead of "". + // This is not just for convenience (since most files are in data/) + // but also to ensure that urls without prefix fail. + // Otherwise it's easy to write tests that pass on test/index.html + // but fail in Karma runner (where the baseURL is different). + baseURL = parentUrl + "test/data/", supportjQuery = this.jQuery, // see RFC 2606 @@ -271,12 +277,9 @@ this.testIframe = function( title, fileName, func, wrapper ) { }; this.iframeCallback = undefined; -if ( window.__karma__ ) { - // In Karma, files are served from /base - baseURL = "base/test/data/"; -} else { - // Tests are always loaded async - // except when running tests in Karma (See Gruntfile) +// Tests are always loaded async +// except when running tests in Karma (See Gruntfile) +if ( !window.__karma__ ) { QUnit.config.autostart = false; } @@ -295,8 +298,19 @@ moduleTypeSupported(); this.loadTests = function() { + // Directly load tests that need synchronous evaluation + if ( !QUnit.urlParams.amd || document.readyState === "loading" ) { + document.write( "