-
Notifications
You must be signed in to change notification settings - Fork 781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Remove inArray with native array.includes() #1695
Conversation
@izelnakri We've discussed raising Node.js requirements for for QUnit 3, but not yet browser support. I think we could consider dropping support for IE10 and below (depends on the benefit, I'd still prefer we include a fallback and reap the perf benefits at runtime and accept increases in QUnit transfer size). However jQuery, WordPress, and Wikimedia all still support IE11 and even if they drop it today it will be a few years before their LTSes expire where I'd prefer to offer them latest QUnit as well (instead of e.g. maintaining support for QUnit 2.x as I'd prefer not to maintain multiple branches). I'm confident that apart from certain startup costs, any major runtime perf benefits we should be able to achieve even with a fallback in place. For this one, we could conditionally define |
@Krinkle I agree with your points, in a new PR I introduced significant performance improvements by assuming non-IE browser support(particularly using This could be a strong case for an optional polyfill inclusion, lets discuss it in this thread if you like ;) |
No problem. Let's take a sidebar here. The topic of polyfills has come up before. I've generally been of the opinion that we shouldn't embed polyfills in QUnit because it changes global state. This is particularly problematic at the unit test layer when QUnit is used by projects such as jQuery and Lodash (which are to some extent kind a polyfill themselves, to normalise differences between browsers), and even actual polyfill projects like core-js (which uses QUnit) or es5-shim and FT polyfill-library (which use Karma with a different unit testing framework). Having said that, we do have a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per previous comments
I just added a file for simple array polyfills, however it is not imported/used by any of the qunit code yet. Feel free to edit the build system/files to add it to runtime anyway you like. Also I added a note for Array.from, this polyfill seems to be complex and we might want to use an npm package like |
If the take the same approach here in Something like this: - export function inArray (elem, array) {
- return array.indexOf(elem) !== -1;
- }
+ export const inArray = Array.prototype.includes
+ ? (elem, array) => array.includes(elem)
+ : (elem, array) => array.indexOf(elem) !== -1; I don't see a way to incorporate a polyfill directly, but either way it seems simpler to maintain inline I think. I'd be fine with additional ones being added like this if you see a use for other ES6+ array methods that some browsers don't support. I noticed that the polyfill file in this PR also includes |
Hi @Krinkle ! It's been 5 months since my last comment so it took me a while to get the context 😅 I agree with both points and making the adjustments now. |
479958a
to
0a23e45
Compare
0a23e45
to
fc85130
Compare
I made the requested changes, while implementing I remembered one of my intentions were to keep the code more readable by removing the inArray wrapper references. We could achieve this by: Array.prototype.includes = Array.prototype.includes || function (elem) {
return this.indexOf(elem) !== -1;
}; and then remove the inArray references. What do you think? |
That's how I'd do it in any regular web app indeed, but we can't in a testing library like QUnit. As per #1695 (comment), doing so leaks into global state, thus changing or making impossible the testing of libraries that themselves involve such conditions. E.g. if you maintian a library that does what we do in QUnit ( |
@Krinkle I see. Although I don't see this being practically as important given the probability and the state of this issue, I'm willing to keep it as it is and not do it :) Let me know if anything else is needed, cheers! |
While reading the source code I realized this internal function isn't needed anymore if we drop the IE support:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes#browser_compatibility