2

enter image description hereI just started using Jest. For debugging under testcase file;

  describe("Filter function", () => {
  test("it should filter by a search", () => {
    const input = [
      { id: 1, url: "https://www.google.com" },
      { id: 2, url: "https://www.yahoo.com" },
      { id: 3, url: "https://www.gmail.com" }
    ];

    const output = [{ id: 3, url: "https://www.gmail.com" }];
    debugger;
    expect(filterByTerm(input, "gmail")).toEqual(output);
    debugger;
    expect(filterByTerm(input, "GMAIL")).toEqual(output);
  });

 
});

under Project directory - run this command

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

After running this command says node --inspect-brk node_modules/jest/bin/jest.js --runInBand Debugger listening on ws://127.0.0.1:9229/ab651461-dfe8-4528-8a07-484a4be5db7b For help, see: https://nodejs.org/en/docs/inspector

after this opened chrome://inspect under it clicked on open dedicated devtools for Node here, It opened window where I added src folder for same and opened test file but debugging didnt came. Help please on same issue

enter image description here However, in the resulting dev tools window, I can't see anything to debug. I am expecting a process where I can set breakpoints and inspect data.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Swift
  • 829
  • 2
  • 12
  • 33
  • Did you click F8 then check on terminal if the test has passed? – tmhao2005 Aug 31 '20 at 15:10
  • @tmhao2005, if something would prompt on screen, F8 is pressed but at debugger line nothing is highlighting. – Swift Aug 31 '20 at 15:39
  • Attched screenshot for reference. @EstusFlask – Swift Aug 31 '20 at 17:17
  • What about Node part? It's unknown what happens there and whether tests run at all. If `debugger` statements is executed, this should be reflected in a debugger. That this doesn't happen suggests that it may not. How exactly was Filter.test.ts opened? Did it open itself? The question doesn't mention that you use TS. It could be something in your setup that wasn't shown. – Estus Flask Aug 31 '20 at 18:12
  • @EstusFlask, nothing is executed at node part. Filter.test.ts is not opened by itself. I opened it as nothing is happening on that node window. Debugger is never executed. And nothing reflected in debugger. That is my question at all ! – Swift Aug 31 '20 at 18:17
  • I see. Debugging clearly doesn't run, otherwise you wouldn't need to open devtools yourself and Filter.test.ts would be open automatically. Node process should appear under "Remote Target", then it can be inspected like [this](https://miro.medium.com/max/1326/1*x4VXx50dLdD_HbqE6hpIRw.png) . No "open dedicated devtools for Node" is needed. That this happens means that something went wrong on your side. I'm unaware of possible causes. Probably Node or Chrome are too old. – Estus Flask Aug 31 '20 at 18:26
  • @EstusFlask, Node process should appear under "Remote Target". In my issues this is not opening attached screenshot for same – Swift Aug 31 '20 at 18:32
  • Google Chrome is up to date Version 85.0.4183.83 (Official Build) (64-bit) , @EstusFlask – Swift Aug 31 '20 at 18:33
  • node -v is 12.15.0 @EstusFlask – Swift Aug 31 '20 at 18:33
  • Doesn't seem suspicious to me. Node keeps showing `... For help, see: https://nodejs.org/en/docs/inspector` with no other changes no matter what, doesn't it? Try some other Chrome-based browser like Chromium portable. You can also try to connect this way instead of `chrome://inspect`, https://stackoverflow.com/a/62069009 . Should be something like `devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/ab651461-dfe8-4528-8a07-484a4be5db7b` (change to your current url, omit `ws://` part) – Estus Flask Aug 31 '20 at 18:41
  • works like charm ! Thank you so much @EstusFlask – Swift Aug 31 '20 at 18:47
  • Thank you so much @EstusFlask – Swift Aug 31 '20 at 18:53
  • Does this answer your question? [How do you debug Jest Tests?](https://stackoverflow.com/questions/33247602/how-do-you-debug-jest-tests) – Liam Sep 01 '20 at 10:09

1 Answers1

2

Run this command;

node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand
Debugger listening on ws://127.0.0.1:9229/6a0bb29e-eca2-4a25-b894-a5e803339ec9
For help, see: https://nodejs.org/en/docs/inspector

After this enter this url in chrome;

devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/6a0bb29e-eca2-4a25-b894-a5e803339ec9

and Resume the button on right hand side again Press again F8 wait for some time, Debugging started Like charm..! on your test file where debugger; is written

Thank you again ! enter image description here

Swift
  • 829
  • 2
  • 12
  • 33