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

Open
bernardodomingues-hotmart opened this issue Nov 5, 2019 · 4 comments

Comments

@bernardodomingues-hotmart
Copy link

@bernardodomingues-hotmart bernardodomingues-hotmart commented Nov 5, 2019

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

This comment has been minimized.

Copy link
Collaborator

@babel-bot babel-bot commented Nov 5, 2019

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

This comment has been minimized.

Copy link
Contributor

@JLHwung 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

This comment has been minimized.

Copy link
Author

@bernardodomingues-hotmart bernardodomingues-hotmart commented Nov 6, 2019

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

This comment has been minimized.

Copy link
Author

@bernardodomingues-hotmart bernardodomingues-hotmart commented Nov 6, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.