Skip to content

Commit 57652ee

Browse files
committed
Build: fix tests in AMD mode
1 parent 828a718 commit 57652ee

File tree

7 files changed

+31
-34
lines changed

7 files changed

+31
-34
lines changed

build/tasks/build.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = function( grunt ) {
2626
skipSemiColonInsertion: true,
2727
wrap: {
2828
startFile: "src/intro.js",
29-
endFile: "src/outro.js"
29+
endFile: [ "src/exports/global.js", "src/outro.js" ]
3030
},
3131
paths: {
3232
sizzle: "../external/sizzle/dist/sizzle"
@@ -61,13 +61,10 @@ module.exports = function( grunt ) {
6161

6262
} else {
6363

64-
// Ignore jQuery's exports (the only necessary one)
65-
if ( name !== "jquery" ) {
66-
contents = contents
67-
.replace( /\s*return\s+[^\}]+(\}\);[^\w\}]*)$/, "$1" )
68-
// Multiple exports
69-
.replace( /\s*exports\.\w+\s*=\s*\w+;/g, "" );
70-
}
64+
contents = contents
65+
.replace( /\s*return\s+[^\}]+(\}\);[^\w\}]*)$/, "$1" )
66+
// Multiple exports
67+
.replace( /\s*exports\.\w+\s*=\s*\w+;/g, "" );
7168

7269
// Remove define wrappers, closure ends, and empty declarations
7370
contents = contents

src/.jshintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
"globals": {
2323
"jQuery": true,
24-
"define": true,
25-
"module": true
24+
"define": false,
25+
"module": false,
26+
"noGlobal": true
2627
}
2728
}

src/exports/global.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
define([
2-
"../core"
3-
], function( jQuery ) {
4-
51
var
62
// Map over jQuery in case of overwrite
73
_jQuery = window.jQuery,
@@ -24,8 +20,6 @@ jQuery.noConflict = function( deep ) {
2420
// Expose jQuery and $ identifiers, even in
2521
// AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
2622
// and CommonJS for browser emulators (#13566)
27-
if ( typeof noGlobal === "undefined" ) {
23+
if ( !noGlobal ) {
2824
window.jQuery = window.$ = jQuery;
2925
}
30-
31-
});

src/jquery.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ define([
2929
"./offset",
3030
"./dimensions",
3131
"./deprecated",
32-
"./exports/amd",
33-
"./exports/global"
32+
"./exports/amd"
3433
], function( jQuery ) {
3534

36-
return jQuery;
35+
return (window.jQuery = window.$ = jQuery);
3736

3837
});

src/outro.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
return jQuery;
12
}));

test/data/testinit.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ this.loadTests = function() {
304304
/**
305305
* Run in noConflict mode
306306
*/
307-
jQuery.noConflict();
307+
if ( jQuery.noConflict ) {
308+
jQuery.noConflict();
309+
}
308310

309311
// Load the TestSwarm listener if swarmURL is in the address.
310312
if ( loadSwarm ) {

test/unit/core.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,24 +226,27 @@ test( "globalEval execution after script injection (#7862)", 1, function() {
226226
ok( window.strictEvalTest - now < 500, "Code executed synchronously" );
227227
});
228228

229-
test("noConflict", function() {
230-
expect(7);
229+
// This is not run in AMD mode
230+
if ( jQuery.noConflict ) {
231+
test("noConflict", function() {
232+
expect(7);
231233

232-
var $$ = jQuery;
234+
var $$ = jQuery;
233235

234-
strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
235-
strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
236-
strictEqual( window["$"], original$, "Make sure $ was reverted." );
236+
strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
237+
strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
238+
strictEqual( window["$"], original$, "Make sure $ was reverted." );
237239

238-
jQuery = $ = $$;
240+
jQuery = $ = $$;
239241

240-
strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
241-
strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
242-
strictEqual( window["$"], original$, "Make sure $ was reverted." );
243-
ok( $$().pushStack([]), "Make sure that jQuery still works." );
242+
strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
243+
strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
244+
strictEqual( window["$"], original$, "Make sure $ was reverted." );
245+
ok( $$().pushStack([]), "Make sure that jQuery still works." );
244246

245-
window["jQuery"] = jQuery = $$;
246-
});
247+
window["jQuery"] = jQuery = $$;
248+
});
249+
}
247250

248251
test("trim", function() {
249252
expect(13);

0 commit comments

Comments
 (0)