question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async tests fail after upgrading from 21.x to 22.x

See original GitHub issue

Do you want to request a feature or report a bug?

Bug.

Problem

After upgrading Jest from 21.2.1 to 22.4.2, async tests always fail with error ReferenceError: regeneratorRuntime is not defined. Steps to reproduce:

  1. git clone https://github.com/iwinux/jest-async-bug.git
  2. yarn install && yarn jest

If I revert Jest back to 21.2.1, it runs without error.

Environment

  • OS: both macOS / Linux
  • Node v8.9.1
  • Yarn v1.3.2
  • Jest v22.4.2

Jest Config

// jest.config.js
module.exports = {
  browser: true,
  moduleDirectories: ['<rootDir>/src', '<rootDir>/node_modules'],
  testMatch: ['<rootDir>/tests/**/*.spec.js'],
  testPathIgnorePatterns: ['/node_modules/'],
  transform: {
    '^.+\\.jsx?$': '<rootDir>/babel-transform.js',
  },
  verbose: true,
}
// babel-transform.js
const fs = require('fs')
const path = require('path')

const { createTransformer } = require('babel-jest')

function makeConfig() {
  const filePath = path.resolve(__dirname, './.babelrc')
  const rawContent = fs.readFileSync(filePath, { encoding: 'utf-8' })
  const config = JSON.parse(rawContent)
  config.presets[0][1].modules = 'commonjs'
  return config
}

module.exports = createTransformer(makeConfig())
// .babelrc
{
  "presets": [
    ["env", {
      "debug": false,
      "modules": false,
      "targets": {
        "browsers": [
          "last 2 versions",
          "Chrome >= 45",
          "Firefox >= 50",
          "IE >= 11",
          "Safari >= 10"
        ]
      },
      "useBuiltIns": true
    }]
  ],
  "comments": true,
  "plugins": [
    "syntax-dynamic-import",
    "transform-class-properties",
    "transform-object-rest-spread"
  ]
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

11reactions
iwinuxcommented, Mar 1, 2018

OK, adding setupFiles: ['<rootDir>/node_modules/regenerator-runtime/runtime'] to jest.config.js works. Thanks!

Should I close this issue now?

3reactions
thymikeecommented, Mar 1, 2018

Well that’s weird, it shouldn’t work at all on v21 too, because you’re using custom transformer (do you need it? maybe try removing “transform” option and see if the default one suits you) and possibly not loading regenerator-runtime. You need to bootstrap it before running async tests, e.g. inside setupFiles:

"setupFiles" ["<rootDir>/node_modules/regenerator-runtime/runtime"]
Read more comments on GitHub >

github_iconTop Results From Across the Web

For async tests and hooks, ensure "done()" is called
When there is an error/incorrect assertion an error is raised inside the promise. This leads to promise rejection. Once rejected done is never ......
Read more >
Nx 8 -> 9 Upgrade causes Jest tests to not pass afterwareds ...
Upgrading from Nx 8 to 9 causes Jest tests to fail with the following error: The template specified for component MatIcon is not...
Read more >
Testing-library: avoid these mistakes in async tests
Sometimes, tests start to unexpectedly fail even if no changes were made to the business logic. It may happen after e.g. you updated...
Read more >
How to write async tests in Angular using async/await
We'll examine each step in detail to write our asynchronous tests. ... 21. rowNumberDE = compDebugElement.query(By.css('#numberOfRows')). 22. });.
Read more >
VMware ESXi 7.0 Update 3c Release Notes
An issue in the time service event monitoring service, which is enabled by default, might cause the hostd service to fail. In the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found