ember-cli-babel icon indicating copy to clipboard operation
ember-cli-babel copied to clipboard

tests.js seems to not get Promise polyfilled for IE11 target

Open raido opened this issue 6 years ago • 15 comments

Ember-CLI v3.5.0, latest ember-cli-babel v6.

function _asyncToGenerator(fn) {
    return function () {
      var gen = fn.apply(this, arguments);
      return new Promise(function (resolve, reject) {
        function step(key, arg) {

tests.js contains code like this, which obviously won't run on IE11. By adding Promise polyfill to tests/index.html all my tests pass. So rest of the application is correctly transpiled for IE11 target.

raido avatar Nov 03 '18 19:11 raido

For now I did something like this in tests/index.html

<script type="text/javascript">
      if (!window.Promise) {
        window.Promise = Ember.RSVP.Promise;
      }
</script>

raido avatar Nov 03 '18 20:11 raido

What does your config/targets.js looks like?

rwjblue avatar Nov 03 '18 20:11 rwjblue

Default:

'use strict';

const browsers = [
  'last 1 Chrome versions',
  'last 1 Firefox versions',
  'last 1 Safari versions'
];

const isCI = !!process.env.CI;
const isProduction = process.env.EMBER_ENV === 'production';

if (isCI || isProduction) {
  browsers.push('ie 11');
}

module.exports = {
  browsers
};

raido avatar Nov 03 '18 20:11 raido

And is this in development or production (or CI)?

rwjblue avatar Nov 03 '18 21:11 rwjblue

CI=true ember serve and CI=true ember test both behave the same.

raido avatar Nov 03 '18 21:11 raido

Are you using async/await?

rwjblue avatar Nov 03 '18 23:11 rwjblue

Does an ember new foo type app have this issue? If not, what addon (or other changes) is needed to replicate?

rwjblue avatar Nov 03 '18 23:11 rwjblue

Steps to reproduce:

  1. ember new foo
  2. ember generate acceptance-test foo (simple await visit() test)
  3. CI=true ember serve
  4. Navigate to http://localhost:4200/tests with IE11 - ReferenceError: Promise is not defined

raido avatar Nov 04 '18 06:11 raido

Example from “ember new foo” - https://gist.github.com/raido/8b71ffc275c261b302ae638658b6bd9c

raido avatar Nov 05 '18 04:11 raido

@rwjblue any updates on this?

raido avatar Nov 24 '18 11:11 raido

Could reproduce this bug for a newly created addon using latest ember-cli (3.8.1):

  • ember addon my-addon
  • cd my-addon
  • ember generate acceptance-test foo # creates a test using async / await
  • CI=true ember serve
  • Open http://localhost:4200/tests in IE 11.

You will see ReferenceError: Promise is not defined as reported already for applications some while ago. It's not only affecting Promise but that's only the first issue you will run into. Having used the work-a-round provided by @raido I got a Symbol is not defined error caused by the result of transpiling a for...of statement.

I've faced this one while working on ember-power-calendar. You could use that one as a real-world showcase for the bug.

jelhan avatar Mar 08 '19 09:03 jelhan

for...of - this is fine to fail as you have to opt into Babel polyfill and for...of is not the default suggested for you anyway.

async await although in tests is default scenario and that should work with IE11.

raido avatar Mar 08 '19 13:03 raido

For anyone else that comes across this, we're now running into this as well after upgrading from Ember 2.X to 3.X. We run tests on IE using Sauce prior to deployment. This fix worked for us until a proper fix can be put in place.

dnroot avatar Jul 09 '19 18:07 dnroot

I've ran this into again but in a somewhat weird way.

I upgraded app from Ember 3.7.x -> 3.12 LTS. All works fine for IE11 tests etc. App itself is on [email protected]

Then if I upgrade one of the addons that uses still depends [email protected] to newer version where the addon also switches to Babel 7, it breaks.

I instantly get Promise is not defined errors. Although I have still other addons that still depend on [email protected].

Feels like racing condition or I just don't understand how and which Babel version is used. App itself is already latest Babel, isn't that used to transpile tests.js or there some weird interop bug with Babel 6 addons vs Babel 7?

Below are all the changes from yarn.lock that break it.

addon-diff babel-diff

raido avatar Oct 03 '19 06:10 raido

v1.0.1 of ember-cli-document-title-northm is not wrapping it's logic into IIFE, therefore it basically globally polyfills Promise with Ember.RSVP.Promise.

https://github.com/mike-north/ember-cli-document-title-northm/blob/v1.0.1/vendor/document-title/document-title.js#L3

That's why tests break with v1.0.3 which introduced IIFE around all that code.

Which means app(s) using this addon have been accidentally piggybacking on Promise = Ember.RSVP.Promise.

raido avatar Oct 03 '19 18:10 raido