]> source.dussan.org Git - jquery.git/commitdiff
Build: Update jsdom; migrate a test with Symbol polyfill to an iframe test
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 4 Mar 2019 17:30:51 +0000 (18:30 +0100)
committerGitHub <noreply@github.com>
Mon, 4 Mar 2019 17:30:51 +0000 (18:30 +0100)
So far, we've been testing that jQuery element iteration works with polyfilled
Symbol & transpiled for-of via a Node test with jsdom with the Symbol global
removed. Unfortunately, jsdom now requires Symbol to be present for its internal
functionality so such a test is no longer possible. Instead, it's been migrated
to an iframe test with transpiled JavaScript.

This PR also enables us to use ECMAScript 2017 or newer in Node.js code.

Closes gh-4305

19 files changed:
.eslintignore
.eslintrc-node.json
.gitignore
Gruntfile.js
build/tasks/node_smoke_tests.js
package.json
test/.eslintrc.json
test/data/core/jquery-iterability-transpiled-es6.js [new file with mode: 0644]
test/data/core/jquery-iterability-transpiled.html [new file with mode: 0644]
test/node_smoke_tests/document_missing.js
test/node_smoke_tests/document_passed.js
test/node_smoke_tests/document_present_originally.js
test/node_smoke_tests/iterable_with_symbol_polyfill.js [deleted file]
test/node_smoke_tests/lib/ensure_global_not_created.js
test/node_smoke_tests/lib/ensure_iterability_es6.js
test/node_smoke_tests/lib/ensure_jquery.js
test/promises_aplus_adapters/deferred.js
test/promises_aplus_adapters/when.js
test/unit/core.js

index 4154933516e4cb08335a932034dce443f9b62983..3ee82bba374d73bea30896a353df34fa369677e4 100644 (file)
@@ -11,4 +11,4 @@ test/data/readywaitasset.js
 test/data/readywaitloader.js
 test/data/support/csp.js
 test/data/support/getComputedSupport.js
-test/node_smoke_tests/lib/ensure_iterability.js
+test/data/core/jquery-iterability-transpiled.js
index 904e7ba94d63aafa63581624fb62a7e0849bcfd6..589144272ce4e865005369ea487d3c16ef3c9465 100644 (file)
@@ -4,10 +4,11 @@
        "extends": "jquery",
 
        "parserOptions": {
-               "ecmaVersion": 5
+               "ecmaVersion": 2017
        },
 
        "env": {
+               "es6": true,
                "node": true
        }
 }
index 6b00bc2e28f702503f2bf39dd468a96d92294410..c00c4ac7eb58911c24a65883ca86104c0595bb40 100644 (file)
@@ -18,4 +18,4 @@ npm-debug.log*
 
 /node_modules
 
-/test/node_smoke_tests/lib/ensure_iterability.js
+/test/data/core/jquery-iterability-transpiled.js
index ca82e8016806c1aa31b3c03457b0743caa15d255..cf11680c4d32845374ff219ec9233d50a3701e9e 100644 (file)
@@ -42,8 +42,8 @@ module.exports = function( grunt ) {
                        },
                        nodeSmokeTests: {
                                files: {
-                                       "test/node_smoke_tests/lib/ensure_iterability.js":
-                                               "test/node_smoke_tests/lib/ensure_iterability_es6.js"
+                                       "test/data/core/jquery-iterability-transpiled.js":
+                                               "test/data/core/jquery-iterability-transpiled-es6.js"
                                }
                        }
                },
