Skip to content

Commit 9cb124e

Browse files
authored
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 jquerygh-4305
1 parent c10945d commit 9cb124e

19 files changed

+162
-131
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ test/data/readywaitasset.js
1111
test/data/readywaitloader.js
1212
test/data/support/csp.js
1313
test/data/support/getComputedSupport.js
14-
test/node_smoke_tests/lib/ensure_iterability.js
14+
test/data/core/jquery-iterability-transpiled.js

.eslintrc-node.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"extends": "jquery",
55

66
"parserOptions": {
7-
"ecmaVersion": 5
7+
"ecmaVersion": 2017
88
},
99

1010
"env": {
11+
"es6": true,
1112
"node": true
1213
}
1314
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ npm-debug.log*
1818

1919
/node_modules
2020

21-
/test/node_smoke_tests/lib/ensure_iterability.js
21+
/test/data/core/jquery-iterability-transpiled.js

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module.exports = function( grunt ) {
4242
},
4343
nodeSmokeTests: {
4444
files: {
45-
"test/node_smoke_tests/lib/ensure_iterability.js":
46-
"test/node_smoke_tests/lib/ensure_iterability_es6.js"
45+
"test/data/core/jquery-iterability-transpiled.js":
46+
"test/data/core/jquery-iterability-transpiled-es6.js"
4747
}
4848
}
4949
},

build/tasks/node_smoke_tests.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
module.exports = function( grunt ) {
1+
module.exports = ( grunt ) => {
22

33
"use strict";
44

5-
var fs = require( "fs" ),
6-
spawnTest = require( "./lib/spawn_test.js" ),
7-
testsDir = "./test/node_smoke_tests/",
8-
nodeSmokeTests = [ "babel:nodeSmokeTests" ];
5+
const fs = require( "fs" );
6+
const spawnTest = require( "./lib/spawn_test.js" );
7+
const testsDir = "./test/node_smoke_tests/";
8+
const nodeSmokeTests = [ "babel:nodeSmokeTests" ];
99

1010
// Fire up all tests defined in test/node_smoke_tests/*.js in spawned sub-processes.
1111
// All the files under test/node_smoke_tests/*.js are supposed to exit with 0 code
@@ -14,15 +14,15 @@ module.exports = function( grunt ) {
1414
// each other, e.g. so that they don't share the require cache.
1515

1616
fs.readdirSync( testsDir )
17-
.filter( function( testFilePath ) {
18-
return fs.statSync( testsDir + testFilePath ).isFile() &&
19-
/\.js$/.test( testFilePath );
20-
} )
21-
.forEach( function( testFilePath ) {
22-
var taskName = "node_" + testFilePath.replace( /\.js$/, "" );
17+
.filter( ( testFilePath ) =>
18+
fs.statSync( testsDir + testFilePath ).isFile() &&
19+
/\.js$/.test( testFilePath )
20+
)
21+
.forEach( ( testFilePath ) => {
22+
const taskName = `node_${ testFilePath.replace( /\.js$/, "" ) }`;
2323

2424
grunt.registerTask( taskName, function() {
25-
spawnTest( this.async(), "node \"test/node_smoke_tests/" + testFilePath + "\"" );
25+
spawnTest( this.async(), `node "test/node_smoke_tests/${ testFilePath }"` );
2626
} );
2727

2828
nodeSmokeTests.push( taskName );

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"gzip-js": "0.3.2",
4646
"husky": "1.3.1",
4747
"insight": "0.10.1",
48-
"jsdom": "5.6.1",
48+
"jsdom": "13.2.0",
4949
"karma": "4.0.0",
5050
"karma-browserstack-launcher": "1.4.0",
5151
"karma-chrome-launcher": "2.2.0",

test/.eslintrc.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,14 @@
5151
// Not really too many - waiting for autofix features for these rules
5252
"lines-around-comment": "off",
5353
"dot-notation": "off"
54-
}
54+
},
55+
56+
"overrides": [
57+
{
58+
"files": ["data/core/jquery-iterability-transpiled-es6.js"],
59+
"parserOptions": {
60+
"ecmaVersion": 2015
61+
}
62+
}
63+
]
5564
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* global startIframeTest */
2+
3+
jQuery( function() {
4+
"use strict";
5+
6+
var elem = jQuery( "<div></div><span></span><a></a>" );
7+
var result = "";
8+
var i;
9+
for ( i of elem ) {
10+
result += i.nodeName;
11+
}
12+
13+
startIframeTest( result );
14+
} );
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<title>jQuery objects transpiled iterability test page</title>
6+
<script src="../../../node_modules/core-js/client/core.min.js"></script>
7+
<script src="../../jquery.js"></script>
8+
<script src="../iframeTest.js"></script>
9+
<script src="jquery-iterability-transpiled.js"></script>
10+
</head>
11+
<body>
12+
<p>jQuery objects transpiled iterability test page</p>
13+
</body>
14+
</html>

test/node_smoke_tests/document_missing.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use strict";
22

3-
var assert = require( "assert" ),
4-
ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ),
5-
jQueryFactory = require( "../../dist/jquery.js" );
3+
const assert = require( "assert" );
4+
const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" );
5+
const jQueryFactory = require( "../../dist/jquery.js" );
66

7-
assert.throws( function() {
7+
assert.throws( () => {
88
jQueryFactory( {} );
99
}, /jQuery requires a window with a document/ );
1010

0 commit comments

Comments
 (0)