Skip to content
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

Fix .includes issue once and for all #3693

Closed
bestander opened this issue Jun 22, 2017 · 15 comments
Closed

Fix .includes issue once and for all #3693

bestander opened this issue Jun 22, 2017 · 15 comments

Comments

@bestander
Copy link
Member

Do you want to request a feature or report a bug?
Node 4 compat issue

What is the current behavior?

  1. Jest tests on Node 4 don't catch compatibility issues like having .includes in -legacy.js builds.
  2. We need to include proper polyfil for Node 4
@Volune
Copy link
Contributor

Volune commented Jun 22, 2017

The simple way would be to add a dependency to babel-polyfill and require it at the beginning.

Node 4 already supports several ES6 features (compatibility table). I think it would be better to add a dependency to core-js, and only require the necessary polyfills.

core-js is internally used by babel-polyfill and babel-runtime. babel-runtime is already used in Yarn, but does not handle instance functions such as Array.prototype.includes.

@bestander
Copy link
Member Author

@Volune, would you send a PR for that please?

@kaylie-alexa
Copy link
Member

I also think that babel-polyfill is quite heavy, if you want to fix just .includes issue, then we should use airbnb's .includes polyfill https://www.npmjs.com/package/array-includes.

@bestander
Copy link
Member Author

bestander commented Jun 23, 2017 via email

@kaylie-alexa
Copy link
Member

hm, looking at babelrc
it looks like jest already runs without the polyfill? I actually think we just need to add a plugin
to the pre-node setting. Happy to send a PR.

@bestander
Copy link
Member Author

bestander commented Jun 23, 2017 via email

@kaylie-alexa
Copy link
Member

Thanks! #3705

@Volune
Copy link
Contributor

Volune commented Jun 23, 2017

I think we should have a look at babel-preset-env to fix all similar potential issues at once.

@voxsim
Copy link
Contributor

voxsim commented Jun 23, 2017

@bestander here, #3652, I upgraded babel and used babel-preset-env.. If you want I can move some commits and arrange a pull request for the next week. This is propedeutic for the new release of Jest too.
I saw the pull request #3705 and imho we should avoid include babel plugins that are not followed and upgraded as well, otherwise next upgrades can be a nightmare O.o
If we want to transpile for node 4 we should do what @Volune says, btw there will be always some pitfalls for what I understand (I read the readme of https://www.npmjs.com/package/babel-plugin-array-includes and the discussion here avajs/ava#263, very interesting) and I think we should avoid Array.prototype.includes in both src and tests files and just write a function includes in our code :P

@bestander
Copy link
Member Author

Thanks for chiming in @voxsim.

A few points.

  1. I think it is bad to allow Node 4 to hold us back.

  2. Jest in Node 4 mode should run with the same babel settings as production builds of Yarn.
    Otherwise there is less value in testing in Node 4.
    However I understand there may be some configuration cost to this.

  3. Could you explain what is the problem with babel-preset-env?

@kaylie-alexa
Copy link
Member

@voxsim I agree we should move to babel-preset-env regardless of support for .includes, to be futureproof. Per the original issue, the only way to use .includes is to include babel-polyfill or a syntax plugin like the one I added, and preset-env doesn't provide it out of the box. But the use of BuiltIns looks promising https://babeljs.io/docs/plugins/preset-env/#optionsuse-built-ins. It will conditionally require the needed polyfills base on the environment using babel-polyfill, so maybe we can get both?

@voxsim
Copy link
Contributor

voxsim commented Jul 1, 2017

@kaylieEB @bestander I opened a pull request with an experiment that seems to work O.o I am using babel-polyfill and babel-preset-env, please let me know if you like it :)

@bestander
Copy link
Member Author

❤️

@BYK
Copy link
Member

BYK commented Jul 5, 2017

@bestander - I think we can close this issue now? Since Node 4 is an LTS and will be maintained until April 2018, I'd say we should support it. At least until 1.0 is out. I think the polyfill is a bit heavy handed and now CI should catch the issues so no further action needed?

@BYK BYK removed the high-priority label Jul 5, 2017
@bestander
Copy link
Member Author

Up to you, @BYK.
The issue is at least mitigated.
Personally I'd like to be able to use .includes in the code one way or the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants