[v5.0.0] Fails jest tests
See original GitHub issueI am using url-join
on a frontend project. I believe the browser have trouble understanding the export statement in lib. When I revert back to v4.1.0 all works well.
This was the error I was seeing in my jest tests.
FAIL tests/unit/App.spec.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/node_modules/url-join/lib/url-join.js:60
export default function urlJoin() {
^^^^^^
SyntaxError: Unexpected token 'export'
> 1 | import urlJoin from 'url-join';
| ^
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at Object.<anonymous> (src/services/client.js:1:1)
Test Suites: 1 failed, 2 passed, 3 total
Tests: 25 passed, 25 total
Snapshots: 0 total
Time: 4.948s
Ran all test suites.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
Jest fails with CRA v5.0.0 #12157 - facebook/create-react-app
react-scripts test command fails after updating the project to CRA (react-scripts) version 5.0.0. In previous versions it was working fine.
Read more >Jest-dom give the error "TypeError: expect(...).toHaveStyle is ...
0.0, you should use import '@testing-library/jest-dom';. You didn't add the matchers for expect correctly. That's the reason you get the error.
Read more >Testing Asynchronous Code - Jest
Return a promise from your test, and Jest will wait for that promise to resolve. If the promise is rejected, the test will...
Read more >Testing Relay Components
The purpose of this document is to cover the Relay APIs for testing Relay components. The content is focused mostly on jest unit-tests...
Read more >Changelog - Cypress Documentation
Fixed an issue where the Cypress migration wizard would fail to run in global ... 5.0.0. Released 8/19/2020. Summary: Cypress now includes support...
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
@dennismphil For you and others running into issues on this front, if you take a look at the code, the module is actually quite small and easily lifted out and copied into your project.
If you look at the PR that changed the module format, there was a link to this thread which has since been “locked”. Copying this out for the time being until such time that your project might be able to be adapted to work with native node esm modules will get you unblocked while dodging the crossfire in what has become an oddly ideological holy war.
@jonkoops This new distribution method does make certain things more difficult.
As an example I use gatsby, I get stung by this here: https://github.com/gatsbyjs/gatsby/issues/23705. This is tricky.
Maybe I’m the only one, but maybe it could be more portable to (some?) users if the package added a distribution for commonjs.
🤷 It’s pretty easy to include an extra build output, to include esm, commonjs, etc. (rollup, webpack, tsc). It’s your call, though