Skip to content

Commit

Permalink
Build: fix tests in AMD mode
Browse files Browse the repository at this point in the history
  • Loading branch information
timmywil committed Dec 9, 2014
1 parent 58c2460 commit 6051609
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
13 changes: 5 additions & 8 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/core/parseHTML.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
define([
"../core",
"./var/rsingleTag",
"./support",

"../manipulation" // buildFragment
], function( jQuery, rsingleTag, support ) {

Expand Down
4 changes: 3 additions & 1 deletion src/core/support.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
define([
"../var/support"
], function( jQuery, support ) {
], function( support ) {
// window.document is used here as it's before the sandboxed document
support.createHTMLDocument = !!window.document.implementation.createHTMLDocument;

return support;
});
6 changes: 0 additions & 6 deletions src/exports/global.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
define([
"../core"
], function( jQuery ) {

var
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
Expand All @@ -27,5 +23,3 @@ jQuery.noConflict = function( deep ) {
if ( !noGlobal ) {
window.jQuery = window.$ = jQuery;
}

});
5 changes: 2 additions & 3 deletions src/jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ define([
"./offset",
"./dimensions",
"./deprecated",
"./exports/amd",
"./exports/global"
"./exports/amd"
], function( jQuery ) {

return jQuery;
return (window.jQuery = window.$ = jQuery);

});
1 change: 1 addition & 0 deletions src/outro.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
return jQuery;
}));
4 changes: 3 additions & 1 deletion test/data/testinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,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 ) {
Expand Down
29 changes: 16 additions & 13 deletions test/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,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);
Expand Down

0 comments on commit 6051609

Please sign in to comment.