Thursday, 19 March 2020

Tips/tricks for getting Mocha & Chrome Developer Tools to play nice?

'Would love to know if someone has a better way of dealing with the following...Some Mocha-based unit test, "sometest.js", starts failing."No problem, let's spin up Mocha and Chrome Developer Tools and see what's going on."Run mocha --inspect sometest.js... Watch as test runs to completion and exits, with no opportunity to view or set breakpoints in the Developer Tools."That was silly. Why did I think that would be helpful...?"Try again, this time with mocha --inspect-brk sometest.js. Developer Tools attach and pause execution at the first line of mocha."Okay, now we're getting somewhere..."Find sometest.js in the "Sources" tab and set a breakpoint."Wait, where's sometest.js?!? Oh, right, we're paused at the start of mocha. sometest.js hasn't loaded yet. \sigh*"*Hit resume to see if sometest.js loads. Watch as mocha runs to completion and exits. Still no opportunity to view or set breakpoints."\Dooh* Why did I think that was a good idea?*"Repeat, but don't hit "Resume". Instead, step through Mocha code until you get to where sometest.js is loaded."Step, step, step... step... step... Ugh, what is all this stuff? Where the hell is sometest.js???"Give up and just manually edit sometest.js to add a debugger statement. Try again with --inspect-brk, .debugger attaches. Hit Resume to run until the debugger line... and now we're (finally) paused in code we actually recognize. Yay."Whew, finally! Now where were we ...?"Find and fix problemgit commit -am "fixed the bug""Crap..."... clicky clicky tap tapgit commit sometest.js -m "remove debugger statement"If you've made it this far, my apologies for the sarcasism. I've done enough variations on this theme that I am embittered by it, and sarcasm is useful coping mechanism. Hopefully this illustrates the problem. I'd love to have a way of running mocha that allows for attaching and setting breakpoints in Developer Tools without having to edit my test files each time.I've actually written my own mocha knockoff to make this process simpler, but I have to think there's a better way.

Submitted March 19, 2020 at 01:33PM by broofa

No comments:

Post a Comment