无法在节点 devTools 下使用 Jest 在 chrome 中调试测试用例

IT技术 node.js reactjs react-native jestjs
2022-07-29 23:48:01

在此处输入图像描述我刚开始使用 Jest。用于测试用例文件下的调试;

  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);
  });

 
});

在项目目录下 - 运行此命令

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

运行此命令后说 node --inspect-brk node_modules/jest/bin/jest.js --runInBand 调试器正在监听 ws://127.0.0.1:9229/ab651461-dfe8-4528-8a07-484a4be5db7b 如需帮助,请参阅:https://nodejs.org/en/docs/inspector

在此打开 chrome://inspect 后,单击此处为节点打开专用开发工具,它打开了窗口,我在其中添加了相同的 src 文件夹并打开了测试文件,但调试没有出现。请帮助解决同样的问题

在此处输入图像描述 但是,在生成的开发工具窗口中,我看不到任何要调试的东西。我期待一个可以设置断点和检查数据的过程。

1个回答

运行此命令;

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

之后在chrome中输入这个url;

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

并再次恢复右侧的按钮再次按下 F8 等待一段时间,调试开始像魅力一样..!在您的测试文件中调试器;写着

再次感谢你 !在此处输入图像描述