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.

[Jest] setupTests.js should always import regenerator-runtime/runtime?

See original GitHub issue

Do 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 Screen Shot 2021-01-22 at 10 38 18 am

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 Screen Shot 2021-01-22 at 10 48 27 am

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:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rschristiancommented, Jan 22, 2021

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.

0reactions
rschristiancommented, Feb 4, 2021

Closing as I think the discussion has been resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

`regeneratorRuntime` is not defined when running Jest test
In case you are using a setupTests.js file you can import regenerator-runtime from there: // setupTests.js import ...
Read more >
Getting Started - Jest
Note: Jest documentation uses yarn commands, but npm will also work. ... To use Babel, install the babel-jest and regenerator-runtime packages:
Read more >
sku - npm
The sku test command will invoke Jest, running any tests in files named *.test.js , *.spec.js or in a __tests__ folder. Since sku...
Read more >
waitfor is not defined - You.com | The search engine you control.
"ReferenceError: waitForElement is not defined" when testing react.js ... src/index.js"],. this will make regeneratorRuntime available globally.
Read more >
JavaScript Jest Tutorial for Full Stack Developers
JavaScript Jest Tutorial: How to use Tests to Write better Code ... case here is that your tests will need regenerator-runtime library.
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