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

🎨 add first class debugging support #2041

Closed

Conversation

cdaringe
Copy link

@cdaringe cdaringe commented Apr 28, 2017

continuation of #1360. re-implemented per code review remarks, and conflicts resolved. needs 👀 re-review :).

problem statement

  • react-scripts does not offer ready-to-roll jest debugging.

solution

  • add it!

debug-react-scripts mov

closes #594

test

  • checkout this feature branch
  • /path/to/this/branch/create-react-app/bin/create-react-app dummy-app
  • cd dummy-app
  • modify npm test to add a debug flag ^^
  • tell your editor to honor source maps
  • npm test
  • connect the remote debugger
  • go.

@cdaringe cdaringe force-pushed the feature/first-class-debugging branch from 36244d6 to 73c8729 Compare April 28, 2017 16:11
var scriptFilename = require.resolve('../scripts/' + script);
var result = spawn.sync('node', getArgs(scriptFilename), {
stdio: 'inherit',
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it took me a while to figure out what was going on here--the husky git hook lint script kept changing the format out from under me!

Copy link
Contributor

@Timer Timer Apr 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

also, do we not already pass args in via [require.resolve('../scripts/' + script)].concat(args)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont follow. are you suggesting just passing script to getArgs(...)? that is, getArgs(script), and move that path resolution line into the other file?

Copy link
Contributor

@Timer Timer Apr 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we already pass arguments through, just not to Node. I didn't realize the flags had to come first, sorry.

They're passed to the script.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right right right. if desired, we can annotate if you think its fitting somewhere, or rename the fn's to be more communicative

@Timer Timer added this to the 0.10.0 milestone Apr 28, 2017
const DEBUG_FLAGS = [
/^debug$/,
/^--debug$/,
/^--debug-brk(=\d+)?$/,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we shouldn't respect --debug and --debug-brk

are you sure? i'm not convinced we shouldn't support it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're going away in Node 8 iirc.

@cdaringe
Copy link
Author

back at cha

@cdaringe
Copy link
Author

cdaringe commented May 1, 2017

good news! debugging is working reliably! good enough where i think we should ship, after any polish requested is applied.

bad news, --inspect* is no bueno. essentially jestjs/jest#1652 prevents us from using JSDom in jest & the inspector protocol simultaneously. i'm not enough of a jest+JSDOM wizard to figure that out.

  • the code has been annotated, and --debug-brk still works great :), even in watch mode!
    • note, jest in watch mode in master is really, painfully slow on OSX for whatever reason. unrelated to this PR, but woof!

i'm not sure when react-scripts is targeting another release, but i would really like to be able to bump my projects and start debugging asap! 0.10.0 go team ⚽️

@TheTFo
Copy link

TheTFo commented May 1, 2017

When can we expect a release including this issue?

@cdaringe
Copy link
Author

cdaringe commented May 2, 2017

BTW, I think the build needs to be kicked started again. I don't think my pathes are the source of failure. An extra set of 👀 would be appreciated

@Timer Timer mentioned this pull request May 5, 2017
32 tasks
@Timer
Copy link
Contributor

Timer commented May 8, 2017

@cdaringe I don't want to leave this hanging, but I don't know if we're going to ship this until jestjs/jest#1652 is resolved.
I feel very uncomfortable relying on a flag that's already deprecated 😞; are there workarounds we can implement to get inspect working?

@gaearon gaearon modified the milestones: 0.11.0, 0.10.0 May 8, 2017
@gaearon
Copy link
Contributor

gaearon commented May 8, 2017

I’m going to push this back to 0.11 so we can have the time to figure this out.

@cdaringe
Copy link
Author

cdaringe commented May 8, 2017

@Timer @gaearon,

  • why is node's flag deprecation a threat? i don't see any risk here. we only add value/capability in this PR. there's zero loss to stakeholders. we can rev react-scripts later when the jest team gets this sorted out.
    • i do not think there's a hack to make --inspect work in the interim, unfortunately :(
  • i'm not sure what more we need to figure out. there's a known open issue against our dependency stack, but there is a reliable, non-hacky workaround--just limit usage to the older, but well tested & supported protocol.

debug capability, IMHO, is super important, & this is the 2nd time I've implemented it. i'm not upset, but i do not want to have to do it a 3rd time. can you speak more to why you feel we shouldn't get this in sooner?

@caiobalthazar
Copy link

I strongly agree with @cdaringe, this is very important for productivity and one of the worst parts of CRA testing.

@TheTFo
Copy link

TheTFo commented May 9, 2017 via email

@TheTFo
Copy link

TheTFo commented May 25, 2017

jestjs/jest#1652 has been closed with no action taken.

@gaearon
Copy link
Contributor

gaearon commented May 25, 2017

There is nothing Jest can do to fix it. Please express your support for nodejs/node#7593.

@gaearon
Copy link
Contributor

gaearon commented May 26, 2017

At this point we just need somebody to help push this through.
nodejs/node#9272 (comment)

Any volunteers?

@Timer
Copy link
Contributor

Timer commented May 26, 2017

@cdaringe sorry I didn't respond earlier

why is node's flag deprecation a threat? i don't see any risk here. we only add value/capability in this PR. there's zero loss to stakeholders. we can rev react-scripts later when the jest team gets this sorted out.

It's not so much that it's a threat, but if it becomes something we support, it's turns into our job to maintain that feature going forward.
When Node 8 is released, it is highly likely that --debug will not exist anymore and the only option will be --inspect (because it was removed from v8).

Jest doesn't work with --inspect, so we'd have to tell users to not upgrade their Node versions if they'd like to debug.

This puts us in a bad position because people will expect test debugging to work across all LTS versions of Node (as they should).
IMO, this is plunging us back into the era of JavaScript F***gue where environment matters and tools don't work reliably.

Secondly, Create React App is a toolchain focused at beginners first, but we still consider advanced users and try to accommodate their needs.
Teaching beginners how to debug using a deprecated method and then telling them they have to switch to --inspect (external of our control [based on their environment]) would be painful and cause a potentially poor/confusing experience.

debug capability, IMHO, is super important, & this is the 2nd time I've implemented it. i'm not upset, but i do not want to have to do it a 3rd time.

I'm really sorry that you feel your development efforts are being wasted.
We try really hard to incorporate as many changes as we can and try to ensure developers feel valued. (and we do value your contributions very much, really.)

We will use your work (and not waste it 😄) as a foundation for building out this feature in the future if you are unable to allocate time, but I hope you can understand our position.


I would feel comfortable adding support for --debug if we had a solid timeline and plan for Jest supporting --inspect (which is blocked by Node currently).

@gaearon
Copy link
Contributor

gaearon commented May 26, 2017

I think any effort here should be directed towards unblocking Node. Let's just fix it there.

@Timer
Copy link
Contributor

Timer commented May 31, 2017

Just dropping this here, speculation was correct and --debug is dead:

Joes-MacBook-Pro:16s-website joe$ node --debug
(node:70606) [DEP0062] DeprecationWarning: `node --debug` and `node --debug-brk` are invalid. Please use `node --inspect` or `node --inspect-brk` instead.

Really looking forward to nodejs/node#7593 and nodejs/node#9272 (comment) progressing.

lancefisher pushed a commit to lancefisher/cellularjs that referenced this pull request Jun 1, 2017
Debugging Jest is still broken. See
facebook/create-react-app#2041
@gaearon
Copy link
Contributor

gaearon commented Jun 1, 2017

Doesn’t seem like anybody wants to take ownership 😞 .

@cdaringe
Copy link
Author

cdaringe commented Jun 2, 2017

My support hath been cast!

@Timer Timer mentioned this pull request Jun 6, 2017
@avantgardnerio
Copy link

avantgardnerio commented Aug 7, 2017

This and various related issues have been open since fall 2016. It seems like debugging is a second class citizen in the react/jest/CRA community? I know some folks think if tests are so complicated you need to debug them, then you are doing it wrong, but I personally think a debugger (with good tests) is one of the most productivity enhancing tools of all times. It would give me great confidence in the react community if debugging was a first-class concern.

For starters, not creating profiles in memory or in an obscure temporary folder would be a good step towards making the transpiled code more obvious. Also, doing things in process vs launching a new process would help considerably.

@Timer
Copy link
Contributor

Timer commented Aug 7, 2017

We'd really like to implement this feature but Node does not support it. See nodejs/node#7593 and nodejs/node#9272 (comment).

If you can help implement the feature in Node, that'd be great!

@lifeiscontent
Copy link
Contributor

@Timer can we move forward on this yet now that inspector has been merged in node?

@jgoz
Copy link

jgoz commented Aug 15, 2017

FYI, debugging Jest tests with inspector is now possible as of Node 8.4.0 (nodejs/node#14465).

@avantgardnerio
Copy link

@jgoz Thank you for mentioning that here! I'll upgrade and try it again. I'm very happy to see this fixed!

@gaearon
Copy link
Contributor

gaearon commented Aug 16, 2017

This and various related issues have been open since fall 2016. It seems like debugging is a second class citizen in the react/jest/CRA community?

No. We were just as frustrated about this. Unfortunately we lacked the necessary knowledge (knowing C, understanding of how contexts work in Node and V8) to fix this. We are also glad the fix has landed! Sometimes a hard fix is just a hard fix, and not some intentional choice. :-)

I don't understand what you mean about profiles.

@dchambers
Copy link

Can any provide guidance as to how to debug Jest tests using Node.js 8.4.0? I've so far tried:

npm test -- --inspect-brk

and:

node --inspect-brk node_modules/jest/bin/jest.js -i

with no joy.

@cdaringe
Copy link
Author

@dchambers, see #594 (comment). make sure you're using version 1.0.11+

@dchambers
Copy link

Thanks @cdaringe, upgrading 'react-scripts' to 1.0.11 then running ./node_modules/.bin/react-scripts --inspect --inspect-brk test --env=jsdom --runInBand did it for me 🎉

@Timer
Copy link
Contributor

Timer commented Sep 29, 2017

Closing this as support has been added in 1.0.11, thanks for all of your hard work!

@Timer Timer closed this Sep 29, 2017
@TheTFo
Copy link

TheTFo commented Oct 22, 2017

Hey all,

I think this is broken. I'm having issues with debugging my thinks.

Here's repro branch

https://github.com/TheTFo/cria/tree/jest-debug?files=1

Attempt to debug tests from vscode launcher, placing a break point on the line indicated in comment in this file:

https://github.com/TheTFo/cria/blob/jest-debug/src/actions/todoActions.js

Breakpoints don't appear to hit the appropriate lines. Not sure what's causing it. I don't see transpiled code, just wierd breakpoints hits.

@valoricDe
Copy link

@TheTFo had the same problem. Comment #594 (comment) fixed it for me

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document how to debug unit tests