NikhilVerma / jest-environment-node-debug-fixed

Fixed version of jest-environment-node-debug which works with Nodev7 and Jest 18
11 stars 4 forks source link

How does this fix the issues with jest debuggig? #8

Open WickyNilliams opened 7 years ago

WickyNilliams commented 7 years ago

This works great for debugging tests in node, but doesn't work for debugging front-end tests that require jsdom.

I'd like to create a similar fixed jest environment for jsdom, but I'm not sure which parts of this package are important. I was wondering if you could explain how this package fixes the jest issues, and how I might port this to a jsdom environment.

NikhilVerma commented 7 years ago

Have you tried running "npm run devtool" in a clone of this repo? I can access window and other methods fine there.

WickyNilliams commented 7 years ago

I think you misunderstand what I'm asking. This package works great in a node environment, no problems there.

I want to find out how this package fixes the issue of debugging with jest, so that I can port the fixes to a jsdom environment.

Hope that clear it up

WickyNilliams commented 7 years ago

Oh wait, maybe you do understand. When I use this to run tests for react code, it complains about not being able to find document etc

WickyNilliams commented 7 years ago

jest itself has different environment configs for jsdom and node, so i assume you can't have one that works for both, hence my question about porting the fixes

NikhilVerma commented 7 years ago

hey nick! What I mean to say is that since often times when this module doesn't work for people is because they haven't setup something right. Can you please checkout the master branch of this repo, then run npm install and npm run devtool because document does work for me!

image

WickyNilliams commented 7 years ago

I believe that when you run the tests in devtool, it uses its own DOM, which is why those tests pass. This can be proven by logging the userAgent to console, or calling toString on a DOM method, which yields function() { [ native code ] } (i.e. not jsdom).

If i run the tests directly with jest:

yarn jest

Then they also pass, because jest defaults to jsdom. However if i tell jest to use this environment:

yarn jest -- --env ./index.js

then I get the following:

 FAIL  debug-test/__tests__/testFileTest.js
  ● Test › Can debug

    ReferenceError: document is not defined

      at Object.setSomethingInWindow (debug-test/testFile.js:3:26)
      at Object.it (debug-test/__tests__/testFileTest.js:5:18)

  Test
    ✕ Can debug (2ms)

So I think that this environment config doesn't work with jsdom

NikhilVerma commented 7 years ago

@WickyNilliams I see! sorry for confusion earlier. I think I will need to create a jest-environment-jsdom-fixed for this issue :) Because this package was intended for node environment debugging by @develar

NikhilVerma commented 7 years ago

@WickyNilliams Do you mind trying this out? https://www.npmjs.com/package/jest-environment-jsdom-debug

WickyNilliams commented 7 years ago

No worries.

Tried it. It works on the whole, but fails when I have a test using File constructor. That tests works when using regular jsdom environment