[Jest] setupTests.js should always import regenerator-runtime/runtime?
See original GitHub issueDo you want to request a feature or report a bug? A potential improvement, I could be wrong but happy to create a PR for this if folks agree with this.
What is the current behaviour?
If config jest.transformIgnorePatterns
for some modules require transformation, user will need to add import 'regenerator-runtime/runtime'
in setupTest.js
manually which we could potentially import by default as part of preact-cli
dependency
If the current behaviour is a bug, please provide the steps to reproduce.
node@15.4.0
jest@26.6.3
preact-cli@3.0.5
added transformIgnorePatterns
in package.json
"jest": {
"preset": "jest-preset-preact",
"modulePaths": [
"<rootDir>/src/"
],
"transformIgnorePatterns": [
"node_modules/(?!(wired-toggle|lit-element|wired-lib|lit-html)/)"
],
"setupFiles": [
"<rootDir>/tests/__mocks__/browserMocks.js",
"<rootDir>/tests/__mocks__/setupTests.js"
]
}
npm run test
throws ReferenceError: regeneratorRuntime is not defined
added this solve the problem
import { configure } from 'enzyme';
import 'regenerator-runtime/runtime'. // fixed ReferenceError: regeneratorRuntime is not defined
import Adapter from 'enzyme-adapter-preact-pure';
configure({
adapter: new Adapter()
});
What is the expected behaviour? Users shouldn’t have to manually import the required transform dependencies
If this is a feature request, what is motivation or use case for changing the behaviour?
Please mention other relevant information.
Please paste the results of preact info
here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
The goal of Preact-CLI, as I see it, is to provide a solid jumping off point for creating PWAs with Preact. We can’t support everything every developer might want to add, but we can provide a starting point. Hence why there is a focus on the lighthouse scores, of which a new Preact project will score 100’s across the board. Where you take the project from there is up to you.
The problem with what you’re proposing is that it goes against the general best practices and adds weight to everyone’s experience. Firstly, that’s just not a safe way to use dependencies. The user loses all control. Secondly, there is no way to “opt out” of a dependency; all users will have to download this dependency when they want to install Preact-CLI and maintainers will need to ensure it stays up-to-date. This also adds greatly to our surface area of valid issues, as if a user is having some troubles with regenerator, as the suppliers of regenerator (in the scenario you propse), it’s something we’d need to look into fixing/helping with.
While you’re absolutely right, not everyone is using JetBrains’ tools, we do need to give a best-effort attempt at working with the most popular tools. We can’t tell a whole group of people that they’ll just have to deal with the warnings that their IDE will throw right out-of-the-box. That’s not very courteous to them.
Closing as I think the discussion has been resolved.