REPL tool for angular / jasmine / karma

I would like to have something like bind.pry in ruby, basically I want to be able to add a line to my code and disable the debugger while karma runs 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); }); 

Then the result will be an invitation

#

Where could I do things with variables available in this area at this 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 the browser environment and inside the terminal in the process of karma. I also found https://github.com/alidavut/locus , however it does not work under karma.

+6
source share
1 answer

I do not know how to start a replica in the process of karma, but you can simply write:

 debugger; 

at the point where you want to debug. Then, if you already have the dev developer tools, when this line is executed, execution is paused and you can use the "expressions for viewing", which may be enough for you. You have access to the call stack and all local variables. You can also assign local variables in a clock expression, and new values ​​are saved when execution resumes.

I tested this only in Chrome. I have to do it:

  • Place the debugger; statement debugger; in.
  • The beginning of karma.
  • Open Chrome dev tools.
  • Save one of the viewed karma files (so now the tests will run again with the tools already open).
  • Profit!

Performing REPL on the karma side will require much more effort, since all the test code is executed in the browser. To control REPL from the karma process, you need to configure events for communication through sockets, which karma sets up to talk to the browser. Must be doable, though if you are so addicted. EDIT:, for this you will still need to execute the Javascript block in a specific expression, and I’m that debugger; is the only way to do this.

+3
source

Source: https://habr.com/ru/post/981074/


All Articles