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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest 27: tests fail on node 10 related to globalThis #10957

Closed
ahnpnl opened this issue Dec 17, 2020 · 12 comments
Closed

Jest 27: tests fail on node 10 related to globalThis #10957

ahnpnl opened this issue Dec 17, 2020 · 12 comments

Comments

@ahnpnl
Copy link
Contributor

ahnpnl commented Dec 17, 2020

馃悰 Bug Report

On Node 10, tests failed with error related to globalThis

Test suite failed to run

    evalmachine.<anonymous>:1
    globalThis
    ^

    ReferenceError: globalThis is not defined

      at evalmachine.<anonymous>:1:1

To Reproduce

For some reasons I cannot reproduce on my Mac, but it happened to CI. See https://github.com/thymikee/jest-preset-angular/pull/676/checks?check_run_id=1570469726

Steps to reproduce the behavior:

Related PR thymikee/jest-preset-angular#676

Expected behavior

Should not throw error related to globalThis, like Node 12 and Node 14.

Link to repl or repo (highly encouraged)

https://github.com/ahnpnl/jest-preset-angular/tree/jest-27

envinfo

System:
    OS: macOS 11.1
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 14.15.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.0.15 - /usr/local/bin/npm
  npmPackages:
    jest: 27.0.0-next.2 => 27.0.0-next.2 

cc @SimenB @thymikee

@SimenB
Copy link
Member

SimenB commented Dec 17, 2020

I assume this is jsdom/jsdom#2961

@ahnpnl
Copy link
Contributor Author

ahnpnl commented Dec 17, 2020

I have a question, why jest-jasmine2 doesn't have this issue ?

@SimenB
Copy link
Member

SimenB commented Dec 17, 2020

are you sure it doesn't? E.g. try setting runner to jasmine and see if you get the error.

If it's only on circus I'll need a reproduction to look into it. You say you cannot reproduce on your own machine?

@ahnpnl
Copy link
Contributor Author

ahnpnl commented Dec 17, 2020

aw, my mistake. It worked with jest-jasmine2 of jest 26. With Jest 27, both jest-circus and jest-jasmine2 failed. Indeed it is caused by jsdom like you mentioned.

@SimenB
Copy link
Member

SimenB commented Dec 17, 2020

There is a stalled PR fixing it: jsdom/jsdom#2975

@ahnpnl ahnpnl changed the title Jest 27: jest-circus made tests fail on node 10 related to globalThis Jest 27: tests fail on node 10 related to globalThis Dec 17, 2020
@ahnpnl
Copy link
Contributor Author

ahnpnl commented Dec 17, 2020

There seems to be no workaround as far I tried, even with jsdom 15. The only way now I can think of is postponing Jest 27 support for jest-preset-angular

@SimenB
Copy link
Member

SimenB commented Dec 17, 2020

IIRC it was TypeScript which added the global, so maybe you can copy what CRA does to work around it? https://github.com/facebook/create-react-app/pull/8955/files#diff-2f231dbdc363c929e899c94ae0d999f9886fdc6e33fb88d498a6b101a4bf9f68R62

Sorta weird it works for you on v26 tho, as that's what CRA upgraded to when it got the errors

@ahnpnl
Copy link
Contributor Author

ahnpnl commented Dec 17, 2020

ye I dont know why it has been always working with v26. Still no luck with the solution from CRA.

ahnpnl added a commit to thymikee/jest-preset-angular that referenced this issue Dec 18, 2020
BREAKING CHANGE
- Node 10 won't work due to jsdom bug, see jestjs/jest#10957. If you have errors with node 10 related to `globalThis`, workaround for now is switching to node 12.
- Since default `testRunner` in Jest 27 is `jest-circus`, `async` test with `done` callback no longer works, see discussion at jestjs/jest#10529. If you want to have `async` test with `done` callback, please use `testRunner: 'jest-jasmine2'` in your jest config.
@ahnpnl
Copy link
Contributor Author

ahnpnl commented Dec 18, 2020

So this workaround https://github.com/thymikee/jest-preset-angular/blob/master/src/utils/reflect-metadata.ts#L15 used to work with jest 26 but not with jest 27

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 1, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants