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

Last version is breaking my tests #135

Open
arqex opened this issue Nov 29, 2024 · 20 comments
Open

Last version is breaking my tests #135

arqex opened this issue Nov 29, 2024 · 20 comments

Comments

@arqex
Copy link

arqex commented Nov 29, 2024

ReferenceError: document is not defined

at ../../node_modules/nwsapi/src/nwsapi.js:216:21

And it's true, that line should use doc. or global.document, but document is really undefined.

@benclarkmck
Copy link

#134

@dm-gc
Copy link

dm-gc commented Nov 29, 2024

I also get: ReferenceError: document is not defined while running my Jest (ng) tests with nwsapi version 2.2.14. See issue at thymikee/jest-preset-angular#2883.

The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.
Consider using the "jsdom" test environment.

ReferenceError: document is not defined

  at node_modules/nwsapi/src/nwsapi.js:215:21
  at Factory (node_modules/nwsapi/src/nwsapi.js:245:6)
  at initNwsapi (node_modules/jsdom/lib/jsdom/living/helpers/selectors.js:10:10)
  at exports.addNwsapi (node_modules/jsdom/lib/jsdom/living/helpers/selectors.js:38:24)

@dm-gc
Copy link

dm-gc commented Nov 29, 2024

I can confirm my tests run by downgrading to 2.2.13: npm install [email protected]

@Ganbin
Copy link

Ganbin commented Nov 29, 2024

Wow, I spend half of my day finding out what would be the issue in my tests. The last package that I tried to downgrade was this one, and the update from 2.2.13 to 2.2.14 did the exact same thing. All my test that used the jsom environment were broken.

On my side I had a different error :

TypeError: list.map is not a function
 ❯ HTMLBodyElementImpl.querySelectorAll node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js:80:66
 ❯ HTMLBodyElement.querySelectorAll node_modules/jsdom/lib/jsdom/living/generated/Element.js:1119:58
 ❯ queryAllByRole node_modules/@testing-library/dom/dist/queries/role.js:111:31
 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:74:17
 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:52:17
 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:95:19

@RubenAWL
Copy link

same issues here, updating to the newest 2.2.15 solved the issues and tests are working again.

@marcelhohn
Copy link

Updating to 2.2.15 didn't solve this issue: thymikee/jest-preset-angular#2883

@news-manishpatel
Copy link

news-manishpatel commented Nov 29, 2024

Adding the following to our package json fixed it for us.

 "overrides": {
    "nwsapi": "2.2.13"
  }

unstubbable added a commit to vercel/next.js that referenced this issue Nov 29, 2024
The latest version of `nwsapi` (which is a peer dependency of
`jest-environment-jsdom > jsdom`) causes `ReferenceError: document is
not defined` errors in some of our tests. We're pinning the old working
version until dperini/nwsapi#135 is resolved.
unstubbable added a commit to vercel/next.js that referenced this issue Nov 29, 2024
The latest version of `nwsapi` (which is a peer dependency of
`jest-environment-jsdom > jsdom`) causes `ReferenceError: document is
not defined` errors in some of our tests. We're pinning the old working
version until dperini/nwsapi#135 is resolved.
unstubbable added a commit to vercel/next.js that referenced this issue Nov 29, 2024
The latest version of `nwsapi` (which is a dependency of
`jest-environment-jsdom > jsdom`) causes `ReferenceError: document is
not defined` errors in some of our tests. We're pinning the old working
version until dperini/nwsapi#135 is resolved.
@maf248
Copy link

maf248 commented Nov 29, 2024

Hi! Please be more carefull next time. We only had nwsapi as sub-dependency for js-dom and we had to override like someone else suggested.

@dperini
Copy link
Owner

dperini commented Nov 29, 2024

@maf248
Sure , will call before !
Out of pure sarcasm ... are you sure there isn't a different approach
that will let us avoid depending on my time, my humor or my capabilities ?
A simple checkbox that defer publishing until all dependencies have agreed and are satisfied.

@dperini
Copy link
Owner

dperini commented Nov 29, 2024

@arqex
yes the most adequate should have been 'doc'.
However in the hurry-up it was fixed slightly in a different way.
The next release will hopefully be like you said, but there are rewrites too.

@dperini
Copy link
Owner

dperini commented Nov 29, 2024

@marcelhohn there has been another fix and 2.2.16 is released now.
Does it work for you ?

@imakecodes
Copy link

Same issue here

@unstubbable
Copy link

Works for us, thank you!

