From 57652eecd96e47f39725671ffce45bfa01493380 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Tue, 9 Dec 2014 15:39:24 -0500 Subject: [PATCH] Build: fix tests in AMD mode --- build/tasks/build.js | 13 +++++-------- src/.jshintrc | 5 +++-- src/exports/global.js | 8 +------- src/jquery.js | 5 ++--- src/outro.js | 1 + test/data/testinit.js | 4 +++- test/unit/core.js | 29 ++++++++++++++++------------- 7 files changed, 31 insertions(+), 34 deletions(-) diff --git a/build/tasks/build.js b/build/tasks/build.js index 199f78120..3c457d0bf 100644 --- a/build/tasks/build.js +++ b/build/tasks/build.js @@ -26,7 +26,7 @@ module.exports = function( grunt ) { skipSemiColonInsertion: true, wrap: { startFile: "src/intro.js", - endFile: "src/outro.js" + endFile: [ "src/exports/global.js", "src/outro.js" ] }, paths: { sizzle: "../external/sizzle/dist/sizzle" @@ -61,13 +61,10 @@ module.exports = function( grunt ) { } else { - // Ignore jQuery's exports (the only necessary one) - if ( name !== "jquery" ) { - contents = contents - .replace( /\s*return\s+[^\}]+(\}\);[^\w\}]*)$/, "$1" ) - // Multiple exports - .replace( /\s*exports\.\w+\s*=\s*\w+;/g, "" ); - } + contents = contents + .replace( /\s*return\s+[^\}]+(\}\);[^\w\}]*)$/, "$1" ) + // Multiple exports + .replace( /\s*exports\.\w+\s*=\s*\w+;/g, "" ); // Remove define wrappers, closure ends, and empty declarations contents = contents diff --git a/src/.jshintrc b/src/.jshintrc index 3ffebfd5a..6e8dcd3db 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -21,7 +21,8 @@ "globals": { "jQuery": true, - "define": true, - "module": true + "define": false, + "module": false, + "noGlobal": true } } diff --git a/src/exports/global.js b/src/exports/global.js index 137f5e26b..067516a75 100644 --- a/src/exports/global.js +++ b/src/exports/global.js @@ -1,7 +1,3 @@ -define([ - "../core" -], function( jQuery ) { - var // Map over jQuery in case of overwrite _jQuery = window.jQuery, @@ -24,8 +20,6 @@ jQuery.noConflict = function( deep ) { // Expose jQuery and $ identifiers, even in // AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557) // and CommonJS for browser emulators (#13566) -if ( typeof noGlobal === "undefined" ) { +if ( !noGlobal ) { window.jQuery = window.$ = jQuery; } - -}); diff --git a/src/jquery.js b/src/jquery.js index 7c1528b88..6e646cf42 100644 --- a/src/jquery.js +++ b/src/jquery.js @@ -29,10 +29,9 @@ define([ "./offset", "./dimensions", "./deprecated", - "./exports/amd", - "./exports/global" + "./exports/amd" ], function( jQuery ) { -return jQuery; +return (window.jQuery = window.$ = jQuery); }); diff --git a/src/outro.js b/src/outro.js index be4600a5c..d792ffb58 100644 --- a/src/outro.js +++ b/src/outro.js @@ -1 +1,2 @@ +return jQuery; })); diff --git a/test/data/testinit.js b/test/data/testinit.js index 9419986fd..5afc2e370 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -304,7 +304,9 @@ this.loadTests = function() { /** * Run in noConflict mode */ - jQuery.noConflict(); + if ( jQuery.noConflict ) { + jQuery.noConflict(); + } // Load the TestSwarm listener if swarmURL is in the address. if ( loadSwarm ) { diff --git a/test/unit/core.js b/test/unit/core.js index ab6aff0e3..2158ee036 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -226,24 +226,27 @@ test( "globalEval execution after script injection (#7862)", 1, function() { ok( window.strictEvalTest - now < 500, "Code executed synchronously" ); }); -test("noConflict", function() { - expect(7); +// This is not run in AMD mode +if ( jQuery.noConflict ) { + test("noConflict", function() { + expect(7); - var $$ = jQuery; + var $$ = jQuery; - strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); - strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." ); - strictEqual( window["$"], original$, "Make sure $ was reverted." ); + strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); + strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." ); + strictEqual( window["$"], original$, "Make sure $ was reverted." ); - jQuery = $ = $$; + jQuery = $ = $$; - strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); - strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." ); - strictEqual( window["$"], original$, "Make sure $ was reverted." ); - ok( $$().pushStack([]), "Make sure that jQuery still works." ); + strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); + strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." ); + strictEqual( window["$"], original$, "Make sure $ was reverted." ); + ok( $$().pushStack([]), "Make sure that jQuery still works." ); - window["jQuery"] = jQuery = $$; -}); + window["jQuery"] = jQuery = $$; + }); +} test("trim", function() { expect(13); -- 2.39.5