aboutsummaryrefslogtreecommitdiffstats
path: root/test/data/testinit.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/data/testinit.js')
-rw-r--r--test/data/testinit.js37
1 files changed, 25 insertions, 12 deletions
diff --git a/test/data/testinit.js b/test/data/testinit.js
index 1aa9a65da..d6c0236e6 100644
--- a/test/data/testinit.js
+++ b/test/data/testinit.js
@@ -1,6 +1,11 @@
/* eslint no-multi-str: "off" */
-var baseURL = "",
+// 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/",
supportjQuery = this.jQuery,
// see RFC 2606
@@ -148,11 +153,13 @@ window.fireNative = document.createEvent ?
/**
* Add random number to url to stop caching
*
- * @example url("data/test.html")
- * @result "data/test.html?10538358428943"
+ * Also prefixes with baseURL automatically.
*
- * @example url("data/test.php?foo=bar")
- * @result "data/test.php?foo=bar&10538358345554"
+ * @example url("index.html")
+ * @result "data/index.html?10538358428943"
+ *
+ * @example url("mock.php?foo=bar")
+ * @result "data/mock.php?foo=bar&10538358345554"
*/
function url( value ) {
return baseURL + value + ( /\?/.test( value ) ? "&" : "?" ) +
@@ -239,7 +246,7 @@ this.testIframe = function( title, fileName, func, wrapper ) {
var done = assert.async(),
$iframe = supportjQuery( "<iframe/>" )
.css( { position: "absolute", top: "0", left: "-600px", width: "500px" } )
- .attr( { id: "qunit-fixture-iframe", src: url( "./data/" + fileName ) } );
+ .attr( { id: "qunit-fixture-iframe", src: url( fileName ) } );
// Test iframes are expected to invoke this via startIframeTest (cf. iframeTest.js)
window.iframeCallback = function() {
@@ -264,14 +271,20 @@ this.testIframe = function( title, fileName, func, wrapper ) {
};
this.iframeCallback = undefined;
-// Tests are always loaded async
-QUnit.config.autostart = false;
-this.loadTests = function() {
+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)
+ QUnit.config.autostart = false;
+}
- // Leverage QUnit URL parsing to detect testSwarm environment and "basic" testing mode
- QUnit.isSwarm = ( QUnit.urlParams.swarmURL + "" ).indexOf( "http" ) === 0;
- QUnit.basicTests = ( QUnit.urlParams.module + "" ) === "basic";
+// Leverage QUnit URL parsing to detect testSwarm environment and "basic" testing mode
+QUnit.isSwarm = ( QUnit.urlParams.swarmURL + "" ).indexOf( "http" ) === 0;
+QUnit.basicTests = ( QUnit.urlParams.module + "" ) === "basic";
+this.loadTests = function() {
// Get testSubproject from testrunner first
require( [ "data/testrunner.js" ], function() {
var i = 0,