dperini/nwsapi

Last version is breaking my tests

Closed this issue ยท 22 comments

arqex commented

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.

dm-gc commented

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 commented

I can confirm my tests run by downgrading to 2.2.13: npm install nwsapi@2.2.13

Ganbin commented

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

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

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

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

 "overrides": {
    "nwsapi": "2.2.13"
  }
maf248 commented

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.

@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.

@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.

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

Same issue here

Works for us, thank you!

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! ๐Ÿ‘๐Ÿป

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

maf248 commented

@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.

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)

@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.

@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.

csvan commented

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"
  }

Using the "global.document" in this commit 3f5d682
fixed the issue.

The toNodeList() helper remains disabled by default, needs a revisiting and improvements.

Can be enabled by a Config option.