From dfa92ccead70d7dd5735a36c6d0dd1af680271cd Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Fri, 7 Sep 2018 10:14:01 -0400 Subject: Tests: Allow Karma to load unminfied source Closes gh-4128 --- test/data/testinit.js | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'test/data') 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( "