Skip to content

Commit 6051609

Browse files
committed
Build: fix tests in AMD mode
1 parent 58c2460 commit 6051609

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
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/core/parseHTML.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
define([
22
"../core",
33
"./var/rsingleTag",
4+
"./support",
5+
46
"../manipulation" // buildFragment
57
], function( jQuery, rsingleTag, support ) {
68

src/core/support.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
define([
22
"../var/support"
3-
], function( jQuery, support ) {
3+
], function( support ) {
44
// window.document is used here as it's before the sandboxed document
55
support.createHTMLDocument = !!window.document.implementation.createHTMLDocument;
6+
7+
return support;
68
});

src/exports/global.js

Lines changed: 0 additions & 6 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,
@@ -27,5 +23,3 @@ jQuery.noConflict = function( deep ) {
2723
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
@@ -28,10 +28,9 @@ define([
2828
"./offset",
2929
"./dimensions",
3030
"./deprecated",
31-
"./exports/amd",
32-
"./exports/global"
31+
"./exports/amd"
3332
], function( jQuery ) {
3433

35-
return jQuery;
34+
return (window.jQuery = window.$ = jQuery);
3635

3736
});

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
@@ -301,7 +301,9 @@ this.loadTests = function() {
301301
/**
302302
* Run in noConflict mode
303303
*/
304-
jQuery.noConflict();
304+
if (jQuery.noConflict) {
305+
jQuery.noConflict();
306+
}
305307

306308
// Load the TestSwarm listener if swarmURL is in the address.
307309
if ( loadSwarm ) {

test/unit/core.js

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

237-
test("noConflict", function() {
238-
expect(7);
237+
// This is not run in AMD mode
238+
if (jQuery.noConflict) {
239+
test("noConflict", function() {
240+
expect(7);
239241

240-
var $$ = jQuery;
242+
var $$ = jQuery;
241243

242-
strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
243-
strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
244-
strictEqual( window["$"], original$, "Make sure $ was reverted." );
244+
strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" );
245+
strictEqual( window["jQuery"], $$, "Make sure jQuery wasn't touched." );
246+
strictEqual( window["$"], original$, "Make sure $ was reverted." );
245247

246-
jQuery = $ = $$;
248+
jQuery = $ = $$;
247249

248-
strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
249-
strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
250-
strictEqual( window["$"], original$, "Make sure $ was reverted." );
251-
ok( $$().pushStack([]), "Make sure that jQuery still works." );
250+
strictEqual( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
251+
strictEqual( window["jQuery"], originaljQuery, "Make sure jQuery was reverted." );
252+
strictEqual( window["$"], original$, "Make sure $ was reverted." );
253+
ok( $$().pushStack([]), "Make sure that jQuery still works." );
252254

253-
window["jQuery"] = jQuery = $$;
254-
});
255+
window["jQuery"] = jQuery = $$;
256+
});
257+
}
255258

256259
test("trim", function() {
257260
expect(13);

0 commit comments

Comments
 (0)