diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/data/testinit.js | 67 | ||||
-rw-r--r-- | test/data/testrunner.js | 136 |
2 files changed, 27 insertions, 176 deletions
diff --git a/test/data/testinit.js b/test/data/testinit.js index af19dc69d..06f33d19b 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -131,8 +131,8 @@ fireNative = document.createEvent ? * @result "data/test.php?foo=bar&10538358345554" */ function url( value ) { - return baseURL + value + (/\?/.test(value) ? "&" : "?") + - new Date().getTime() + "" + parseInt(Math.random() * 100000, 10); + return baseURL + value + (/\?/.test( value ) ? "&" : "?") + + new Date().getTime() + "" + parseInt( Math.random() * 100000, 10 ); } // Ajax testing helper @@ -203,19 +203,17 @@ this.ajaxTest = function( title, expect, options ) { this.testIframe = function( fileName, name, fn ) { - - test(name, function() { - // pause execution for now - stop(); + asyncTest(name, function() { // load fixture in iframe var iframe = loadFixture(), win = iframe.contentWindow, - interval = setInterval( function() { + interval = setInterval(function() { if ( win && win.jQuery && win.jQuery.isReady ) { clearInterval( interval ); - // continue + start(); + // call actual tests passing the correct jQuery instance to use fn.call( this, win.jQuery, win, win.document ); document.body.removeChild( iframe ); @@ -225,9 +223,10 @@ this.testIframe = function( fileName, name, fn ) { }); function loadFixture() { - var src = url("./data/" + fileName + ".html"), - iframe = jQuery("<iframe />").appendTo("body")[0]; + var src = url( "./data/" + fileName + ".html" ), + iframe = jQuery( "<iframe />" ).appendTo( "body" )[ 0 ]; iframe.style.cssText = "width: 500px; height: 500px; position: absolute; top: -600px; left: -600px; visibility: hidden;"; + iframe.contentWindow.location = src; return iframe; } @@ -265,11 +264,12 @@ QUnit.config.autostart = false; this.loadTests = function() { var loadSwarm, url = window.location.search; - url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + "swarmURL=".length ) ); - loadSwarm = url && url.indexOf("http") === 0; + + url = decodeURIComponent( url.slice( url.indexOf( "swarmURL=" ) + "swarmURL=".length ) ); + loadSwarm = url && url.indexOf( "http" ) === 0; // Get testSubproject from testrunner first - require([ "data/testrunner.js" ], function( testSubproject ) { + require([ "data/testrunner.js" ], function() { var tests = [ "unit/core.js", "unit/callbacks.js", @@ -294,39 +294,26 @@ this.loadTests = function() { // Ensure load order (to preserve test numbers) (function loadDep() { var dep = tests.shift(); + if ( dep ) { require( [ dep ], loadDep ); - } else { - - // Subproject tests must be last because they replace our test fixture - testSubproject( "Sizzle", "../src/sizzle/test/", /^unit\/.*\.js$/, function() { - // Call load to build module filter select element - QUnit.load(); - - /** - * Run in noConflict mode - */ - jQuery.noConflict(); - - // Expose Sizzle for Sizzle's selector tests - // We remove Sizzle's globalization in jQuery - window.Sizzle = window.Sizzle || jQuery.find; + } else { + QUnit.load(); - // For checking globals pollution despite auto-created globals in various environments - supportjQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) { - window[ name ] = window[ name ]; - }); + /** + * Run in noConflict mode + */ + jQuery.noConflict(); - // Load the TestSwarm listener if swarmURL is in the address. - if ( loadSwarm ) { - require( [ "http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() ], function() { - QUnit.start(); - }); - } else { + // Load the TestSwarm listener if swarmURL is in the address. + if ( loadSwarm ) { + require( [ "http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() ], function() { QUnit.start(); - } - }); + }); + } else { + QUnit.start(); + } } })(); }); diff --git a/test/data/testrunner.js b/test/data/testrunner.js index aea91624e..0f741fa9d 100644 --- a/test/data/testrunner.js +++ b/test/data/testrunner.js @@ -186,8 +186,6 @@ reset = function() { // Cleanup globals Globals.cleanup(); - - jQuery("#qunit-fixture")[0].innerHTML = QUnit.config.fixture; }; QUnit.testDone(reset); @@ -214,138 +212,4 @@ window.Globals = (function() { }; })(); -/** - * Test a subproject with its own fixture - * @param {String} label Project name - * @param {String} url Test folder location - * @param {RegExp} risTests To filter script sources - */ -function testSubproject( label, subProjectURL, risTests, complete ) { - var sub, fixture, fixtureHTML, - fixtureReplaced = false; - - // Don't let subproject tests jump the gun - QUnit.config.reorder = false; - - // Create module - module( label ); - - // Duckpunch QUnit - // TODO restore parent fixture on teardown to support reordering - module = QUnit.module = function( name ) { - var args = arguments; - - // Remember subproject-scoped module name - sub = name; - - // Override - args[0] = label; - return qunitModule.apply( this, args ); - }; - test = function( name ) { - var args = arguments, - i = args.length - 1; - - // Prepend subproject-scoped module name to test name - args[0] = sub + ": " + name; - - // Find test function and wrap to require subproject fixture - for ( ; i >= 0; i-- ) { - if ( supportjQuery.isFunction( args[i] ) ) { - args[i] = requireFixture( args[i] ); - break; - } - } - - return qunitTest.apply( this, args ); - }; - - // Load tests and fixture from subproject - // Test order matters, so we must be synchronous and throw an error on load failure - supportjQuery.ajax( subProjectURL, { - async: false, - dataType: "html", - error: function( jqXHR, status ) { - throw new Error( "Could not load: " + subProjectURL + " (" + status + ")" ); - }, - success: function( data, status, jqXHR ) { - var sources = [], - page = supportjQuery.parseHTML( - // replace html/head with dummy elements so they are represented in the DOM - ( data || "" ).replace( /<\/?((!DOCTYPE|html|head)\b.*?)>/gi, "[$1]" ), - document, - true - ); - - if ( !page || !page.length ) { - this.error( jqXHR, "no data" ); - } - page = supportjQuery( page ); - - // Include subproject tests - page.filter("script[src]").add( page.find("script[src]") ).map(function() { - var src = supportjQuery( this ).attr("src"); - if ( risTests.test( src ) ) { - sources.push( src ); - } - }); - - // Ensure load order - (function loadDep() { - var dep = sources.shift(); - if ( dep ) { - require( [ subProjectURL + dep ], loadDep ); - } else if ( complete ) { - complete(); - } - })(); - - // Get the fixture, including content outside of #qunit-fixture - fixture = page.find("[id='qunit-fixture']"); - fixtureHTML = fixture.html(); - fixture.empty(); - while ( fixture.length && !fixture.prevAll("[id='qunit']").length ) { - fixture = fixture.parent(); - } - fixture = fixture.add( fixture.nextAll() ); - } - }); - - function requireFixture( fn ) { - return function() { - if ( !fixtureReplaced ) { - // Make sure that we retrieved a fixture for the subproject - if ( !fixture.length ) { - ok( false, "Found subproject fixture" ); - return; - } - - // Update helper function behavior - baseURL = subProjectURL; - - // Replace the current fixture, including content outside of #qunit-fixture - var oldFixture = supportjQuery("#qunit-fixture"); - while ( oldFixture.length && !oldFixture.prevAll("[id='qunit']").length ) { - oldFixture = oldFixture.parent(); - } - oldFixture.nextAll().remove(); - oldFixture.replaceWith( fixture ); - - // WARNING: UNDOCUMENTED INTERFACE - QUnit.config.fixture = fixtureHTML; - reset(); - if ( supportjQuery("#qunit-fixture").html() !== fixtureHTML ) { - ok( false, "Copied subproject fixture" ); - return; - } - - fixtureReplaced = true; - } - fn.apply( this, arguments ); - }; - } -} - -return testSubproject; - }); |