I would like to have something like binding.pry in ruby, basically, I want to be able to add a line to my code, and have a debugger stop there, while karma is running my angular/jasmine tests
it('runs my jasmine test', function () {
var a = true;
binding.pry // stops code and enters REPL prompt
expect(a).toBe(true);
});
The result would then be a prompt
#
Where I could do things to the variables available in that scope, at that point in time
# a = false;
Then I could exit and continue execution.
# exit
Just like debugging with dev tools, but I would like to have this outside of the browser environment and inside the terminal under a karma process. I've also found https://github.com/alidavut/locus, however it doesn't seem to work under karma.
I'm not aware of any way to launch a repl in the karma process, but what you can do is simply write:
debugger;
at the point where you want to debug. Then, if you have the browser's dev tools already open when that line is executed, the execution will pause and you'll be able to use "watch expressions" which might be enough for you. You have access to the call stack and all the local variables. You can also assign to local variables in a watch expression and the new values will persist when you resume execution.
I've only tested this on Chrome. What I have to do is:
debugger;
statement in.Making a REPL on the karma side would require a lot more effort as all the test code is executed on the browser. To control a REPL from the karma process you would need to setup events to communicate via the sockets that karma sets up to talk to the browser. Should be doable though if you're so inclined. EDIT: actually, to do this you would still need to be able to make Javascript block execution at a particular statement, and I'm pretty sure that debugger;
is the only way to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With