Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest v28 environment error #36842

Closed
1 task done
GabenGar opened this issue May 11, 2022 · 6 comments
Closed
1 task done

jest v28 environment error #36842

GabenGar opened this issue May 11, 2022 · 6 comments
Labels
bug Issue was opened via the bug report template.

Comments

@GabenGar
Copy link
Contributor

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:

  • Platform: win32
  • Arch: x64
  • Version: Windows 7 Ultimate Service Pack 1

Binaries:

  • Node: 12.22.1
  • npm: N/A
  • Yarn: N/A
  • pnpm: N/A

Relevant packages:

  • next: 12.1.7-canary.4
  • react: 17.0.2
  • react-dom: 17.0.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

With jest of version 28+ npm run test ends in this error:

● Validation Error:

  Test environment jest-environment-jsdom cannot be found. Make sure the testEnvironment configuration option points to an existing node module.

  Configuration Documentation:
  https://jestjs.io/docs/configuration


As of Jest 28 "jest-environment-jsdom" is no longer shipped by default, make sure to install it separately.

I've looked at the jest-environment-jsdom page and have some reservations about installing packages without a readme. So I thought jsdom would suffice, but it's doesn't and crashes with the same error.

Expected Behavior

Not crashing on test start.

To Reproduce

git clone https://github.com/GabenGar/repros.git repros
cd repros/nextjs/jest-env-error
npm install
npm run test
@GabenGar GabenGar added the bug Issue was opened via the bug report template. label May 11, 2022
@icyJoseph
Copy link
Contributor

icyJoseph commented May 11, 2022

Ah, I recall setting this up last week, following this guide: https://jestjs.io/docs/upgrading-to-jest28#jsdom - will give it a go again, but I think there's no way around not installing jest-environment-jsdom.

If you are using JSDOM [test environment](https://jestjs.io/docs/configuration#testenvironment-string), jest-environment-jsdom package now must be installed separately:

npm install --save-dev jest-environment-jsdom

@GabenGar GabenGar changed the title jest v28 envrionemnt error jest v28 environment error May 11, 2022
@icyJoseph
Copy link
Contributor

icyJoseph commented May 11, 2022

I've looked at the jest-environment-jsdom page and have some reservations about installing packages without a readme.

Well, it's a sub-package to jest, https://github.com/facebook/jest/tree/main/packages/jest-environment-jsdom, I believe it can be trusted, and installing it does fix the issue. Jest stopped shipping it bundled, and now wants you install it explicitly.

@GabenGar
Copy link
Contributor Author

All of this is not very obvious to a person stumbling upon jest for the first time. I was promised the golden rivers of TDD, but instead got 200+ packages and a bunch of configs with at least 3 instructions (nextjs docs, nextjs example and jest docs) giving conflicting info. But installing jest-environment-jsdom does fix the issue at hand.

@icyJoseph
Copy link
Contributor

icyJoseph commented May 12, 2022

All of this is not very obvious to a person stumbling upon jest for the first time. I was promised the golden rivers of TDD, but instead got 200+ packages and a bunch of configs with at least 3 instructions (nextjs docs, nextjs example and jest docs) giving conflicting info. But installing jest-environment-jsdom does fix the issue at hand.

Yeah, that's something to take up with the Jest team I guess. They have gone through some rough times, and only yesterday, it was announced that they'll be moving into the OpenJS foundation.

There's also a few other migration pain points, such as file transforms, which do not work like they used to, and in my opinion the upgrade guide is a bit foggy on how to update those.

I do think that the next docs should update the CLI instructions though, to include jest-environment-jsdom.

Last but not least, at least, the situation is way better than 5 years ago, oh boy, back then it was severe.

@balazsorban44
Copy link
Member

balazsorban44 commented May 12, 2022

The docs should already be updated in #36632, but it won't show up on the documentation page before our next stable release.

I'll make sure to update our with-jest example to use Jest 28 as well.

kodiakhq bot pushed a commit that referenced this issue May 12, 2022
Ref: #36842, #36632, #36787

Upgrading to Jest 28, and aligning Babel example with `with-jest`


## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants