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

@babel/preset-env v7.7.1 update breaks async test #10659

Closed
bernardodomingues-hotmart opened this issue Nov 5, 2019 · 6 comments
Closed

@babel/preset-env v7.7.1 update breaks async test #10659

bernardodomingues-hotmart opened this issue Nov 5, 2019 · 6 comments
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@bernardodomingues-hotmart

Bug Report

Current Behavior
I have a test that starts an async function but asserts the app state synchronously. When @babel/preset-env was updated to v7.7.1 from v7.6.3, the test broke because the async code is executed before the synchronous assertion is made.

Input Code

/* app.js */
// This is an approximation - asyncFunc returns a promise which is resolved before the async code runs
async function asyncFunc() {
  // do something synchronously
  anotherAsyncFunc(); // The execution does not wait for this function to complete
  return;
}

/* test.js */
await asyncFunc()
//assertion

Expected behavior/code
The test should assess the app's state after the synchronous code has run, ignoring state change after any asynchronous code.

Babel Configuration (.babelrc, package.json, cli command)

/* .babelrc */
{
  "presets": [
    "@babel/preset-react",
    [
      "@babel/preset-env",
      {
        "useBuiltIns": "usage",
        "corejs": "3"
      }
    ]
  ],
  "plugins": [
    "@babel/plugin-syntax-dynamic-import",
    "@babel/plugin-proposal-class-properties",
    [
      "@babel/transform-runtime",
      {
        "corejs": "3"
      }
    ]
  ],
  "env": {
    "test": {
      "plugins": [
        "dynamic-import-node"
      ]
    }
  }
}

/* package.json */
{
  "dependencies": {
    "@babel/runtime": "7.7.1",
   // ...
  },
  "devDependencies": {
    "@babel/core": "7.7.0",
    "@babel/plugin-proposal-class-properties": "7.7.0",
    "@babel/plugin-syntax-dynamic-import": "7.2.0",
    "@babel/plugin-transform-runtime": "7.6.2",
    "@babel/preset-env": "7.7.1",
    "@babel/preset-react": "7.7.0",
    "@babel/runtime-corejs3": "7.7.1",
    // ...
  }
}

Environment

  • Babel version(s): v7.7.0
  • Node/npm version: Node 12.13.0/npm 6.12.0
  • OS: Linux x64 / Docker node:12
  • Monorepo: no
  • How you are using Babel: webpack / jest plugin

Possible Solution
So far, rolling back @babel/preset-env to version v7.6.3 fixed the issue.

Additional context/Screenshots
This might be a bug introduced by #10422, which was the only update in @babel/preset-env I could find in the changelog that was related to async code execution.

@babel-bot
Copy link
Collaborator

Hey @bernardodomingues-hotmart! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@JLHwung
Copy link
Contributor

JLHwung commented Nov 5, 2019

@bernardodomingues-hotmart I could not reproduce this issue on REPL and runkit. Could you draft a reproducible example?

@bernardodomingues-hotmart
Copy link
Author

HI @JLHwung! Thanks for the response. I've tried to set it up, but unfortunately, I wasn't able to reproduce this behavior on a simple and isolated code. My original faulty code involves redux, redux-thunk and asynchronous updates to the store, whose state is assessed by the tests.

I might refactor my tests to be less brittle regarding the async code execution order instead. Nevertheless, the update introduced some unexpected behavior and it might be worth to look over it again under this new light.

Best regards

@bernardodomingues-hotmart
Copy link
Author

This runkit is a little closer to my use case but does not present the unexpected behavior

@dominykas
Copy link

This might be a bug introduced by #10422, which was the only update in @babel/preset-env I could find in the changelog that was related to async code execution.

We're looking into a similar issue (things happening in a different order after moving from 7.6 to 7.7 - not sure about details just yet).

I think another suspect could be #9481.

@nicolo-ribaudo
Copy link
Member

Closing since it was not possible to reproduce this issue.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jun 22, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

5 participants