mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Build: Update jsdom; migrate a test with Symbol polyfill to an iframe test
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
This commit is contained in:
parent
c10945d0e1
commit
9cb124ed00
@ -11,4 +11,4 @@ test/data/readywaitasset.js
|
|||||||
test/data/readywaitloader.js
|
test/data/readywaitloader.js
|
||||||
test/data/support/csp.js
|
test/data/support/csp.js
|
||||||
test/data/support/getComputedSupport.js
|
test/data/support/getComputedSupport.js
|
||||||
test/node_smoke_tests/lib/ensure_iterability.js
|
test/data/core/jquery-iterability-transpiled.js
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
"extends": "jquery",
|
"extends": "jquery",
|
||||||
|
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 5
|
"ecmaVersion": 2017
|
||||||
},
|
},
|
||||||
|
|
||||||
"env": {
|
"env": {
|
||||||
|
"es6": true,
|
||||||
"node": true
|
"node": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -18,4 +18,4 @@ npm-debug.log*
|
|||||||
|
|
||||||
/node_modules
|
/node_modules
|
||||||
|
|
||||||
/test/node_smoke_tests/lib/ensure_iterability.js
|
/test/data/core/jquery-iterability-transpiled.js
|
||||||
|
@ -42,8 +42,8 @@ module.exports = function( grunt ) {
|
|||||||
},
|
},
|
||||||
nodeSmokeTests: {
|
nodeSmokeTests: {
|
||||||
files: {
|
files: {
|
||||||
"test/node_smoke_tests/lib/ensure_iterability.js":
|
"test/data/core/jquery-iterability-transpiled.js":
|
||||||
"test/node_smoke_tests/lib/ensure_iterability_es6.js"
|
"test/data/core/jquery-iterability-transpiled-es6.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
module.exports = function( grunt ) {
|
module.exports = ( grunt ) => {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var fs = require( "fs" ),
|
const fs = require( "fs" );
|
||||||
spawnTest = require( "./lib/spawn_test.js" ),
|
const spawnTest = require( "./lib/spawn_test.js" );
|
||||||
testsDir = "./test/node_smoke_tests/",
|
const testsDir = "./test/node_smoke_tests/";
|
||||||
nodeSmokeTests = [ "babel:nodeSmokeTests" ];
|
const nodeSmokeTests = [ "babel:nodeSmokeTests" ];
|
||||||
|
|
||||||
// Fire up all tests defined in test/node_smoke_tests/*.js in spawned sub-processes.
|
// 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
|
// 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.
|
// each other, e.g. so that they don't share the require cache.
|
||||||
|
|
||||||
fs.readdirSync( testsDir )
|
fs.readdirSync( testsDir )
|
||||||
.filter( function( testFilePath ) {
|
.filter( ( testFilePath ) =>
|
||||||
return fs.statSync( testsDir + testFilePath ).isFile() &&
|
fs.statSync( testsDir + testFilePath ).isFile() &&
|
||||||
/\.js$/.test( testFilePath );
|
/\.js$/.test( testFilePath )
|
||||||
} )
|
)
|
||||||
.forEach( function( testFilePath ) {
|
.forEach( ( testFilePath ) => {
|
||||||
var taskName = "node_" + testFilePath.replace( /\.js$/, "" );
|
const taskName = `node_${ testFilePath.replace( /\.js$/, "" ) }`;
|
||||||
|
|
||||||
grunt.registerTask( taskName, function() {
|
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 );
|
nodeSmokeTests.push( taskName );
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
"gzip-js": "0.3.2",
|
"gzip-js": "0.3.2",
|
||||||
"husky": "1.3.1",
|
"husky": "1.3.1",
|
||||||
"insight": "0.10.1",
|
"insight": "0.10.1",
|
||||||
"jsdom": "5.6.1",
|
"jsdom": "13.2.0",
|
||||||
"karma": "4.0.0",
|
"karma": "4.0.0",
|
||||||
"karma-browserstack-launcher": "1.4.0",
|
"karma-browserstack-launcher": "1.4.0",
|
||||||
"karma-chrome-launcher": "2.2.0",
|
"karma-chrome-launcher": "2.2.0",
|
||||||
|
@ -51,5 +51,14 @@
|
|||||||
// Not really too many - waiting for autofix features for these rules
|
// Not really too many - waiting for autofix features for these rules
|
||||||
"lines-around-comment": "off",
|
"lines-around-comment": "off",
|
||||||
"dot-notation": "off"
|
"dot-notation": "off"
|
||||||
|
},
|
||||||
|
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["data/core/jquery-iterability-transpiled-es6.js"],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2015
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
14
test/data/core/jquery-iterability-transpiled-es6.js
vendored
Normal file
14
test/data/core/jquery-iterability-transpiled-es6.js
vendored
Normal file
@ -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 );
|
||||||
|
} );
|
14
test/data/core/jquery-iterability-transpiled.html
Normal file
14
test/data/core/jquery-iterability-transpiled.html
Normal file
@ -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>
|
@ -1,10 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var assert = require( "assert" ),
|
const assert = require( "assert" );
|
||||||
ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
|
const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" );
|
||||||
jQueryFactory = require( "../../dist/jquery.js" );
|
const jQueryFactory = require( "../../dist/jquery.js" );
|
||||||
|
|
||||||
assert.throws( function() {
|
assert.throws( () => {
|
||||||
jQueryFactory( {} );
|
jQueryFactory( {} );
|
||||||
}, /jQuery requires a window with a document/ );
|
}, /jQuery requires a window with a document/ );
|
||||||
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var assert = require( "assert" );
|
const { JSDOM } = require( "jsdom" );
|
||||||
|
|
||||||
require( "jsdom" ).env( "", function( errors, window ) {
|
const { window } = new JSDOM( "" );
|
||||||
assert.ifError( errors );
|
|
||||||
|
|
||||||
var ensureJQuery = require( "./lib/ensure_jquery" ),
|
const ensureJQuery = require( "./lib/ensure_jquery" );
|
||||||
ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
|
const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" );
|
||||||
jQuery = require( "../../dist/jquery.js" )( window );
|
const jQuery = require( "../../dist/jquery.js" )( window );
|
||||||
|
|
||||||
ensureJQuery( jQuery );
|
ensureJQuery( jQuery );
|
||||||
ensureGlobalNotCreated( module.exports );
|
ensureGlobalNotCreated( module.exports );
|
||||||
} );
|
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var assert = require( "assert" );
|
const { JSDOM } = require( "jsdom" );
|
||||||
|
|
||||||
require( "jsdom" ).env( "", function( errors, window ) {
|
const { window } = new JSDOM( "" );
|
||||||
assert.ifError( errors );
|
|
||||||
|
|
||||||
// Pretend the window is a global.
|
// Pretend the window is a global.
|
||||||
global.window = window;
|
global.window = window;
|
||||||
|
|
||||||
var ensureJQuery = require( "./lib/ensure_jquery" ),
|
const ensureJQuery = require( "./lib/ensure_jquery" );
|
||||||
ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
|
const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" );
|
||||||
jQuery = require( "../../dist/jquery.js" );
|
const jQuery = require( "../../dist/jquery.js" );
|
||||||
|
|
||||||
ensureJQuery( jQuery );
|
ensureJQuery( jQuery );
|
||||||
ensureGlobalNotCreated( module.exports, window );
|
ensureGlobalNotCreated( module.exports, window );
|
||||||
} );
|
|
||||||
|
@ -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" )();
|
|
@ -1,15 +1,15 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var assert = require( "assert" );
|
const assert = require( "assert" );
|
||||||
|
|
||||||
// Ensure the jQuery property on global/window/module.exports/etc. was not
|
// Ensure the jQuery property on global/window/module.exports/etc. was not
|
||||||
// created in a CommonJS environment.
|
// created in a CommonJS environment.
|
||||||
// `global` is always checked in addition to passed parameters.
|
// `global` is always checked in addition to passed parameters.
|
||||||
module.exports = function ensureGlobalNotCreated() {
|
const ensureGlobalNotCreated = ( ...args ) => {
|
||||||
var args = [].slice.call( arguments ).concat( global );
|
[ ...args, global ].forEach( function( object ) {
|
||||||
|
|
||||||
args.forEach( function( object ) {
|
|
||||||
assert.strictEqual( object.jQuery, undefined,
|
assert.strictEqual( object.jQuery, undefined,
|
||||||
"A jQuery global was created in a CommonJS environment." );
|
"A jQuery global was created in a CommonJS environment." );
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = ensureGlobalNotCreated;
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var assert = require( "assert" );
|
const assert = require( "assert" );
|
||||||
|
|
||||||
module.exports = function ensureIterability() {
|
const ensureIterability = () => {
|
||||||
require( "jsdom" ).env( "", function( errors, window ) {
|
const { JSDOM } = require( "jsdom" );
|
||||||
assert.ifError( errors );
|
|
||||||
|
|
||||||
var i,
|
const { window } = new JSDOM( "" );
|
||||||
ensureJQuery = require( "./ensure_jquery" ),
|
|
||||||
jQuery = require( "../../../dist/jquery.js" )( window ),
|
let i;
|
||||||
elem = jQuery( "<div></div><span></span><a></a>" ),
|
const ensureJQuery = require( "./ensure_jquery" );
|
||||||
result = "";
|
const jQuery = require( "../../../dist/jquery.js" )( window );
|
||||||
|
const elem = jQuery( "<div></div><span></span><a></a>" );
|
||||||
|
let result = "";
|
||||||
|
|
||||||
ensureJQuery( jQuery );
|
ensureJQuery( jQuery );
|
||||||
|
|
||||||
@ -19,5 +20,6 @@ module.exports = function ensureIterability() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert.strictEqual( result, "DIVSPANA", "for-of works on jQuery objects" );
|
assert.strictEqual( result, "DIVSPANA", "for-of works on jQuery objects" );
|
||||||
} );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = ensureIterability;
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
"use strict";
|
"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.
|
// 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 ),
|
assert( /^jQuery/.test( jQuery.expando ),
|
||||||
"jQuery.expando was not detected, the jQuery bootstrap process has failed" );
|
"jQuery.expando was not detected, the jQuery bootstrap process has failed" );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = ensureJQuery;
|
||||||
|
@ -1,20 +1,17 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require( "jsdom" ).env( "", function( errors, window ) {
|
const { JSDOM } = require( "jsdom" );
|
||||||
if ( errors ) {
|
|
||||||
console.error( errors );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var jQuery = require( "../../" )( window );
|
const { window } = new JSDOM( "" );
|
||||||
|
|
||||||
module.exports.deferred = function() {
|
const jQuery = require( "../../" )( window );
|
||||||
var deferred = jQuery.Deferred();
|
|
||||||
|
module.exports.deferred = () => {
|
||||||
|
const deferred = jQuery.Deferred();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
promise: deferred.promise(),
|
promise: deferred.promise(),
|
||||||
resolve: deferred.resolve.bind( deferred ),
|
resolve: deferred.resolve.bind( deferred ),
|
||||||
reject: deferred.reject.bind( deferred )
|
reject: deferred.reject.bind( deferred )
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
} );
|
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require( "jsdom" ).env( "", function( errors, window ) {
|
const { JSDOM } = require( "jsdom" );
|
||||||
if ( errors ) {
|
|
||||||
console.error( errors );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var jQuery = require( "../../" )( window );
|
const { window } = new JSDOM( "" );
|
||||||
|
|
||||||
module.exports.deferred = function() {
|
const jQuery = require( "../../" )( window );
|
||||||
var adopted, promised,
|
|
||||||
obj = {
|
module.exports.deferred = () => {
|
||||||
|
let adopted, promised;
|
||||||
|
|
||||||
|
return {
|
||||||
resolve: function() {
|
resolve: function() {
|
||||||
if ( !adopted ) {
|
if ( !adopted ) {
|
||||||
adopted = jQuery.when.apply( jQuery, arguments );
|
adopted = jQuery.when.apply( jQuery, arguments );
|
||||||
@ -43,7 +42,4 @@ require( "jsdom" ).env( "", function( errors, window ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
};
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
} );
|
|
||||||
|
@ -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 ) {
|
QUnit[ jQuery.Deferred ? "test" : "skip" ]( "jQuery.readyException (original)", function( assert ) {
|
||||||
assert.expect( 1 );
|
assert.expect( 1 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user