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

feature/add-first-class-debugging-support-for-tests #1360

Closed

Conversation

cdaringe
Copy link

@cdaringe cdaringe commented Jan 7, 2017

problem statement

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

solution

  • add it!
    • i selected a natural model where --debug-brk and debug are working flags passed to npm test. that is npm test -- --debug-brk works. i think this is a nice entry point into the system.
    • auto-handle other flags that need to be massaged to make debugging work. that is, disable watch and enable runInBand

debug-react-scripts mov

closes #594

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions.

var scriptArgs = [require.resolve('../scripts/' + script)].concat(args);
var debugFlag = getDebugFlag(args);
if (debugFlag) {
scriptArgs.unshift(debugFlag);
Copy link
Author

Choose a reason for hiding this comment

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

note, running node --debug-brk ./node_modules/.bin/react-scripts test --debug-brk will biff on conflicting port access to 5858, if this wasn't clear already. I did not handle this case, but it may be worth discussion?

* Greetings! If you are here attempting to start a debugging session, please
* ensure that your debugger of choice is configured to enable source maps,
* otherwise your code may appear mangled by babel!
*/
Copy link
Author

Choose a reason for hiding this comment

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

🎉 greet the debugging user with some 🌶 🔥 tips

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

if (!isRunInBand) {
argv.push('--runInBand')
}
argv.splice(argv.indexOf(debugFlag), 1)
Copy link
Author

Choose a reason for hiding this comment

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

any of the node debug flags are not valid input to jest. something counter convention i did in this PR was allow a debug flag (like --debug-brk) to enter via argv, where previously all of the other args were jest specific. IMHO, this is OK. the filtering may be cleaner towards the top-of-the-file

@cdaringe
Copy link
Author

cdaringe commented Jan 7, 2017

i'm a little puzzled w/ the CI error. it fails on being unable to locate a file, but only on some node versions. maybe a caching thing? can someone weigh in or re- kick it off?

@tuchk4
Copy link
Contributor

tuchk4 commented Jan 7, 2017

@cdaringe CI fails becasue this require at packages/react-scripts/scripts/test.js

// packages/react-scripts/scripts/test.js

utils dir is not available after eject

@@ -7,3 +7,4 @@ template/src/__tests__/__snapshots__/
lerna-debug.log
npm-debug.log
/.changelog
.vscode
Copy link
Contributor

@EnoahNetzach EnoahNetzach Jan 7, 2017

Choose a reason for hiding this comment

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

Put this IDE ignore in a global .gitignore (@see #958)

@@ -1,5 +1,6 @@
#!/usr/bin/env node
var spawn = require('cross-spawn');
var getDebugFlag = require('../utils/getDebugFlag');
Copy link
Contributor

Choose a reason for hiding this comment

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

For this to work after the eject, you'll probably have to add the right path here.

@cdaringe cdaringe force-pushed the feature/improved-jest-debugging branch from c976b56 to 14d53fb Compare January 7, 2017 20:49
@cdaringe cdaringe changed the title Feature/improved jest debugging feature/add-first-class-debugging-support Jan 7, 2017
@cdaringe cdaringe changed the title feature/add-first-class-debugging-support feature/add-first-class-debugging-support-for-tests Jan 7, 2017
@cdaringe
Copy link
Author

cdaringe commented Jan 7, 2017

thanks @tuchk4, @EnoahNetzach. i dropped the editor ignore commit, rebased w/ patches to restore the build. should be g2g now, post review :)

@cdaringe
Copy link
Author

cdaringe commented Jan 9, 2017

FYI, to reviewers, this also only accepts one flag as written. that is --debug-brk --inspect won't work, but we can do a follow up to add that support later. i'd love for someone to test it out on their box too to validate!

@gaearon gaearon added this to the 0.10.0 milestone Feb 12, 2017
@gaearon
Copy link
Contributor

gaearon commented Feb 12, 2017

Tagging with a milestone because we need to review this.

@cdaringe
Copy link
Author

i'm not entirely in love with the implementation, especially now that --inspect is essentially mainstream. feel free to be harsh

@Gregoor
Copy link

Gregoor commented Mar 23, 2017

Would love to see this land or help in making it happen. Especially as Webstorm/IntelliJ integrated testing would then work with create-react-app (related issue).

@Timer
Copy link
Contributor

Timer commented Mar 23, 2017

I won't have time to review this until first week of April.

xref: https://youtrack.jetbrains.com/issue/WEB-26048

@lifeiscontent
Copy link
Contributor

@Timer any updates on this?

@Timer
Copy link
Contributor

Timer commented Apr 10, 2017

Just added it to my list of soonish TODOs, @lifeiscontent. Thanks for the reminder. ❤️

@lifeiscontent
Copy link
Contributor

@Timer you rock! 👍

@Timer
Copy link
Contributor

Timer commented Apr 10, 2017

Considering that the legacy protocol is dead, I'm not sure if we should implement it (--debug varieties).
See Node docs and Microsoft docs.
Microsoft hints that as of Node 8.x, it (inspect) will be the official and recommended way to debug.

On that note, I'd like to see support for strictly --inspect ^ --inspect-brk.
This isn't the most optimal situation since it's an experimental protocol, however, the community seems to be rallying around it.
VSCode supports it first class, WebStorm uses it, and community packages are deprecating themselves.

Also, we should make sure it supports the port syntax --inspect=4321.
Additionally, I'd like to not extract logic to other files yet as it adds unnecessary review complexity (e.g. babelJestDefault tab, babelJestDebug tab).


@cdaringe do you happen to have any free time to bring this PR up to date?
If not, that's fine and we'll find time to take care of it.

@cdaringe
Copy link
Author

On that note, I'd like to see support for strictly --inspect ^ --inspect-brk.

totally. in agreement.

Also, we should make sure it supports the port syntax --inspect=4321.

yep. agreed.

Additionally, I'd like to not extract logic to other files yet as it adds unnecessary review complexity (e.g. babelJestDefault tab, babelJestDebug tab).

if you can find a way around it, that'd be great!

i'm swamped for a few weeks--i wont be getting to it anytime soon. :(

@quantuminformation
Copy link

So looking fwd to this, it will also enable Jetbrains to debug JSX:

https://youtrack.jetbrains.com/issue/WEB-26048

@Timer
Copy link
Contributor

Timer commented Apr 12, 2017

@cdaringe not a problem, thanks so much for letting me know!

babelrc: false
});
const babelJestDebugConfig = require('./babelJestDebugConfig');
module.exports = babelJest.createTransformer(babelJestDebugConfig);
Copy link
Author

Choose a reason for hiding this comment

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

this was probably supposed to be Default v Debug?


const babelTransform = isEjecting
? '<rootDir>/node_modules/babel-jest'
: resolve('config/jest/babelTransform' + (isDebug ? 'Debug' : '') + '.js')
Copy link
Author

@cdaringe cdaringe Apr 12, 2017

Choose a reason for hiding this comment

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

@Timer, 👀, this is where/why there were two babelTransform files. we are passing the babel config as a file path, therefore, to enable sourceMaps, i added a different file. if there's another way to get those babel settings passed to jest, we could pursue that. we could also set something in the ENV to drop it down to one transform file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I hadn't reviewed deep enough to have this understanding.
Thanks for explaining!

I'll snoop around and see what our best option(s) are. 😄

@thg303
Copy link

thg303 commented Apr 20, 2017

would somebody pleeaaase merge this! I am pulling my hairs on debugging for a week now :'(

@quantuminformation
Copy link

@thg303 you should have some hairs left before webstorms 2017.2 release

@Timer
Copy link
Contributor

Timer commented Apr 20, 2017

Sorry for the delay @thg303.
It's happening soon, I promise!

@cdaringe
Copy link
Author

moving to #2041

@cdaringe cdaringe closed this Apr 28, 2017
@cdaringe cdaringe deleted the feature/improved-jest-debugging branch April 28, 2017 08:48
@avantgardnerio
Copy link

The solution does not work for me, I can't figure out how to debug jest.

@cdaringe
Copy link
Author

cdaringe commented Aug 7, 2017

It's super old on the react-scripts time scale, I wouldn't expect it to

@avantgardnerio
Copy link

For those who are also stuck, it looks like you can downgrade to node 7.10 to debug:

nodejs/node#7593

@lock lock bot locked and limited conversation to collaborators Jan 21, 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