Skip to content

Commit 6899813

Browse files
committed
Tests: Make selector-native tests work again
Backport some changes from gh-5085 to make selector-native tests pass. Plus a few other fixes.
1 parent a214a89 commit 6899813

File tree

6 files changed

+41
-27
lines changed

6 files changed

+41
-27
lines changed

.github/workflows/node.js.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525
NODE_VERSION: "16.x"
2626
NPM_SCRIPT: "test:no-deprecated"
2727
BROWSERS: "ChromeHeadless"
28-
- NAME: "Browser tests: no-Sizzle build, Chrome stable"
28+
- NAME: "Browser tests: selector-native build, Chrome stable"
2929
NODE_VERSION: "16.x"
30-
NPM_SCRIPT: "test:no-sizzle"
30+
NPM_SCRIPT: "test:selector-native"
3131
BROWSERS: "ChromeHeadless"
3232
- NAME: "Browser tests: AMD build, Chrome stable"
3333
NODE_VERSION: "16.x"

build/tasks/build.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,19 @@ module.exports = function( grunt ) {
171171
* Adds the specified module to the excluded or included list, depending on the flag
172172
* @param {String} flag A module path relative to
173173
* the src directory starting with + or - to indicate
174-
* whether it should included or excluded
174+
* whether it should be included or excluded
175175
*/
176176
excluder = function( flag ) {
177177
var additional,
178-
m = /^(\+|\-|)([\w\/-]+)$/.exec( flag ),
178+
m = /^(\+|-|)([\w\/-]+)$/.exec( flag ),
179179
exclude = m[ 1 ] === "-",
180180
module = m[ 2 ];
181181

182+
// Recognize the legacy `sizzle` alias
183+
if ( module === "sizzle" ) {
184+
module = "selector-full";
185+
}
186+
182187
if ( exclude ) {
183188

184189
// Can't exclude certain modules
@@ -255,12 +260,8 @@ module.exports = function( grunt ) {
255260

256261
// Handle full selector module exclusion.
257262
// Replace with selector-native.
258-
// Recognize the legacy `sizzle` alias
259-
if ( ( index = excluded.indexOf( "selector-full" ) ) > -1 ||
260-
( index = excluded.indexOf( "sizzle" ) ) > -1
261-
) {
263+
if ( ( index = excluded.indexOf( "selector-full" ) ) > -1 ) {
262264
config.rawText.selector = "define(['./selector-native']);";
263-
excluded.splice( index, 1 );
264265
}
265266

266267
// Replace exports/global with a noop noConflict

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
"test:browser": "grunt && grunt karma:main",
7373
"test:amd": "grunt && grunt karma:amd",
7474
"test:no-deprecated": "grunt test:prepare && grunt custom:-deprecated && grunt karma:main",
75-
"test:no-sizzle": "grunt test:prepare && grunt custom:-sizzle && grunt karma:main",
75+
"test:selector-native": "grunt test:prepare && grunt custom:-selector-full && grunt karma:main",
7676
"test:slim": "grunt test:prepare && grunt custom:slim && grunt karma:main",
77-
"test": "npm run test:slim && npm run test:no-deprecated && npm run test:no-sizzle && grunt && grunt test:slow && grunt karma:main && grunt karma:amd",
77+
"test": "npm run test:slim && npm run test:no-deprecated && npm run test:selector-native && grunt && grunt test:slow && grunt karma:main && grunt karma:amd",
7878
"jenkins": "npm run test:browserless"
7979
},
8080
"commitplease": {

test/data/testinit.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,6 @@ if ( !window.__karma__ ) {
332332
QUnit.isSwarm = ( QUnit.urlParams.swarmURL + "" ).indexOf( "http" ) === 0;
333333
QUnit.basicTests = ( QUnit.urlParams.module + "" ) === "basic";
334334

335-
// Says whether jQuery positional selector extensions are supported.
336-
// A full selector engine is required to support them as they need to be evaluated
337-
// left-to-right. Remove that property when support for positional selectors is dropped.
338-
// if your custom jQuery versions relies more on native qSA.
339-
QUnit.jQuerySelectorsPos = true;
340-
341-
// Says whether jQuery selector extensions are supported. Change that to `false`
342-
// if your custom jQuery versions relies more on native qSA.
343-
// This doesn't include support for positional selectors (see above).
344-
// TODO do we want to keep this or just assume support for jQuery extensions?
345-
QUnit.jQuerySelectors = true;
346-
347335
// Async test for module script type support
348336
function moduleTypeSupported() {
349337
var script = document.createElement( "script" );
@@ -481,6 +469,17 @@ this.loadTests = function() {
481469
*/
482470
jQuery.noConflict();
483471

472+
// Says whether jQuery positional selector extensions are supported.
473+
// A full selector engine is required to support them as they need to
474+
// be evaluated left-to-right. Remove that property when support for
475+
// positional selectors is dropped.
476+
QUnit.jQuerySelectorsPos = includesModule( "selector-full" );
477+
478+
// Says whether jQuery selector extensions are supported. Change that
479+
// to `false` if your custom jQuery versions relies more on native qSA.
480+
// This doesn't include support for positional selectors (see above).
481+
QUnit.jQuerySelectors = includesModule( "selector-full" );
482+
484483
// Load the TestSwarm listener if swarmURL is in the address.
485484
if ( QUnit.isSwarm ) {
486485
require( [ "https://swarm.jquery.org/js/inject.js?" + ( new Date() ).getTime() ],

test/unit/selector.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
QUnit.module( "selector", {
22
beforeEach: function() {
33
this.safari = /\bsafari\b/i.test( navigator.userAgent ) &&
4-
!/\bchrome\b/i.test( navigator.userAgent );
4+
!/\b(?:headless)?chrome\b/i.test( navigator.userAgent );
55
},
66
afterEach: moduleTeardown
77
} );
@@ -1935,7 +1935,9 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
19351935
}
19361936
}
19371937
Arrayish.prototype = {
1938-
sliceForTestOnly: [].slice
1938+
slice: [].slice,
1939+
sort: [].sort,
1940+
splice: [].splice
19391941
};
19401942

19411943
var i, tests,
@@ -2001,7 +2003,7 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
20012003
// and the second test becomes worthless.
20022004
assert.deepEqual( jQuery.uniqueSort( test.input.slice( 0 ) ).slice( 0, length ),
20032005
test.expected, label + " (array)" );
2004-
assert.deepEqual( jQuery.uniqueSort( new Arrayish( test.input ) ).sliceForTestOnly( 0, length ),
2006+
assert.deepEqual( jQuery.uniqueSort( new Arrayish( test.input ) ).slice( 0, length ),
20052007
test.expected, label + " (quasi-array)" );
20062008
} );
20072009
} );

test/unit/support.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,24 @@ testIframe(
387387

388388
// Make the slim build pass tests.
389389
for ( browserKey in expectedMap ) {
390-
if ( !jQuery.ajax ) {
390+
if ( !includesModule( "ajax" ) ) {
391391
delete expectedMap[ browserKey ].ajax;
392392
delete expectedMap[ browserKey ].cors;
393393
}
394394
}
395395

396+
// Make the selector-native build pass tests.
397+
for ( browserKey in expectedMap ) {
398+
if ( !includesModule( "selector-full" ) ) {
399+
delete expectedMap[ browserKey ].cssSupportsSelector;
400+
delete expectedMap[ browserKey ].disconnectedMatch;
401+
delete expectedMap[ browserKey ].getById;
402+
delete expectedMap[ browserKey ].scope;
403+
delete expectedMap[ browserKey ].sortDetached;
404+
delete expectedMap[ browserKey ].sortStable;
405+
}
406+
}
407+
396408
if ( /edge\//i.test( userAgent ) ) {
397409
expected = expectedMap.edge;
398410
} else if ( /(msie 10\.0|trident\/7\.0)/i.test( userAgent ) ) {

0 commit comments

Comments
 (0)