Commit 14e1501b authored by Richard Gibson's avatar Richard Gibson

Fix testing of no-ajax custom builds

parent 03a07628
This diff is collapsed.
/*jshint multistr:true */ /*jshint multistr:true */
var jQuery = this.jQuery || "jQuery", // For testing .noConflict() var originaljQuery = this.jQuery || "jQuery",
$ = this.$ || "$", original$ = this.$ || "$",
originaljQuery = jQuery,
original$ = $,
hasPHP = true, hasPHP = true,
// Disable Ajax tests to reduce network strain // Disable Ajax tests to reduce network strain
// Re-enabled (at least the variable should be declared) // Re-enabled (at least the variable should be declared)
isLocal = window.location.protocol === "file:", isLocal = window.location.protocol === "file:",
amdDefined; amdDefined;
// For testing .noConflict()
this.jQuery = originaljQuery;
this.$ = original$;
/** /**
* Set up a mock AMD define function for testing AMD registration. * Set up a mock AMD define function for testing AMD registration.
*/ */
......
...@@ -22,6 +22,7 @@ function testSubproject( label, url, risTests ) { ...@@ -22,6 +22,7 @@ function testSubproject( label, url, risTests ) {
module( label ); module( label );
// Duckpunch QUnit // Duckpunch QUnit
// TODO restore parent fixture on teardown to support reordering
module = QUnit.module = function( name ) { module = QUnit.module = function( name ) {
var args = arguments; var args = arguments;
...@@ -41,7 +42,7 @@ function testSubproject( label, url, risTests ) { ...@@ -41,7 +42,7 @@ function testSubproject( label, url, risTests ) {
// Find test function and wrap to require subproject fixture // Find test function and wrap to require subproject fixture
for ( ; i >= 0; i-- ) { for ( ; i >= 0; i-- ) {
if ( jQuery.isFunction( args[i] ) ) { if ( originaljQuery.isFunction( args[i] ) ) {
args[i] = requireFixture( args[i] ); args[i] = requireFixture( args[i] );
break; break;
} }
...@@ -52,14 +53,14 @@ function testSubproject( label, url, risTests ) { ...@@ -52,14 +53,14 @@ function testSubproject( label, url, risTests ) {
// Load tests and fixture from subproject // Load tests and fixture from subproject
// Test order matters, so we must be synchronous and throw an error on load failure // Test order matters, so we must be synchronous and throw an error on load failure
jQuery.ajax( url, { originaljQuery.ajax( url, {
async: false, async: false,
dataType: "html", dataType: "html",
error: function( jqXHR, status ) { error: function( jqXHR, status ) {
throw new Error( "Could not load: " + url + " (" + status + ")" ); throw new Error( "Could not load: " + url + " (" + status + ")" );
}, },
success: function( data, status, jqXHR ) { success: function( data, status, jqXHR ) {
var page = jQuery.parseHTML( var page = originaljQuery.parseHTML(
// replace html/head with dummy elements so they are represented in the DOM // replace html/head with dummy elements so they are represented in the DOM
( data || "" ).replace( /<\/?((!DOCTYPE|html|head)\b.*?)>/gi, "[$1]" ), ( data || "" ).replace( /<\/?((!DOCTYPE|html|head)\b.*?)>/gi, "[$1]" ),
document, document,
...@@ -69,15 +70,15 @@ function testSubproject( label, url, risTests ) { ...@@ -69,15 +70,15 @@ function testSubproject( label, url, risTests ) {
if ( !page || !page.length ) { if ( !page || !page.length ) {
this.error( jqXHR, "no data" ); this.error( jqXHR, "no data" );
} }
page = jQuery( page ); page = originaljQuery( page );
// Include subproject tests // Include subproject tests
page.filter("script[src]").add( page.find("script[src]") ).each(function() { page.filter("script[src]").add( page.find("script[src]") ).each(function() {
var src = jQuery( this ).attr("src"), var src = originaljQuery( this ).attr("src"),
html = "<script src='" + url + src + "'></script>"; html = "<script src='" + url + src + "'></script>";
if ( risTests.test( src ) ) { if ( risTests.test( src ) ) {
if ( jQuery.isReady ) { if ( originaljQuery.isReady ) {
jQuery("head").first().append( html ); originaljQuery("head").first().append( html );
} else { } else {
document.write( html ); document.write( html );
} }
...@@ -105,7 +106,7 @@ function testSubproject( label, url, risTests ) { ...@@ -105,7 +106,7 @@ function testSubproject( label, url, risTests ) {
} }
// Replace the current fixture, including content outside of #qunit-fixture // Replace the current fixture, including content outside of #qunit-fixture
var oldFixture = jQuery("#qunit-fixture"); var oldFixture = originaljQuery("#qunit-fixture");
while ( oldFixture.length && !oldFixture.prevAll("[id^='qunit-']").length ) { while ( oldFixture.length && !oldFixture.prevAll("[id^='qunit-']").length ) {
oldFixture = oldFixture.parent(); oldFixture = oldFixture.parent();
} }
...@@ -115,7 +116,7 @@ function testSubproject( label, url, risTests ) { ...@@ -115,7 +116,7 @@ function testSubproject( label, url, risTests ) {
// WARNING: UNDOCUMENTED INTERFACE // WARNING: UNDOCUMENTED INTERFACE
QUnit.config.fixture = fixtureHTML; QUnit.config.fixture = fixtureHTML;
QUnit.reset(); QUnit.reset();
if ( jQuery("#qunit-fixture").html() !== fixtureHTML ) { if ( originaljQuery("#qunit-fixture").html() !== fixtureHTML ) {
ok( false, "Copied subproject fixture" ); ok( false, "Copied subproject fixture" );
return; return;
} }
...@@ -285,7 +286,11 @@ function testSubproject( label, url, risTests ) { ...@@ -285,7 +286,11 @@ function testSubproject( label, url, risTests ) {
// Reset internal jQuery state // Reset internal jQuery state
jQuery.event.global = {}; jQuery.event.global = {};
jQuery.ajaxSettings = jQuery.extend( {}, ajaxSettings ); if ( ajaxSettings ) {
jQuery.ajaxSettings = jQuery.extend( {}, ajaxSettings );
} else {
delete jQuery.ajaxSettings;
}
// Let QUnit reset the fixture // Let QUnit reset the fixture
reset.apply( this, arguments ); reset.apply( this, arguments );
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
<link rel="Stylesheet" media="screen" href="data/testsuite.css" /> <link rel="Stylesheet" media="screen" href="data/testsuite.css" />
<!-- Includes --> <!-- Includes -->
<!-- Allows us to fetch submodule tests when using a no-ajax build -->
<script src="data/jquery-1.8.2.ajax_xhr.min.js"></script>
<script src="data/testinit.js"></script> <script src="data/testinit.js"></script>
<script src="qunit/qunit/qunit.js"></script> <script src="qunit/qunit/qunit.js"></script>
......
...@@ -257,6 +257,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo ...@@ -257,6 +257,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
for ( var i in expected ) { for ( var i in expected ) {
if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) { if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) {
equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]); equal( jQuery.support[i], expected[i], "jQuery.support['" + i + "']: " + jQuery.support[i] + ", expected['" + i + "']: " + expected[i]);
} else {
ok( true, "no ajax; skipping jQuery.support['" + i + "']" );
} }
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment