"external/requirejs/require.js",
"test/data/testinit.js",
- "dist/jquery.min.js",
+ "test/jquery.js",
// Replacement for testinit.js#loadTests()
"test/data/testrunner.js",
"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,
/* 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
};
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;
}
this.loadTests = function() {
+ // Directly load tests that need synchronous evaluation
+ if ( !QUnit.urlParams.amd || document.readyState === "loading" ) {
+ document.write( "<script src='" + parentUrl + "test/unit/ready.js'><\x2Fscript>" );
+ } else {
+ QUnit.module( "ready", function() {
+ QUnit.test( "jQuery ready", function( assert ) {
+ assert.ok( false, "Test should be initialized before DOM ready" );
+ } );
+ } );
+ }
+
// Get testSubproject from testrunner first
- require( [ "data/testrunner.js" ], function() {
+ require( [ parentUrl + "test/data/testrunner.js" ], function() {
var i = 0,
tests = [
// A special module with basic tests, meant for
if ( dep ) {
if ( !QUnit.basicTests || i === 1 ) {
- require( [ dep ], loadDep );
+ require( [ parentUrl + "test/" + dep ], loadDep );
// Support: Android 2.3 only
// When running basic tests, replace other modules with dummies to avoid overloading
( function() {
/* global loadTests: false */
- var pathname = window.location.pathname,
- path = pathname.slice( 0, pathname.lastIndexOf( "test" ) ),
+ var 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 || parent.QUnit,
require = window.require || parent.require,
// Define configuration parameters controlling how jQuery is loaded
if ( QUnit ) {
- QUnit.config.urlConfig.push( {
- id: "amd",
- label: "Load with AMD",
- tooltip: "Load the AMD jQuery file (and its dependencies)"
- } );
+
+ // AMD loading is asynchronous and incompatible with synchronous test loading in Karma
+ if ( !window.__karma__ ) {
+ QUnit.config.urlConfig.push( {
+ id: "amd",
+ label: "Load with AMD",
+ tooltip: "Load the AMD jQuery file (and its dependencies)"
+ } );
+ }
+
QUnit.config.urlConfig.push( {
id: "dev",
label: "Load unminified",
// This doesn't apply to iframes because they synchronously expect jQuery to be there.
if ( urlParams.amd && window.QUnit ) {
require.config( {
- baseUrl: path
+ baseUrl: parentUrl
} );
src = "src/jquery";
// Otherwise, load synchronously
} else {
- document.write( "<script id='jquery-js' src='" + path + src + "'><\x2Fscript>" );
-
- // Synchronous-only tests (other tests are loaded from the test page)
- if ( typeof loadTests !== "undefined" ) {
- document.write( "<script src='" + path + "test/unit/ready.js'><\x2Fscript>" );
- }
+ document.write( "<script id='jquery-js' src='" + parentUrl + src + "'><\x2Fscript>" );
}
} )();
};
} );
- ajaxTest( "jQuery.ajax() - hash", 4, function( assert ) {
+ ajaxTest( "jQuery.ajax() - URL fragment component preservation", 4, function( assert ) {
return [
{
url: baseURL + "name.html#foo",
beforeSend: function( xhr, settings ) {
- assert.equal( settings.url, baseURL + "name.html#foo", "Make sure that the URL has its hash." );
+ assert.equal( settings.url, baseURL + "name.html#foo",
+ "hash preserved for request with no query component." );
return false;
},
error: true
{
url: baseURL + "name.html?abc#foo",
beforeSend: function( xhr, settings ) {
- assert.equal( settings.url, baseURL + "name.html?abc#foo", "Make sure that the URL has its hash." );
+ assert.equal( settings.url, baseURL + "name.html?abc#foo",
+ "hash preserved for request with query component." );
return false;
},
error: true
"test": 123
},
beforeSend: function( xhr, settings ) {
- assert.equal( settings.url, baseURL + "name.html?abc&test=123#foo", "Make sure that the URL has its hash." );
+ assert.equal( settings.url, baseURL + "name.html?abc&test=123#foo",
+ "hash preserved for request with query component and data." );
return false;
},
error: true
},
cache: false,
beforeSend: function( xhr, settings ) {
- // Remove the random number, but ensure the cache-buster param is there
- var url = settings.url.replace( /\d+/, "" );
- assert.equal( url, baseURL + "name.html?abc&devo=hat&_=#brownies", "Make sure that the URL has its hash." );
+ // Clear the cache-buster param value
+ var url = settings.url.replace( /_=[^&#]+/, "_=" );
+ assert.equal( url, baseURL + "name.html?abc&devo=hat&_=#brownies",
+ "hash preserved for cache-busting request with query component and data." );
return false;
},
error: true
setup: function() {
Globals.register( "testBar" );
},
- url: window.location.href.replace( /[^\/]*$/, "" ) + baseURL + "mock.php?action=testbar",
+ url: url( "mock.php?action=testbar" ),
dataType: "script",
success: function() {
assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
setup: function() {
Globals.register( "testBar" );
},
- url: window.location.href.replace( /[^\/]*$/, "" ) + baseURL + "mock.php?action=testbar",
+ url: url( "mock.php?action=testbar" ),
type: "POST",
dataType: "script",
success: function( data, status ) {
setup: function() {
Globals.register( "testBar" );
},
- url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + baseURL + "mock.php?action=testbar",
+ url: url( "mock.php?action=testbar" ),
dataType: "script",
success: function() {
assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
} );
QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function( assert ) {
- jQuery.getJSON( window.location.href.replace( /[^\/]*$/, "" ) + url( "mock.php?action=json" ), function( json ) {
+ var absoluteUrl = url( "mock.php?action=json" );
+
+ // Make a relative URL absolute relative to the document location
+ if ( !/^[a-z][a-z0-9+.-]*:/i.test( absoluteUrl ) ) {
+
+ // An absolute path replaces everything after the host
+ if ( absoluteUrl.charAt( 0 ) === "/" ) {
+ absoluteUrl = window.location.href.replace( /(:\/*[^/]*).*$/, "$1" ) + absoluteUrl;
+
+ // A relative path replaces the last slash-separated path segment
+ } else {
+ absoluteUrl = window.location.href.replace( /[^/]*$/, "" ) + absoluteUrl;
+ }
+ }
+
+ jQuery.getJSON( absoluteUrl, function( json ) {
assert.strictEqual( json.data.lang, "en", "Check JSON: lang" );
assert.strictEqual( json.data.length, 25, "Check JSON: length" );
QUnit.start();