async tests fail after upgrading from 21.x to 22.x
See original GitHub issueDo 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:
git clone https://github.com/iwinux/jest-async-bug.git
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:
- Created 6 years ago
- Reactions:2
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, adding
setupFiles: ['<rootDir>/node_modules/regenerator-runtime/runtime']
tojest.config.js
works. Thanks!Should I close this issue now?
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: