From 004c1fc5bb40ae8dfec18d6719534abad636b7e8 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Thu, 29 Aug 2013 16:18:17 -0400 Subject: Pass all tests (and load Sizzle fixture correctly) when loading with AMD --- test/.jshintrc | 1 + test/data/testrunner.js | 40 +++++++++++++++++-------- test/index.html | 74 ++++++++++++++++++++++++++------------------- test/jquery.js | 41 +++++++++---------------- test/unit/event.js | 79 ------------------------------------------------- test/unit/ready.js | 73 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 159 insertions(+), 149 deletions(-) create mode 100644 test/unit/ready.js (limited to 'test') diff --git a/test/.jshintrc b/test/.jshintrc index 75c50eeeb..f974f8e4b 100644 --- a/test/.jshintrc +++ b/test/.jshintrc @@ -21,6 +21,7 @@ "wsh": true, "globals": { + "require": false, "DOMParser": false, "QUnit": false, "ok": false, diff --git a/test/data/testrunner.js b/test/data/testrunner.js index 072de9bba..80e7bb6c9 100644 --- a/test/data/testrunner.js +++ b/test/data/testrunner.js @@ -16,7 +16,13 @@ var Sizzle = Sizzle || jQuery.find, qunitModule = QUnit.module, qunitTest = QUnit.test; -this.testSubproject = function( label, url, risTests ) { +/** + * 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 + */ +this.testSubproject = function( label, url, risTests, complete ) { var sub, fixture, fixtureHTML, fixtureReplaced = false; @@ -65,7 +71,8 @@ this.testSubproject = function( label, url, risTests ) { throw new Error( "Could not load: " + url + " (" + status + ")" ); }, success: function( data, status, jqXHR ) { - var page = originaljQuery.parseHTML( + var sources = [], + page = originaljQuery.parseHTML( // replace html/head with dummy elements so they are represented in the DOM ( data || "" ).replace( /<\/?((!DOCTYPE|html|head)\b.*?)>/gi, "[$1]" ), document, @@ -78,18 +85,23 @@ this.testSubproject = function( label, url, risTests ) { page = originaljQuery( page ); // Include subproject tests - page.filter("script[src]").add( page.find("script[src]") ).each(function() { - var src = originaljQuery( this ).attr("src"), - html = ""; + page.filter("script[src]").add( page.find("script[src]") ).map(function() { + var src = originaljQuery( this ).attr("src"); if ( risTests.test( src ) ) { - if ( originaljQuery.isReady ) { - originaljQuery("head").first().append( html ); - } else { - document.write( html ); - } + sources.push( src ); } }); + // Ensure load order + (function loadDep() { + var dep = sources.shift(); + if ( dep ) { + require( [ url + dep ], loadDep ); + } else if ( complete ) { + complete(); + } + })(); + // Get the fixture, including content outside of #qunit-fixture fixture = page.find("[id='qunit-fixture']"); fixtureHTML = fixture.html(); @@ -156,6 +168,11 @@ this.Globals = (function() { }; })(); + +/** + * QUnit hooks + */ + // Sandbox start for great justice (function() { var oldStart = window.start; @@ -164,9 +181,6 @@ this.Globals = (function() { }; })(); -/** - * QUnit hooks - */ (function() { // Store the old counts so that we only assert on tests that have actually leaked, // instead of asserting every time a test has leaked sometime in the past diff --git a/test/index.html b/test/index.html index 013548558..3636df471 100644 --- a/test/index.html +++ b/test/index.html @@ -11,44 +11,58 @@ - - - + + + - +