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

🐛 Bug: Mocha loads incomplete Promise polyfill #4783

Closed
4 tasks done
straker opened this issue Nov 2, 2021 · 5 comments
Closed
4 tasks done

🐛 Bug: Mocha loads incomplete Promise polyfill #4783

straker opened this issue Nov 2, 2021 · 5 comments
Assignees
Labels
area: browser browser-specific semver-major implementation requires increase of "major" version number; "breaking changes" status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@straker
Copy link

straker commented Nov 2, 2021

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

I recently upgrade Mocha from v7 to latest and noticed that Mocha loads its own Promise polyfill. Unfortunately the polyfill is incomplete and does not implement Promise.finally and causes our tests to fail in IE11 (sorry, we can't drop support yet). We try to load es6-promise if we detect that Promise isn't already defined on window, but since Mocha loads first we detect that Promise exists and don't load our working polyfill.

I verified that the Promise polyfill is loaded starting in v8.1.0 and above.

With mocha on the page
image

Without mocha on the page
image

@straker straker changed the title Mocha ^8.1.0 loads incomplete Promise polyfill Mocha 8.1.0 and above loads incomplete Promise polyfill Nov 2, 2021
@juergba
Copy link
Contributor

juergba commented Nov 4, 2021

@straker is the first image from IE11? Showing "F12 Developer Tools" and "function Promise() { [native code] }?

Anyway I haven't reproduced your issue, because it's IE11 ...
In our Babel configuration we set useBuiltIns: 'usage', therefore only those polyfills are inserted which we are using in our Mocha code. And we haven't used Promise#finally() so far.
For testing I inserted a dummy finally() somewhere in runner.js and now the debug log of the build shows - besides es.promise - an additional es.promise.finally polyfill (both from core-js).

So I don't know how to proceed:

  • should Mocha add es.promise.finally, via a dummy finally() or evtl. via the include option?
  • could you check for window.Promise and window.Promise.finally and load your own polyfill?

@juergba juergba added the area: browser browser-specific label Nov 4, 2021
@juergba
Copy link
Contributor

juergba commented Nov 4, 2021

see also #4446

@straker
Copy link
Author

straker commented Nov 4, 2021

Thanks for the information. Yes the first image is from IE11 when mocha is loaded on the page. I'm not sure why core-js adds Promise as [native code], but it seems to.

Would it be possible import the core-js Promise polyfill in the mocha code where it's used and then use the non-global import? That might get around the global pollute.

import Promise from 'core-js-pure/features/promise';

@juergba
Copy link
Contributor

juergba commented Nov 4, 2021

I don't know, but by fixing "global Promise" only, the root problem still persists. There are dozens of other pollyfills loaded by Mocha.

There is this babel-polyfills package, which seems to offer an option "method": "usage-pure" in order to prevent global pollution. I think it relies on core-js-pure.

I would need some help on this issue. Maybe you know somebody, who could struggle through this transpiling challenge. We also have some funds to spend.

@juergba juergba added type: bug a defect, confirmed by a maintainer status: accepting prs Mocha can use your help with this one! and removed unconfirmed-bug labels Nov 4, 2021
@JoshuaKGoldberg JoshuaKGoldberg changed the title Mocha 8.1.0 and above loads incomplete Promise polyfill 🐛 Bug: Mocha 8.1.0 and above loads incomplete Promise polyfill Dec 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title 🐛 Bug: Mocha 8.1.0 and above loads incomplete Promise polyfill 🐛 Bug: Mocha loads incomplete Promise polyfill Dec 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg added the semver-major implementation requires increase of "major" version number; "breaking changes" label Mar 1, 2024
@JoshuaKGoldberg JoshuaKGoldberg added this to the v11.0.0 milestone Aug 6, 2024
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Sep 3, 2024
@JoshuaKGoldberg
Copy link
Member

There's no longer any code specific to Promises in rollup.config.js, nor core-js referenced anywhere in config files or project code. I think this was resolved by #4848. 🚀

@JoshuaKGoldberg JoshuaKGoldberg removed this from the v11.0.0 milestone Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: browser browser-specific semver-major implementation requires increase of "major" version number; "breaking changes" status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants