diff --git a/.gitignore b/.gitignore index c00c4ac7e..44a868959 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ npm-debug.log* /node_modules /test/data/core/jquery-iterability-transpiled.js +/test/data/qunit-fixture.js diff --git a/.travis.yml b/.travis.yml index 43891aeb1..8fc6c710d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,23 +9,37 @@ env: - NPM_SCRIPT=test:browserless matrix: include: - # Run browser tests only on one Node.js version to save time. - - node_js: "12" + - name: "Browser tests: full build, Chrome & Firefox stable" + node_js: "12" env: - NPM_SCRIPT="test:browser" - BROWSERS="ChromeHeadless,FirefoxHeadless" addons: chrome: stable firefox: latest - # Run AMD tests. - - node_js: "12" + - name: "Browser tests: slim build, Chrome stable" + node_js: "12" + env: + - NPM_SCRIPT="test:slim" + - BROWSERS="ChromeHeadless" + addons: + chrome: stable + - name: "Browser tests: no-deprecated build, Chrome stable" + node_js: "12" + env: + - NPM_SCRIPT="test:no-deprecated" + - BROWSERS="ChromeHeadless" + addons: + chrome: stable + - name: "Browser tests: AMD build, Chrome stable" + node_js: "12" env: - NPM_SCRIPT="test:amd" - BROWSERS="ChromeHeadless" addons: chrome: stable - # Run tests on Firefox ESR as well. - - node_js: "12" + - name: "Browser tests: full build, Firefox ESR" + node_js: "12" env: - NPM_SCRIPT="test:browser" - BROWSERS="FirefoxHeadless" diff --git a/Gruntfile.js b/Gruntfile.js index f3786d4eb..486a0f303 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -41,7 +41,7 @@ module.exports = function( grunt ) { retainLines: true, plugins: [ "@babel/transform-for-of" ] }, - nodeSmokeTests: { + tests: { files: { "test/data/core/jquery-iterability-transpiled.js": "test/data/core/jquery-iterability-transpiled-es6.js" @@ -351,7 +351,13 @@ module.exports = function( grunt ) { "karma:jsdom" ] ); + grunt.registerTask( "test:prepare", [ + "qunit_fixture", + "babel:tests" + ] ); + grunt.registerTask( "test", [ + "test:prepare", "test:fast", "test:slow" ] ); @@ -372,7 +378,7 @@ module.exports = function( grunt ) { "uglify", "remove_map_comment", "dist:*", - "qunit_fixture", + "test:prepare", "eslint:dist", "test:fast", "compare_size" diff --git a/build/tasks/node_smoke_tests.js b/build/tasks/node_smoke_tests.js index 40c49a4d9..574a63b4a 100644 --- a/build/tasks/node_smoke_tests.js +++ b/build/tasks/node_smoke_tests.js @@ -4,7 +4,7 @@ module.exports = ( grunt ) => { const fs = require( "fs" ); const spawnTest = require( "./lib/spawn_test.js" ); const testsDir = "./test/node_smoke_tests/"; - const nodeSmokeTests = [ "babel:nodeSmokeTests" ]; + const nodeSmokeTests = []; // Fire up all tests defined in test/node_smoke_tests/*.js in spawned sub-processes. // All the files under test/node_smoke_tests/*.js are supposed to exit with 0 code diff --git a/package.json b/package.json index 905e6a15e..a38cf1c17 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,9 @@ "test:browserless": "grunt && grunt test:slow", "test:browser": "grunt && grunt karma:main", "test:amd": "grunt && grunt karma:amd", - "test": "grunt && grunt test:slow && grunt karma:main && grunt karma:amd", + "test:no-deprecated": "grunt test:prepare && grunt custom:-deprecated && grunt karma:main", + "test:slim": "grunt test:prepare && grunt custom:slim && grunt karma:main", + "test": "npm run test:slim && npm run test:no-deprecated && grunt && grunt test:slow && grunt karma:main && grunt karma:amd", "jenkins": "npm run test:browserless" }, "commitplease": { diff --git a/src/ajax.js b/src/ajax.js index b1f160840..11eda0da0 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -8,7 +8,7 @@ define( [ "./ajax/var/rquery", "./core/init", - "./ajax/parseXML", + "./core/parseXML", "./event/trigger", "./deferred", "./serialize" // jQuery.param diff --git a/src/ajax/parseXML.js b/src/core/parseXML.js similarity index 100% rename from src/ajax/parseXML.js rename to src/core/parseXML.js diff --git a/src/jquery.js b/src/jquery.js index 61c4b2f0d..0c144c194 100644 --- a/src/jquery.js +++ b/src/jquery.js @@ -23,6 +23,8 @@ define( [ "./ajax/script", "./ajax/jsonp", "./ajax/load", + "./core/parseXML", + "./core/parseHTML", "./effects", "./effects/animatedSelector", "./offset", diff --git a/test/data/core/dynamic_ready.html b/test/data/core/dynamic_ready.html index e8180cd2b..fade7adc2 100644 --- a/test/data/core/dynamic_ready.html +++ b/test/data/core/dynamic_ready.html @@ -2,7 +2,7 @@ - + diff --git a/test/data/offset/absolute.html b/test/data/offset/absolute.html index 9d8700465..4883e81be 100644 --- a/test/data/offset/absolute.html +++ b/test/data/offset/absolute.html @@ -18,15 +18,15 @@ diff --git a/test/data/offset/body.html b/test/data/offset/body.html index 75757d7e6..a27e242af 100644 --- a/test/data/offset/body.html +++ b/test/data/offset/body.html @@ -12,13 +12,13 @@ diff --git a/test/data/offset/fixed.html b/test/data/offset/fixed.html index 48a2c4797..9016f87a9 100644 --- a/test/data/offset/fixed.html +++ b/test/data/offset/fixed.html @@ -15,10 +15,10 @@ diff --git a/test/data/offset/scroll.html b/test/data/offset/scroll.html index 28cade1c3..3b9848fe4 100644 --- a/test/data/offset/scroll.html +++ b/test/data/offset/scroll.html @@ -17,16 +17,16 @@ diff --git a/test/data/offset/static.html b/test/data/offset/static.html index 1f4c3dc3d..913f9d260 100644 --- a/test/data/offset/static.html +++ b/test/data/offset/static.html @@ -13,15 +13,15 @@ diff --git a/test/data/offset/table.html b/test/data/offset/table.html index eeac19b77..1650e7297 100644 --- a/test/data/offset/table.html +++ b/test/data/offset/table.html @@ -13,13 +13,13 @@ diff --git a/test/data/qunit-fixture.js b/test/data/qunit-fixture.js deleted file mode 100644 index 46f0c3c26..000000000 --- a/test/data/qunit-fixture.js +++ /dev/null @@ -1,2 +0,0 @@ -// Generated by build/tasks/qunit_fixture.js -QUnit.config.fixture = "