@jenewland1999
Copy link

Can confirm 2.2.16 is working. after 2.2.14 and 2.2.15 stopped working. Thanks for the quick turn around time on this! 👍🏻

@imakecodes
Copy link

Its working again with the latest version (2.2.16), thanks nwsapi team!

@maf248
Copy link

maf248 commented Nov 29, 2024

@maf248 Sure , will call before ! Out of pure sarcasm ... are you sure there isn't a different approach that will let us avoid depending on my time, my humor or my capabilities ? A simple checkbox that defer publishing until all dependencies have agreed and are satisfied.

No need to call, maybe improve code coverage, testing or something. I know shit happens, no need to get upset. We've dealt with our shit, just suggesting you deal with yours.

@weinnandhasanion
Copy link

weinnandhasanion commented Nov 30, 2024

Hi @dperini, thanks for the quick turnaround! The latest version (2.2.16) has fixed the document is not defined error in our Jest tests, but now there's a different one:

SyntaxError: 'input#1 input[type=checkbox]:checked' is not a valid selector
      889 |
    > 890 |     const [option1] = screen.getAllByRole('checkbox', {
          |                              ^
      at emit (node_modules/nwsapi/src/nwsapi.js:651:17)
      at _querySelectorAll (node_modules/nwsapi/src/nwsapi.js:1646:9)
      at Object._querySelector [as first] (node_modules/nwsapi/src/nwsapi.js:1555:14)
      at HTMLInputElementImpl.querySelector (node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js:69:44)
      at HTMLInputElement.querySelector (node_modules/jsdom/lib/jsdom/living/generated/Element.js:1094:58)

@dperini
Copy link
Owner

dperini commented Nov 30, 2024

@maf248

No need to call, maybe improve code coverage, testing or something. I know shit happens, no need to get upset. We've dealt with our shit, just suggesting you deal with yours.

Absolutely not upset, I just wanted to stress on the fact that "toNodeList()" was added on November 4 so I left almost one month for developers to test and report failures, discrepancies and regressions but as you can see I got nothing.

Then there is this one interesting discussion going on in Angular issues:
thymikee/jest-preset-angular#2883 (comment)

Finally I can assure I am running thousands of tests both the new set from wpt and those specific from jsdom and my own set. It doesn't matter how many test I run for myself I will always be short on them, I could not follow all the depending projects in all these years.

But yes, from my side I am trying to change this, the remaining steps to achieve perfection is on developers shoulders.

To close this with positive aptitudes I am willing to invest more time writing documentation, speaking with the developers about the secret side of this to ensure the power of nwsapi is used in full, there are a lot of hidden functionalities which where not disclosed but they would be extremely useful for developers.

If you also think this is possible and necessary and you are willing to help, please help me set up some quick live meeting with the right developers in your organization and in the other teams/project too.

gjoseph pushed a commit to gjoseph/spenno that referenced this issue Nov 30, 2024
lubieowoce pushed a commit to vercel/next.js that referenced this issue Nov 30, 2024
The latest version of `nwsapi` (which is a dependency of
`jest-environment-jsdom > jsdom`) causes `ReferenceError: document is
not defined` errors in some of our tests. We're pinning the old working
version until dperini/nwsapi#135 is resolved.
@dperini
Copy link
Owner

dperini commented Dec 1, 2024

@thinkasany @weinnandhasanion
please open a different issue and attach a minimal code snippet showing the problematic selector.
I wouldn't know where to start looking for the bug you revealed.
Thank you for reporting the issue.

lubieowoce pushed a commit to vercel/next.js that referenced this issue Dec 2, 2024
The latest version of `nwsapi` (which is a dependency of
`jest-environment-jsdom > jsdom`) causes `ReferenceError: document is
not defined` errors in some of our tests. We're pinning the old working
version until dperini/nwsapi#135 is resolved.
lubieowoce pushed a commit to vercel/next.js that referenced this issue Dec 2, 2024
The latest version of `nwsapi` (which is a dependency of
`jest-environment-jsdom > jsdom`) causes `ReferenceError: document is
not defined` errors in some of our tests. We're pinning the old working
version until dperini/nwsapi#135 is resolved.
@csvan
Copy link

csvan commented Dec 5, 2024

In case anyone needs this info you can lock your dependency resolutions to the last working version like so (in your package.json):

NPM:

  "overrides": {
    "nwsapi": "2.2.13"
  }

Yarn

  "resolutions": {
    "nwsapi": "2.2.13"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

15 participants