index bd0a9150e0b3574734f4b61df1bc3cbd9c004b59..e3d69db883a472b2106bca6586fa9719ce662577 100644 (file)
@@ -1,11 +1,11 @@
-module.exports = function( grunt ) {
+module.exports = ( grunt ) => {
 
        "use strict";
 
-       var fs = require( "fs" ),
-               spawnTest = require( "./lib/spawn_test.js" ),
-               testsDir = "./test/node_smoke_tests/",
-               nodeSmokeTests = [ "babel:nodeSmokeTests" ];
+       const fs = require( "fs" );
+       const spawnTest = require( "./lib/spawn_test.js" );
+       const testsDir = "./test/node_smoke_tests/";
+       const nodeSmokeTests = [ "babel: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
@@ -14,15 +14,15 @@ module.exports = function( grunt ) {
        // each other, e.g. so that they don't share the require cache.
 
        fs.readdirSync( testsDir )
-               .filter( function( testFilePath ) {
-                       return fs.statSync( testsDir + testFilePath ).isFile() &&
-                               /\.js$/.test( testFilePath );
-               )
-               .forEach( function( testFilePath ) {
-                       var taskName = "node_" + testFilePath.replace( /\.js$/, "" );
+               .filter( ( testFilePath ) =>
+                       fs.statSync( testsDir + testFilePath ).isFile() &&
+                               /\.js$/.test( testFilePath )
+               )
+               .forEach( ( testFilePath ) => {
+                       const taskName = `node_${ testFilePath.replace( /\.js$/, "" ) }`;
 
                        grunt.registerTask( taskName, function() {
-                               spawnTest( this.async(), "node \"test/node_smoke_tests/" + testFilePath + "\"" );
+                               spawnTest( this.async(), `node "test/node_smoke_tests/${ testFilePath }"` );
                        } );
 
                        nodeSmokeTests.push( taskName );
index 43c8b6271489f347f4a5aaf2ebceb8725316854c..e09a4765ea1aec60de5ad0a45c7987468fb5852e 100644 (file)
@@ -45,7 +45,7 @@
     "gzip-js": "0.3.2",
     "husky": "1.3.1",
     "insight": "0.10.1",
-    "jsdom": "5.6.1",
+    "jsdom": "13.2.0",
     "karma": "4.0.0",
     "karma-browserstack-launcher": "1.4.0",
     "karma-chrome-launcher": "2.2.0",
index c3924fbc637633869e5e7ce590644b30f1806d2d..2c724626fc0ab96285897d5f0717fc74d31ca2f3 100644 (file)
                // Not really too many - waiting for autofix features for these rules
                "lines-around-comment": "off",
                "dot-notation": "off"
-       }
+       },
+
+       "overrides": [
+               {
+                       "files": ["data/core/jquery-iterability-transpiled-es6.js"],
+                       "parserOptions": {
+                               "ecmaVersion": 2015
+                       }
+               }
+       ]
 }
diff --git a/test/data/core/jquery-iterability-transpiled-es6.js b/test/data/core/jquery-iterability-transpiled-es6.js
new file mode 100644 (file)
index 0000000..0c3bda6
--- /dev/null
@@ -0,0 +1,14 @@
+/* global startIframeTest */
+
+jQuery( function() {
+       "use strict";
+
+       var elem = jQuery( "<div></div><span></span><a></a>" );
+       var result = "";
+       var i;
+       for ( i of elem ) {
+               result += i.nodeName;
+       }
+
+       startIframeTest( result );
+} );
diff --git a/test/data/core/jquery-iterability-transpiled.html b/test/data/core/jquery-iterability-transpiled.html
new file mode 100644 (file)
index 0000000..69ac182
--- /dev/null
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+       <title>jQuery objects transpiled iterability test page</title>
+       <script src="../../../node_modules/core-js/client/core.min.js"></script>
+       <script src="../../jquery.js"></script>
+       <script src="../iframeTest.js"></script>
+       <script src="jquery-iterability-transpiled.js"></script>
+</head>
+<body>
+       <p>jQuery objects transpiled iterability test page</p>
+</body>
+</html>
index 348e9a4efa2759985da9aa735cb8da66ec6c220f..0f6a3f78b20c16f1ad5f07c4192368d4f7a55b8d 100644 (file)
@@ -1,10 +1,10 @@
 "use strict";
 
-var assert = require( "assert" ),
-       ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
-       jQueryFactory = require( "../../dist/jquery.js" );
+const assert = require( "assert" );
+const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" );
+const jQueryFactory = require( "../../dist/jquery.js" );
 
-assert.throws( function() {
+assert.throws( () => {
        jQueryFactory( {} );
 }, /jQuery requires a window with a document/ );
 
index 5999cc74410f015ca72441f60a20105f104b3107..b1154d3a31e809252c3b69f96a4a1af1f68b1570 100644 (file)
@@ -1,14 +1,12 @@
 "use strict";
 
-var assert = require( "assert" );
+const { JSDOM } = require( "jsdom" );
 
-require( "jsdom" ).env( "", function( errors, window ) {
-       assert.ifError( errors );
+const { window } = new JSDOM( "" );
 
-       var ensureJQuery = require( "./lib/ensure_jquery" ),
-               ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
-               jQuery = require( "../../dist/jquery.js" )( window );
+const ensureJQuery = require( "./lib/ensure_jquery" );
+const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" );
+const jQuery = require( "../../dist/jquery.js" )( window );
 
-       ensureJQuery( jQuery );
-       ensureGlobalNotCreated( module.exports );
-} );
+ensureJQuery( jQuery );
+ensureGlobalNotCreated( module.exports );
index f75148708073ab32ff772c1db0048c87f7516f8f..89b0c7bd87c83823ae5b1f38878d72cb1b2fc74e 100644 (file)
@@ -1,17 +1,15 @@
 "use strict";
 
-var assert = require( "assert" );
+const { JSDOM } = require( "jsdom" );
 
-require( "jsdom" ).env( "", function( errors, window ) {
-       assert.ifError( errors );
+const { window } = new JSDOM( "" );
 
-       // Pretend the window is a global.
-       global.window = window;
+// Pretend the window is a global.
+global.window = window;
 
-       var ensureJQuery = require( "./lib/ensure_jquery" ),
-               ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
-               jQuery = require( "../../dist/jquery.js" );
+const ensureJQuery = require( "./lib/ensure_jquery" );
+const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" );
+const jQuery = require( "../../dist/jquery.js" );
 
-       ensureJQuery( jQuery );
-       ensureGlobalNotCreated( module.exports, window );
-} );
+ensureJQuery( jQuery );
+ensureGlobalNotCreated( module.exports, window );
diff --git a/test/node_smoke_tests/iterable_with_symbol_polyfill.js b/test/node_smoke_tests/iterable_with_symbol_polyfill.js
deleted file mode 100644 (file)
index 34701d6..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-"use strict";
-
-var assert = require( "assert" );
-
-delete global.Symbol;
-require( "core-js" );
-
-assert.strictEqual( typeof Symbol, "function", "Expected Symbol to be a function" );
-assert.notEqual( typeof Symbol.iterator, "symbol", "Expected Symbol.iterator to be polyfilled" );
-
-require( "./lib/ensure_iterability" )();
index 7cc83b54110e9fcb62bdd586fbbf0994324b170a..95db622267070fbb6017ec5f419c85c4746c49c0 100644 (file)
@@ -1,15 +1,15 @@
 "use strict";
 
-var assert = require( "assert" );
+const assert = require( "assert" );
 
 // Ensure the jQuery property on global/window/module.exports/etc. was not
 // created in a CommonJS environment.
 // `global` is always checked in addition to passed parameters.
-module.exports = function ensureGlobalNotCreated() {
-       var args = [].slice.call( arguments ).concat( global );
-
-       args.forEach( function( object ) {
+const ensureGlobalNotCreated = ( ...args ) => {
+       [ ...args, global ].forEach( function( object ) {
                assert.strictEqual( object.jQuery, undefined,
                        "A jQuery global was created in a CommonJS environment." );
        } );
 };
+
+module.exports = ensureGlobalNotCreated;
index 4b30690a5bb05a9a4cf37d8a37a4ad789197fd24..a948f1996d9f04c48d96c0c210b7dc5fa33e81aa 100644 (file)
@@ -1,23 +1,25 @@
 "use strict";
 
-var assert = require( "assert" );
+const assert = require( "assert" );
 
-module.exports = function ensureIterability() {
-       require( "jsdom" ).env( "", function( errors, window ) {
-               assert.ifError( errors );
+const ensureIterability = () => {
+       const { JSDOM } = require( "jsdom" );
 
-               var i,
-                       ensureJQuery = require( "./ensure_jquery" ),
-                       jQuery = require( "../../../dist/jquery.js" )( window ),
-                       elem = jQuery( "<div></div><span></span><a></a>" ),
-                       result = "";
+       const { window } = new JSDOM( "" );
 
-               ensureJQuery( jQuery );
+       let i;
+       const ensureJQuery = require( "./ensure_jquery" );
+       const jQuery = require( "../../../dist/jquery.js" )( window );
+       const elem = jQuery( "<div></div><span></span><a></a>" );
+       let result = "";
 
-               for ( i of elem ) {
-                       result += i.nodeName;
-               }
+       ensureJQuery( jQuery );
 
-               assert.strictEqual( result, "DIVSPANA", "for-of works on jQuery objects" );
-       } );
+       for ( i of elem ) {
+               result += i.nodeName;
+       }
+
+       assert.strictEqual( result, "DIVSPANA", "for-of works on jQuery objects" );
 };
+
+module.exports = ensureIterability;
index 0933a1d3387f72c2254becc054d6a6da25cab4af..5b7c064f1408d59754e197a937808be199f9bbdd 100644 (file)
@@ -1,9 +1,11 @@
 "use strict";
 
-var assert = require( "assert" );
+const assert = require( "assert" );
 
 // Check if the object we got is the jQuery object by invoking a basic API.
-module.exports = function ensureJQuery( jQuery ) {
+const ensureJQuery = ( jQuery ) => {
        assert( /^jQuery/.test( jQuery.expando ),
                "jQuery.expando was not detected, the jQuery bootstrap process has failed" );
 };
+
+module.exports = ensureJQuery;
index 31af166556a8d0f40cf896f697a52bad80490bb5..5e3ffe2d854839545b0a9b53f1e661b408433d5a 100644 (file)
@@ -1,20 +1,17 @@
 "use strict";
 
-require( "jsdom" ).env( "", function( errors, window ) {
-       if ( errors ) {
-               console.error( errors );
-               return;
-       }
+const { JSDOM } = require( "jsdom" );
 
-       var jQuery = require( "../../" )( window );
+const { window } = new JSDOM( "" );
 
-       module.exports.deferred = function() {
-               var deferred = jQuery.Deferred();
+const jQuery = require( "../../" )( window );
 
-               return {
-                       promise: deferred.promise(),
-                       resolve: deferred.resolve.bind( deferred ),
-                       reject: deferred.reject.bind( deferred )
-               };
+module.exports.deferred = () => {
+       const deferred = jQuery.Deferred();
+
+       return {
+               promise: deferred.promise(),
+               resolve: deferred.resolve.bind( deferred ),
+               reject: deferred.reject.bind( deferred )
        };
-} );
+};
index adde1a13a6117136c9dcd065dc421e9172058761..3e945d47558e1991d2036ad0232cdb20c77b76de 100644 (file)
@@ -1,49 +1,45 @@
 "use strict";
 
-require( "jsdom" ).env( "", function( errors, window ) {
-       if ( errors ) {
-               console.error( errors );
-               return;
-       }
+const { JSDOM } = require( "jsdom" );
 
-       var jQuery = require( "../../" )( window );
+const { window } = new JSDOM( "" );
 
-       module.exports.deferred = function() {
-               var adopted, promised,
-                       obj = {
-                               resolve: function() {
-                                       if ( !adopted ) {
-                                               adopted = jQuery.when.apply( jQuery, arguments );
-                                               if ( promised ) {
-                                                       adopted.then( promised.resolve, promised.reject );
-                                               }
-                                       }
-                                       return adopted;
-                               },
-                               reject: function( value ) {
-                                       if ( !adopted ) {
-                                               adopted = jQuery.when( jQuery.Deferred().reject( value ) );
-                                               if ( promised ) {
-                                                       adopted.then( promised.resolve, promised.reject );
-                                               }
-                                       }
-                                       return adopted;
-                               },
+const jQuery = require( "../../" )( window );
 
-                               // A manually-constructed thenable that works even if calls precede resolve/reject
-                               promise: {
-                                       then: function() {
-                                               if ( !adopted ) {
-                                                       if ( !promised ) {
-                                                               promised = jQuery.Deferred();
-                                                       }
-                                                       return promised.then.apply( promised, arguments );
-                                               }
-                                               return adopted.then.apply( adopted, arguments );
-                                       }
+module.exports.deferred = () => {
+       let adopted, promised;
+
+       return {
+               resolve: function() {
+                       if ( !adopted ) {
+                               adopted = jQuery.when.apply( jQuery, arguments );
+                               if ( promised ) {
+                                       adopted.then( promised.resolve, promised.reject );
                                }
-                       };
+                       }
+                       return adopted;
+               },
+               reject: function( value ) {
+                       if ( !adopted ) {
+                               adopted = jQuery.when( jQuery.Deferred().reject( value ) );
+                               if ( promised ) {
+                                       adopted.then( promised.resolve, promised.reject );
+                               }
+                       }
+                       return adopted;
+               },
 
-               return obj;
+               // A manually-constructed thenable that works even if calls precede resolve/reject
+               promise: {
+                       then: function() {
+                               if ( !adopted ) {
+                                       if ( !promised ) {
+                                               promised = jQuery.Deferred();
+                                       }
+                                       return promised.then.apply( promised, arguments );
+                               }
+                               return adopted.then.apply( adopted, arguments );
+                       }
+               }
        };
-} );
+};
index 260038300c1db97909310076bbd9f8ec3e0a5f26..8205aa24255fb76e2d19c03e2aa95e0c3984dc0d 100644 (file)
@@ -1425,6 +1425,17 @@ QUnit.test( "Iterability of jQuery objects (gh-1693)", function( assert ) {
        }
 } );
 
+testIframe(
+       "Iterability of jQuery objects with Symbol polyfill (gh-1693)",
+       "core/jquery-iterability-transpiled.html",
+       function( assert, jQuery, window, document, testString ) {
+               assert.expect( 1 );
+
+               assert.strictEqual( testString, "DIVSPANA",
+                       "for-of works on jQuery objects with Symbol polyfilled" );
+       }
+);
+
 QUnit[ jQuery.Deferred ? "test" : "skip" ]( "jQuery.readyException (original)", function( assert ) {
        assert.expect( 1 );