See this blog entry for more information.

\n

\n\tHere are some links in a normal paragraph: Google,\n\tGoogle Groups (Link).\n\tThis link has class=\"blog\":\n\tdiveintomark\n\n

\n
\n\t

Everything inside the red border is inside a div with id=\"foo\".

\n\t

This is a normal link: Yahoo

\n\t

This link has class=\"blog\": Simon Willison's Weblog

\n\n
\n
\n\t
\n
\n\n

Try them out:

\n\n
    \n
    \n\t\n\t\n\t\n\t\n\n\t\n\t\n\t\n\n\t\n\t\n\n\t\n\t\n\n\t\n\n\t\n\n\t\n\t\n\t\n\t\n\t\n\n\t\n\t\t\n\t\t\n\t\n\n\t\n\t\n\t\n\t\n\t\n\t\n\n\ttest element\n
    \nFloat test.\n\n
    \n\t\n\t\n
    \n
    \n\n
    \n\t\n\t\n\t\n\t\n
    \n\n
    \n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\n
    \n
    \n\t
    \n\t\t
    \n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t
    \n\t
    \n\t
    hi there
    \n\t
    \n\t\t
    hidden
    \n\t
    \n\t
    \n\t\t
    \n\t
    \n\t
    \n
    \n\n
    \n\t
      \n\t\t
    1. Rice
    2. \n\t\t
    3. Beans
    4. \n\t\t
    5. Blinis
    6. \n\t\t
    7. Tofu
    8. \n\t
    \n\n\t
    I'm hungry. I should...
    \n\t...Eat lots of food... |\n\t...Eat a little food... |\n\t...Eat no food...\n\t...Eat a burger...\n\t...Eat some funyuns...\n\t...Eat some funyuns...\n\t\n\t\n\t\n\t\n\t\t\n\t\n
    \n\n
    \n\t\n\t\n
    \n\n
    \n\t1\n\t2\n\t\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t\n\t\n
    \n
    \n\t
    \n\t\t
    fadeIn
    fadeIn
    \n\t\t
    fadeOut
    fadeOut
    \n\n\t\t
    show
    show
    \n\t\t
    hide
    hide
    \n\t\t
    hide
    hide
    \n\n\t\t
    togglein
    togglein
    \n\t\t
    toggleout
    toggleout
    \n\t\t
    toggleout
    toggleout
    \n\n\t\t
    slideUp
    slideUp
    \n\t\t
    slideDown
    slideDown
    \n\t\t
    slideUp
    slideUp
    \n\n\t\t
    slideToggleIn
    slideToggleIn
    \n\t\t
    slideToggleOut
    slideToggleOut
    \n\n\t\t
    fadeToggleIn
    fadeToggleIn
    \n\t\t
    fadeToggleOut
    fadeToggleOut
    \n\n\t\t
    fadeTo
    fadeTo
    \n\t
    \n\n\t
    \n\t\n
    \n"; diff --git a/test/unit/ajax.js b/test/unit/ajax.js index fda7a9daf..bcf7202cd 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -257,7 +257,7 @@ QUnit.module( "ajax", { ajaxTest( "jQuery.ajax() - headers", 8, function( assert ) { return { setup: function() { - jQuery( document ).ajaxSend( function( evt, xhr ) { + jQuery( document ).on( "ajaxSend", function( evt, xhr ) { xhr.setRequestHeader( "ajax-send", "test" ); } ); }, @@ -611,10 +611,10 @@ QUnit.module( "ajax", { return { setup: function() { jQuery( context ).appendTo( "#foo" ) - .ajaxSend( event ) - .ajaxComplete( event ) - .ajaxError( event ) - .ajaxSuccess( event ); + .on( "ajaxSend", event ) + .on( "ajaxComplete", event ) + .on( "ajaxError", event ) + .on( "ajaxSuccess", event ); }, requests: [ { url: url( "name.html" ), @@ -2455,7 +2455,7 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re var done = assert.async(); addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert )(); - jQuery( document ).ajaxStop( done ); + jQuery( document ).on( "ajaxStop", done ); jQuery( "
    " ).load( baseURL + "404.txt", function() { assert.ok( true, "complete" ); } ); @@ -2643,7 +2643,7 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re jQuery.ajaxSetup( { dataType: "json" } ); - jQuery( document ).ajaxComplete( function( e, xml, s ) { + jQuery( document ).on( "ajaxComplete", function( e, xml, s ) { assert.strictEqual( s.dataType, "html", "Verify the load() dataType was html" ); jQuery( document ).off( "ajaxComplete" ); done(); @@ -2664,7 +2664,7 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re } } ); jQuery( "#foo" ).load( baseURL + "mock.php?action=echoQuery", data ); - jQuery( document ).ajaxComplete( function( event, jqXHR, options ) { + jQuery( document ).on( "ajaxComplete", function( event, jqXHR, options ) { assert.ok( ~options.data.indexOf( "foo=bar" ), "Data from ajaxSettings was used" ); done(); } ); diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index b440f3822..c1a6eacf6 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -4,6 +4,12 @@ QUnit.module( "callbacks", { ( function() { +if ( !jQuery.Callbacks ) { + return; +} + +( function() { + var output, addToOutput = function( string ) { return function() { @@ -387,3 +393,5 @@ QUnit.test( "jQuery.Callbacks() - list with memory stays locked (gh-3469)", func cb.fire(); assert.equal( fired, 11, "Post-lock() fire ignored" ); } ); + +} )(); diff --git a/test/unit/data.js b/test/unit/data.js index 32605cff8..bd0b4e882 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -737,6 +737,7 @@ QUnit.test( ".data supports interoperable hyphenated/camelCase get/set of proper QUnit.test( ".data supports interoperable removal of hyphenated/camelCase properties", function( assert ) { var div = jQuery( "
    ", { id: "hyphened" } ).appendTo( "#qunit-fixture" ), + rdashAlpha = /-([a-z])/g, datas = { "non-empty": "a string", "empty-string": "", @@ -755,11 +756,19 @@ QUnit.test( ".data supports interoperable removal of hyphenated/camelCase proper assert.expect( 27 ); + function fcamelCase( all, letter ) { + return letter.toUpperCase(); + } + jQuery.each( datas, function( key, val ) { div.data( key, val ); assert.deepEqual( div.data( key ), val, "get: " + key ); - assert.deepEqual( div.data( jQuery.camelCase( key ) ), val, "get: " + jQuery.camelCase( key ) ); + assert.deepEqual( + div.data( key.replace( rdashAlpha, fcamelCase ) ), + val, + "get: " + key.replace( rdashAlpha, fcamelCase ) + ); div.removeData( key ); diff --git a/test/unit/deferred.js b/test/unit/deferred.js index c704f905f..0132a0129 100644 --- a/test/unit/deferred.js +++ b/test/unit/deferred.js @@ -2,6 +2,12 @@ QUnit.module( "deferred", { afterEach: moduleTeardown } ); +( function() { + +if ( !jQuery.Deferred ) { + return; +} + jQuery.each( [ "", " - new operator" ], function( _, withNew ) { function createDeferred( fn ) { @@ -1154,3 +1160,5 @@ QUnit.test( "jQuery.when(...) - opportunistically synchronous", function( assert when = "after"; } ); + +} )(); diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js index 977ab35eb..8ab520e58 100644 --- a/test/unit/deprecated.js +++ b/test/unit/deprecated.js @@ -1,7 +1,7 @@ QUnit.module( "deprecated", { afterEach: moduleTeardown } ); -QUnit.test( "bind/unbind", function( assert ) { +QUnit[ jQuery.fn.bind ? "test" : "skip" ]( "bind/unbind", function( assert ) { assert.expect( 4 ); var markup = jQuery( @@ -22,7 +22,7 @@ QUnit.test( "bind/unbind", function( assert ) { .remove(); } ); -QUnit.test( "delegate/undelegate", function( assert ) { +QUnit[ jQuery.fn.delegate ? "test" : "skip" ]( "delegate/undelegate", function( assert ) { assert.expect( 2 ); var markup = jQuery( @@ -41,28 +41,25 @@ QUnit.test( "delegate/undelegate", function( assert ) { .remove(); } ); -if ( jQuery.fn.hover ) { - QUnit.test( "hover() mouseenter mouseleave", function( assert ) { - assert.expect( 1 ); +QUnit[ jQuery.fn.hover ? "test" : "skip" ]( "hover() mouseenter mouseleave", function( assert ) { + assert.expect( 1 ); - var times = 0, - handler1 = function() { ++times; }, - handler2 = function() { ++times; }; + var times = 0, + handler1 = function() { ++times; }, + handler2 = function() { ++times; }; - jQuery( "#firstp" ) - .hover( handler1, handler2 ) - .mouseenter().mouseleave() - .off( "mouseenter", handler1 ) - .off( "mouseleave", handler2 ) - .hover( handler1 ) - .mouseenter().mouseleave() - .off( "mouseenter mouseleave", handler1 ) - .mouseenter().mouseleave(); + jQuery( "#firstp" ) + .hover( handler1, handler2 ) + .mouseenter().mouseleave() + .off( "mouseenter", handler1 ) + .off( "mouseleave", handler2 ) + .hover( handler1 ) + .mouseenter().mouseleave() + .off( "mouseenter mouseleave", handler1 ) + .mouseenter().mouseleave(); - assert.equal( times, 4, "hover handlers fired" ); - - } ); -} + assert.equal( times, 4, "hover handlers fired" ); +} ); QUnit[ jQuery.fn.click ? "test" : "skip" ]( "trigger() shortcuts", function( assert ) { @@ -99,6 +96,45 @@ QUnit[ jQuery.fn.click ? "test" : "skip" ]( "trigger() shortcuts", function( ass assert.equal( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" ); } ); +if ( jQuery.ajax && jQuery.fn.ajaxSend ) { + ajaxTest( "jQuery.ajax() - events with context", 12, function( assert ) { + var context = document.createElement( "div" ); + + function event( e ) { + assert.equal( this, context, e.type ); + } + + function callback( msg ) { + return function() { + assert.equal( this, context, "context is preserved on callback " + msg ); + }; + } + + return { + setup: function() { + jQuery( context ).appendTo( "#foo" ) + .ajaxSend( event ) + .ajaxComplete( event ) + .ajaxError( event ) + .ajaxSuccess( event ); + }, + requests: [ { + url: url( "name.html" ), + context: context, + beforeSend: callback( "beforeSend" ), + success: callback( "success" ), + complete: callback( "complete" ) + }, { + url: url( "404.txt" ), + context: context, + beforeSend: callback( "beforeSend" ), + error: callback( "error" ), + complete: callback( "complete" ) + } ] + }; + } ); +} + QUnit[ jQuery.fn.click ? "test" : "skip" ]( "Event aliases", function( assert ) { // Explicitly skipping focus/blur events due to their flakiness @@ -117,7 +153,7 @@ QUnit[ jQuery.fn.click ? "test" : "skip" ]( "Event aliases", function( assert ) } ); } ); -QUnit.test( "jQuery.parseJSON", function( assert ) { +QUnit[ jQuery.parseJSON ? "test" : "skip" ]( "jQuery.parseJSON", function( assert ) { assert.expect( 20 ); assert.strictEqual( jQuery.parseJSON( null ), null, "primitive null" ); @@ -187,13 +223,13 @@ QUnit.test( "jQuery.parseJSON", function( assert ) { assert.strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" ); } ); -QUnit.test( "jQuery.isArray", function( assert ) { +QUnit[ jQuery.isArray ? "test" : "skip" ]( "jQuery.isArray", function( assert ) { assert.expect( 1 ); assert.strictEqual( jQuery.isArray, Array.isArray, "Array.isArray equals jQuery.isArray" ); } ); -QUnit.test( "jQuery.nodeName", function( assert ) { +QUnit[ jQuery.nodeName ? "test" : "skip" ]( "jQuery.nodeName", function( assert ) { assert.expect( 8 ); assert.strictEqual( typeof jQuery.nodeName, "function", "jQuery.nodeName is a function" ); @@ -242,7 +278,7 @@ QUnit.test( "jQuery.nodeName", function( assert ) { } ); -QUnit.test( "type", function( assert ) { +QUnit[ jQuery.type ? "test" : "skip" ]( "type", function( assert ) { assert.expect( 28 ); assert.equal( jQuery.type( null ), "null", "null" ); @@ -281,14 +317,15 @@ QUnit.test( "type", function( assert ) { assert.equal( jQuery.type( new MyObject() ), "object", "Object" ); } ); -QUnit[ typeof Symbol === "function" ? "test" : "skip" ]( "type for `Symbol`", function( assert ) { +QUnit[ jQuery.type && typeof Symbol === "function" ? "test" : "skip" ]( + "type for `Symbol`", function( assert ) { assert.expect( 2 ); assert.equal( jQuery.type( Symbol() ), "symbol", "Symbol" ); assert.equal( jQuery.type( Object( Symbol() ) ), "symbol", "Symbol" ); } ); -QUnit.test( "isFunction", function( assert ) { +QUnit[ jQuery.isFunction ? "test" : "skip" ]( "isFunction", function( assert ) { assert.expect( 20 ); var mystr, myarr, myfunction, fn, obj, nodes, first, input, a; @@ -376,7 +413,7 @@ QUnit.test( "isFunction", function( assert ) { } ); } ); -QUnit.test( "isFunction(cross-realm function)", function( assert ) { +QUnit[ jQuery.isFunction ? "test" : "skip" ]( "isFunction(cross-realm function)", function( assert ) { assert.expect( 1 ); var iframe, doc, @@ -409,7 +446,7 @@ supportjQuery.each( fn = Function( "return " + source )(); } catch ( e ) {} - QUnit[ fn ? "test" : "skip" ]( "isFunction(" + subclass + ")", + QUnit[ jQuery.isFunction && fn ? "test" : "skip" ]( "isFunction(" + subclass + ")", function( assert ) { assert.expect( 1 ); @@ -419,7 +456,7 @@ supportjQuery.each( } ); -QUnit[ typeof Symbol === "function" && Symbol.toStringTag ? "test" : "skip" ]( +QUnit[ jQuery.isFunction && typeof Symbol === "function" && Symbol.toStringTag ? "test" : "skip" ]( "isFunction(custom @@toStringTag)", function( assert ) { assert.expect( 2 ); @@ -434,7 +471,7 @@ QUnit[ typeof Symbol === "function" && Symbol.toStringTag ? "test" : "skip" ]( } ); -QUnit.test( "jQuery.isWindow", function( assert ) { +QUnit[ jQuery.isWindow ? "test" : "skip" ]( "jQuery.isWindow", function( assert ) { assert.expect( 14 ); assert.ok( jQuery.isWindow( window ), "window" ); @@ -453,7 +490,7 @@ QUnit.test( "jQuery.isWindow", function( assert ) { assert.ok( !jQuery.isWindow( function() {} ), "function" ); } ); -QUnit.test( "jQuery.camelCase()", function( assert ) { +QUnit[ jQuery.camelCase ? "test" : "skip" ]( "jQuery.camelCase()", function( assert ) { var tests = { "foo-bar": "fooBar", @@ -472,13 +509,13 @@ QUnit.test( "jQuery.camelCase()", function( assert ) { } ); } ); -QUnit.test( "jQuery.now", function( assert ) { +QUnit[ jQuery.now ? "test" : "skip" ]( "jQuery.now", function( assert ) { assert.expect( 1 ); assert.ok( typeof jQuery.now() === "number", "jQuery.now is a function" ); } ); -QUnit.test( "jQuery.proxy", function( assert ) { +QUnit[ jQuery.proxy ? "test" : "skip" ]( "jQuery.proxy", function( assert ) { assert.expect( 9 ); var test2, test3, test4, fn, cb, @@ -526,7 +563,7 @@ QUnit.test( "jQuery.proxy", function( assert ) { cb.call( thisObject, "arg3" ); } ); -QUnit.test( "isNumeric", function( assert ) { +QUnit[ jQuery.isNumeric ? "test" : "skip" ]( "isNumeric", function( assert ) { assert.expect( 43 ); var t = jQuery.isNumeric, @@ -594,14 +631,15 @@ QUnit.test( "isNumeric", function( assert ) { assert.equal( t( new Date() ), false, "Instance of a Date" ); } ); -QUnit[ typeof Symbol === "function" ? "test" : "skip" ]( "isNumeric(Symbol)", function( assert ) { +QUnit[ jQuery.isNumeric && typeof Symbol === "function" ? "test" : "skip" ]( + "isNumeric(Symbol)", function( assert ) { assert.expect( 2 ); assert.equal( jQuery.isNumeric( Symbol() ), false, "Symbol" ); assert.equal( jQuery.isNumeric( Object( Symbol() ) ), false, "Symbol inside an object" ); } ); -QUnit.test( "trim", function( assert ) { +QUnit[ jQuery.trim ? "test" : "skip" ]( "trim", function( assert ) { assert.expect( 13 ); var nbsp = String.fromCharCode( 160 ); diff --git a/test/unit/event.js b/test/unit/event.js index 9a7692023..fdddb0ba6 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -1317,7 +1317,7 @@ QUnit.test( "Delegated events with malformed selectors (gh-3071)", function( ass jQuery( "#foo" ).on( "click", "nonexistent:not", function() {} ); }, "short-circuitable malformed selector throws on attach" ); - jQuery( "#foo > :first-child" ).click(); + jQuery( "#foo > :first-child" ).trigger( "click" ); assert.ok( true, "malformed selector does not throw on event" ); } ); @@ -2490,7 +2490,7 @@ QUnit.test( "drag/drop events copy mouse-related event properties (gh-1925, gh-2 fireNative( $fixture[ 0 ], "drop" ); - $fixture.unbind( "dragmove drop" ).remove(); + $fixture.off( "dragmove drop" ).remove(); } ); QUnit.test( "focusin using non-element targets", function( assert ) { @@ -2543,7 +2543,8 @@ testIframe( function( assert, jQuery, window, document, isOk ) { assert.expect( 1 ); assert.ok( isOk, "$.when( $.ready ) works" ); - } + }, + jQuery.when ? QUnit.test : QUnit.skip ); // need PHP here to make the incepted IFRAME hang diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index d3f719d1b..b7fc95a0a 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2441,7 +2441,6 @@ QUnit.test( "html() - script exceptions bubble (#11743)", function( assert ) { assert.ok( true, "Exception ignored" ); } else { assert.ok( true, "No jQuery.ajax" ); - assert.ok( true, "No jQuery.ajax" ); } }; @@ -2531,7 +2530,7 @@ QUnit.test( "script evaluation (#11795)", function( assert ) { } } ); -QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) { +QUnit[ jQuery.ajax ? "test" : "skip" ]( "jQuery._evalUrl (#12838)", function( assert ) { assert.expect( 5 ); @@ -2825,7 +2824,8 @@ QUnit.test( "Make sure tags with single-character names are found (gh-4124)", fu assert.strictEqual( htmlOut, htmlIn ); } ); -QUnit.test( "Insert script with data-URI (gh-1887)", function( assert ) { +// The AJAX module is needed for jQuery._evalUrl. +QUnit[ jQuery.ajax ? "test" : "skip" ]( "Insert script with data-URI (gh-1887)", function( assert ) { assert.expect( 1 ); Globals.register( "testFoo" ); Globals.register( "testSrcFoo" ); @@ -2908,13 +2908,14 @@ testIframe( } ); }, + // The AJAX module is needed for jQuery._evalUrl. // Support: Edge 18+, iOS 7-9 only, Android 4.0-4.4 only // Edge doesn't support nonce in non-inline scripts. // See https://web.archive.org/web/20171203124125/https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13246371/ // Old iOS & Android Browser versions support script-src but not nonce, making this test // impossible to run. Browsers not supporting CSP at all are not a problem as they'll skip // script-src restrictions completely. - QUnit[ /\bedge\/|iphone os [789]|android 4\./i.test( navigator.userAgent ) ? "skip" : "test" ] + QUnit[ jQuery.ajax && !/\bedge\/|iphone os [789]|android 4\./i.test( navigator.userAgent ) ? "test" : "skip" ] ); testIframe( diff --git a/test/unit/queue.js b/test/unit/queue.js index 6c8ad762d..7735544bc 100644 --- a/test/unit/queue.js +++ b/test/unit/queue.js @@ -1,5 +1,11 @@ QUnit.module( "queue", { afterEach: moduleTeardown } ); +( function() { + +if ( !jQuery.fn.queue ) { + return; +} + QUnit.test( "queue() with other types", function( assert ) { var done = assert.async( 2 ); assert.expect( 14 ); @@ -271,64 +277,63 @@ QUnit.test( ".promise(obj)", function( assert ) { assert.strictEqual( promise, obj, ".promise(type, obj) returns obj" ); } ); -if ( jQuery.fn.stop ) { - QUnit.test( "delay() can be stopped", function( assert ) { - var done = assert.async(); - assert.expect( 3 ); - var storage = {}; - jQuery( {} ) - .queue( "alternate", function( next ) { - storage.alt1 = true; - assert.ok( true, "This first function was dequeued" ); - next(); - } ) - .delay( 1000, "alternate" ) - .queue( "alternate", function() { - storage.alt2 = true; - assert.ok( true, "The function was dequeued immediately, the delay was stopped" ); - } ) - .dequeue( "alternate" ) +QUnit[ jQuery.fn.stop ? "test" : "skip" ]( "delay() can be stopped", function( assert ) { + var done = assert.async(); + assert.expect( 3 ); + var storage = {}; + jQuery( {} ) + .queue( "alternate", function( next ) { + storage.alt1 = true; + assert.ok( true, "This first function was dequeued" ); + next(); + } ) + .delay( 1000, "alternate" ) + .queue( "alternate", function() { + storage.alt2 = true; + assert.ok( true, "The function was dequeued immediately, the delay was stopped" ); + } ) + .dequeue( "alternate" ) - // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next - .stop( "alternate", false, false ) + // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next + .stop( "alternate", false, false ) - // this test - .delay( 1 ) - .queue( function() { - storage.default1 = true; - assert.ok( false, "This queue should never run" ); - } ) + // this test + .delay( 1 ) + .queue( function() { + storage.default1 = true; + assert.ok( false, "This queue should never run" ); + } ) - // stop( clearQueue ) should clear the queue - .stop( true, false ); + // stop( clearQueue ) should clear the queue + .stop( true, false ); - assert.deepEqual( storage, { alt1: true, alt2: true }, "Queue ran the proper functions" ); + assert.deepEqual( storage, { alt1: true, alt2: true }, "Queue ran the proper functions" ); - setTimeout( function() { + setTimeout( function() { + done(); + }, 1500 ); +} ); + +QUnit[ jQuery.fn.stop ? "test" : "skip" ]( "queue stop hooks", function( assert ) { + assert.expect( 2 ); + var done = assert.async(); + var foo = jQuery( "#foo" ); + + foo.queue( function( next, hooks ) { + hooks.stop = function( gotoEnd ) { + assert.equal( !!gotoEnd, false, "Stopped without gotoEnd" ); + }; + } ); + foo.stop(); + + foo.queue( function( next, hooks ) { + hooks.stop = function( gotoEnd ) { + assert.equal( gotoEnd, true, "Stopped with gotoEnd" ); done(); - }, 1500 ); + }; } ); - QUnit.test( "queue stop hooks", function( assert ) { - assert.expect( 2 ); - var done = assert.async(); - var foo = jQuery( "#foo" ); + foo.stop( false, true ); +} ); - foo.queue( function( next, hooks ) { - hooks.stop = function( gotoEnd ) { - assert.equal( !!gotoEnd, false, "Stopped without gotoEnd" ); - }; - } ); - foo.stop(); - - foo.queue( function( next, hooks ) { - hooks.stop = function( gotoEnd ) { - assert.equal( gotoEnd, true, "Stopped with gotoEnd" ); - done(); - }; - } ); - - foo.stop( false, true ); - } ); - -} // if ( jQuery.fn.stop ) +} )(); diff --git a/test/unit/ready.js b/test/unit/ready.js index d3396b1c4..fd33c0a18 100644 --- a/test/unit/ready.js +++ b/test/unit/ready.js @@ -2,7 +2,7 @@ QUnit.module( "ready" ); ( function() { var notYetReady, noEarlyExecution, - whenified = jQuery.when( jQuery.ready ), + whenified = jQuery.when && jQuery.when( jQuery.ready ), promisified = Promise.resolve( jQuery.ready ), start = new Date(), order = [], @@ -105,7 +105,7 @@ QUnit.module( "ready" ); } ); } ); - QUnit.test( "jQuery.when(jQuery.ready)", function( assert ) { + QUnit[ jQuery.when ? "test" : "skip" ]( "jQuery.when(jQuery.ready)", function( assert ) { assert.expect( 2 ); var done = jQuery.map( new Array( 2 ), function() { return assert.async(); } ); @@ -149,15 +149,18 @@ QUnit.module( "ready" ); } ); } ); - testIframe( - "holdReady test needs to be a standalone test since it deals with DOM ready", - "readywait.html", - function( assert, jQuery, window, document, releaseCalled ) { - assert.expect( 2 ); - var now = new Date(); - assert.ok( now - start >= 300, "Needs to have waited at least half a second" ); - assert.ok( releaseCalled, "The release function was called, which resulted in ready" ); - } - ); + // jQuery.holdReady is deprecated, skip the test if it was excluded. + if ( jQuery.holdReady ) { + testIframe( + "holdReady test needs to be a standalone test since it deals with DOM ready", + "readywait.html", + function( assert, jQuery, window, document, releaseCalled ) { + assert.expect( 2 ); + var now = new Date(); + assert.ok( now - start >= 300, "Needs to have waited at least half a second" ); + assert.ok( releaseCalled, "The release function was called, which resulted in ready" ); + } + ); + } } )(); diff --git a/test/unit/serialize.js b/test/unit/serialize.js index d23421ddd..c4e6a6c5e 100644 --- a/test/unit/serialize.js +++ b/test/unit/serialize.js @@ -77,7 +77,7 @@ QUnit.test( "jQuery.param()", function( assert ) { assert.equal( jQuery.param( params ), "", "jQuery.param( undefined ) === empty string" ); } ); -QUnit.test( "jQuery.param() not affected by ajaxSettings", function( assert ) { +QUnit[ jQuery.ajax ? "test" : "skip" ]( "jQuery.param() not affected by ajaxSettings", function( assert ) { assert.expect( 1 ); var oldTraditional = jQuery.ajaxSettings.traditional; diff --git a/test/unit/support.js b/test/unit/support.js index d7de8ac5c..e293c7423 100644 --- a/test/unit/support.js +++ b/test/unit/support.js @@ -55,7 +55,7 @@ testIframe( ); ( function() { - var expected, + var browserKey, expected, userAgent = window.navigator.userAgent, expectedMap = { edge: { @@ -294,6 +294,14 @@ testIframe( } }; + // Make the slim build pass tests. + for ( browserKey in expectedMap ) { + if ( !jQuery.ajax ) { + delete expectedMap[ browserKey ].ajax; + delete expectedMap[ browserKey ].cors; + } + } + if ( /edge\//i.test( userAgent ) ) { expected = expectedMap.edge; } else if ( /(msie 10\.0|trident\/7\.0)/i.test( userAgent ) ) {