aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2013-08-15 14:15:49 -0400
committerTimmy Willison <timmywillisn@gmail.com>2013-08-15 14:15:49 -0400
commit6318ae6ab90d4b450dfadf32ab95fe52ed6331cb (patch)
tree50b247fed8569e909e380b281e9145bd1458a39e /test
parent7627b8b6d9ef6e57dbd20a55b946bd1991c1223e (diff)
downloadjquery-6318ae6ab90d4b450dfadf32ab95fe52ed6331cb.tar.gz
jquery-6318ae6ab90d4b450dfadf32ab95fe52ed6331cb.zip
AMD-ify jQuery sourcegit s! Woo! Fixes #14113, #14163.
Diffstat (limited to 'test')
-rw-r--r--test/data/testinit.js11
-rw-r--r--test/data/testrunner.js4
-rw-r--r--test/index.html84
-rw-r--r--test/jquery.js82
-rw-r--r--test/unit/core.js24
-rw-r--r--test/unit/data.js16
-rw-r--r--test/unit/support.js15
7 files changed, 137 insertions, 99 deletions
diff --git a/test/data/testinit.js b/test/data/testinit.js
index 0351f0264..30136de36 100644
--- a/test/data/testinit.js
+++ b/test/data/testinit.js
@@ -1,6 +1,6 @@
/*jshint multistr:true, quotmark:false */
-var amdDefined, fireNative,
+var fireNative,
originaljQuery = this.jQuery || "jQuery",
original$ = this.$ || "$",
// see RFC 2606
@@ -14,15 +14,6 @@ this.jQuery = originaljQuery;
this.$ = original$;
/**
- * Set up a mock AMD define function for testing AMD registration.
- */
-function define( name, dependencies, callback ) {
- amdDefined = callback();
-}
-
-define.amd = {};
-
-/**
* Returns an array of elements with the given IDs
* @example q("main", "foo", "bar")
* @result [<div id="main">, <span id="foo">, <input id="bar">]
diff --git a/test/data/testrunner.js b/test/data/testrunner.js
index 93c285eb6..072de9bba 100644
--- a/test/data/testrunner.js
+++ b/test/data/testrunner.js
@@ -248,11 +248,11 @@ this.Globals = (function() {
}
};
- QUnit.config.urlConfig.push( {
+ QUnit.config.urlConfig.push({
id: "jqdata",
label: "Always check jQuery.data",
tooltip: "Trigger QUnit.expectJqData detection for all tests instead of just the ones that call it"
- } );
+ });
/**
* Ensures that tests have cleaned up properly after themselves. Should be passed as the
diff --git a/test/index.html b/test/index.html
index 0bacc19c3..778dc4dff 100644
--- a/test/index.html
+++ b/test/index.html
@@ -14,63 +14,33 @@
<script src="data/testinit.js"></script>
<script src="../bower_components/qunit/qunit/qunit.js"></script>
- <script>
- (function() {
- var src = "../dist/jquery.min.js";
-
- // Config parameter to use minified jQuery
- QUnit.config.urlConfig.push({
- id: "dev",
- label: "Load unminified",
- tooltip: "Load the development (unminified) jQuery file"
- });
- if ( QUnit.urlParams.dev ) {
- src = "../dist/jquery.js";
- }
-
- // Config parameter to force basic code paths
- QUnit.config.urlConfig.push({
- id: "basic",
- label: "Bypass optimizations",
- tooltip: "Force use of the most basic code by disabling native querySelectorAll; contains; compareDocumentPosition"
- });
- if ( QUnit.urlParams.basic ) {
- document.querySelectorAll = null;
- document.documentElement.contains = null;
- document.documentElement.compareDocumentPosition = null;
- }
-
- // Load jQuery
- document.write( "<script id='jquery-js' src='" + src + "'><\x2Fscript>" );
- })();
- </script>
- <script src="data/testrunner.js"></script>
-
- <script src="unit/core.js"></script>
- <script src="unit/callbacks.js"></script>
- <script src="unit/deferred.js"></script>
- <script src="unit/support.js"></script>
- <script src="unit/data.js"></script>
- <script src="unit/queue.js"></script>
- <script src="unit/attributes.js"></script>
- <script src="unit/event.js"></script>
- <script src="unit/selector.js"></script>
- <script src="unit/traversing.js"></script>
- <script src="unit/manipulation.js"></script>
- <script src="unit/wrap.js"></script>
- <script src="unit/css.js"></script>
- <script src="unit/serialize.js"></script>
- <script src="unit/ajax.js"></script>
- <script src="unit/effects.js"></script>
- <script src="unit/offset.js"></script>
- <script src="unit/dimensions.js"></script>
- <script src="unit/deprecated.js"></script>
- <script src="unit/exports.js"></script>
-
- <!-- Subproject tests must be last because they replace our test fixture -->
- <script>
- testSubproject( "Sizzle", "../bower_components/sizzle/test/", /^unit\/.*\.js$/ );
- </script>
+ <script src="../bower_components/requirejs/require.js"></script>
+ <script>loadTests = [
+ "data/testrunner.js",
+ "unit/core.js",
+ "unit/callbacks.js",
+ "unit/deferred.js",
+ "unit/support.js",
+ "unit/data.js",
+ "unit/queue.js",
+ "unit/attributes.js",
+ "unit/event.js",
+ "unit/selector.js",
+ "unit/traversing.js",
+ "unit/manipulation.js",
+ "unit/wrap.js",
+ "unit/css.js",
+ "unit/serialize.js",
+ "unit/ajax.js",
+ "unit/effects.js",
+ "unit/offset.js",
+ "unit/dimensions.js"
+ ];</script>
+ <!-- A script that includes jQuery min, dev, or AMD -->
+ <!-- Adds "basic" URL option, even to iframes -->
+ <!-- iframes will not load AMD as loading needs to be synchronous for some tests -->
+ <!-- Also loads the tests above synchronously with min or dev and async with AMD -->
+ <script src="jquery.js"></script>
<script>
// html5shiv, enabling HTML5 elements to be used with jQuery
diff --git a/test/jquery.js b/test/jquery.js
index 93d1095cd..faebaaed0 100644
--- a/test/jquery.js
+++ b/test/jquery.js
@@ -1,5 +1,77 @@
-// Use the right jQuery source in iframe tests
-document.write( "<script id='jquery-js' src='" +
- parent.document.getElementById("jquery-js").src.replace( /^(?![^\/?#]+:)/,
- parent.location.pathname.replace( /[^\/]$/, "$0/" ) ) +
-"'><\x2Fscript>" );
+// Use the right jQuery source on the test page (and iframes)
+(function() {
+ /* global loadTests: true, testSubproject: false */
+ /* jshint eqeqeq: false */
+
+ var i, len,
+ // Parent is the current window if not an iframe, which is fine
+ src = /^(.*)test\//.exec( parent.location.pathname )[1],
+ QUnit = QUnit || parent.QUnit,
+ require = require || parent.require;
+
+ // Config parameter to force basic code paths
+ QUnit.config.urlConfig.push({
+ id: "basic",
+ label: "Bypass optimizations",
+ tooltip: "Force use of the most basic code by disabling native querySelectorAll; contains; compareDocumentPosition"
+ });
+ if ( QUnit.urlParams.basic ) {
+ document.querySelectorAll = null;
+ document.documentElement.contains = null;
+ document.documentElement.compareDocumentPosition = null;
+ }
+
+ // iFrames won't load AMD (the iframe tests synchronously expect jQuery to be there)
+ QUnit.config.urlConfig.push({
+ id: "amd",
+ label: "Load with AMD",
+ tooltip: "Load the AMD jQuery file (and its dependencies)"
+ });
+ if ( QUnit.urlParams.amd && parent == window ) {
+ require.config({ baseUrl: src });
+ src = "src/jquery";
+ // Include tests if specified
+ if ( typeof loadTests !== "undefined" ) {
+ QUnit.config.autostart = false;
+ require( [ src ], function() {
+ // Ensure load order (to preserve test numbers)
+ (function loadDep() {
+ var dep = loadTests.shift();
+ if ( dep ) {
+ require( [ dep ], loadDep );
+ } else {
+ // Subproject tests must be last because they replace our test fixture
+ testSubproject( "Sizzle", "../bower_components/sizzle/test/", /^unit\/.*\.js$/ );
+
+ QUnit.start();
+ }
+ })();
+ });
+ } else {
+ require( [ src ] );
+ }
+ return;
+ }
+
+ // Config parameter to use minified jQuery
+ QUnit.config.urlConfig.push({
+ id: "dev",
+ label: "Load unminified",
+ tooltip: "Load the development (unminified) jQuery file"
+ });
+ if ( QUnit.urlParams.dev ) {
+ src += "dist/jquery.js";
+ } else {
+ src += "dist/jquery.min.js";
+ }
+
+ // Load jQuery
+ document.write( "<script id='jquery-js' src='" + src + "'><\x2Fscript>" );
+
+ // Load tests synchronously if available
+ if ( typeof loadTests !== "undefined" ) {
+ for ( i = 0, len = loadTests.length; i < len; i++ ) {
+ document.write( "<script src='" + loadTests.shift() + "'><\x2Fscript>" );
+ }
+ }
+})();
diff --git a/test/unit/core.js b/test/unit/core.js
index 5fba3cf28..a849591dd 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -17,18 +17,6 @@ test("Basic requirements", function() {
ok( $, "$" );
});
-testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
- expect( 3 );
- ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
- deepEqual( errors, [], "No errors" );
- ok( $(), "jQuery executes" );
-});
-
-testIframeWithCallback( "document ready when jQuery loaded asynchronously (#13655)", "core/dynamic_ready.html", function( ready ) {
- expect( 1 );
- equal( true, ready, "document ready correctly fired when jQuery is loaded after DOMContentLoaded" );
-});
-
test("jQuery()", function() {
var elem, i,
@@ -1385,3 +1373,15 @@ test("jQuery.camelCase()", function() {
equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
});
});
+
+testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) {
+ expect( 3 );
+ ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) );
+ deepEqual( errors, [], "No errors" );
+ ok( $(), "jQuery executes" );
+});
+
+testIframeWithCallback( "document ready when jQuery loaded asynchronously (#13655)", "core/dynamic_ready.html", function( ready ) {
+ expect( 1 );
+ equal( true, ready, "document ready correctly fired when jQuery is loaded after DOMContentLoaded" );
+});
diff --git a/test/unit/data.js b/test/unit/data.js
index ad43d34cd..eebe50e84 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -62,7 +62,7 @@ test( "jQuery.hasData no side effects", function() {
);
});
-function dataTests (elem) {
+function dataTests( elem ) {
var dataObj, internalDataObj;
equal( jQuery.data(elem, "foo"), undefined, "No data exists initially" );
@@ -129,30 +129,30 @@ function dataTests (elem) {
test("jQuery.data(div)", 25, function() {
var div = document.createElement("div");
- dataTests(div);
+ dataTests( div );
// We stored one key in the private data
// assert that nothing else was put in there, and that that
// one stayed there.
- QUnit.expectJqData(div, "foo");
+ QUnit.expectJqData( div, "foo" );
});
test("jQuery.data({})", 25, function() {
- dataTests({});
+ dataTests( {} );
});
test("jQuery.data(window)", 25, function() {
// remove bound handlers from window object to stop potential false positives caused by fix for #5280 in
// transports/xhr.js
- jQuery(window).off("unload");
+ jQuery( window ).off( "unload" );
- dataTests(window);
+ dataTests( window );
});
test("jQuery.data(document)", 25, function() {
- dataTests(document);
+ dataTests( document );
- QUnit.expectJqData(document, "foo");
+ QUnit.expectJqData( document, "foo" );
});
test("jQuery.data(<embed>)", 25, function() {
diff --git a/test/unit/support.js b/test/unit/support.js
index 51d0abd6d..3edc92b48 100644
--- a/test/unit/support.js
+++ b/test/unit/support.js
@@ -3,13 +3,18 @@ module("support", { teardown: moduleTeardown });
if ( jQuery.css ) {
testIframeWithCallback( "body background is not lost if set prior to loading jQuery (#9239)", "support/bodyBackground.html", function( color, support ) {
expect( 2 );
- var okValue = {
- "#000000": true,
- "rgb(0, 0, 0)": true
- };
+ var okValue = {
+ "#000000": true,
+ "rgb(0, 0, 0)": true
+ };
ok( okValue[ color ], "color was not reset (" + color + ")" );
- deepEqual( jQuery.extend( {}, support ), jQuery.support, "Same support properties" );
+ stop();
+ // Run doc ready tests as well
+ jQuery(function() {
+ deepEqual( jQuery.extend( {}, support ), jQuery.support, "Same support properties" );
+ start();
+ });
});
}