1

I joined a group building a product with Node, Webpack, TypeScript and Express/Feathers. Other developers know what they are doing, but I have only used JavaScript on a client until now and have literally only a few hours of Node under my belt. Trying to figure out how to go about debugging. Specifically, my first task is to fix some failing API tests.

Tests are executed with:

$npm run testserver

My package has:

"scripts": {
....
"testserver": "webpack --config webpack.servertest.config.js && NODE_ENV=test mocha dist/serverTests.js",
....
},

The routine is to compile typescript into ES6 then babel to ES5 compatible with Node.

I tried doing:

$node-debug dist/serverTests.js

When this node-debug invocation runs, the results are not the same as with npm. Please share your experience.

Thank you

4

1 回答 1

1

根据您的设置,我可以推荐您尝试 Visual Studio Code、基于 Electron 的 OS 文本编辑器/ide 以及 Atom 编辑器。

要解决您的问题,您可以使用两个 vscode 功能:

  • 调试- 文档链接如何在 vscode 中调试
  • 任务- 任务管理,例如查看以一些 args 等开头的 webpack 配置

首先,让我们尝试一下可能适合您的情况的简单解决方案(不需要任务文件):

添加到 testserver 的末尾,--debug-brk它用于在 node.js 中进行调试,brk - 它只是在第一行停止执行。

"testserver": "webpack --config webpack.servertest.config.js && NODE_ENV=test mocha dist/serverTests.js --debug-brk",

现在,当你npm run testserver,mocha 以调试模式启动时,在控制台中你会看到类似Debugger listen on port 5858

第二步,在 vscode 中,您需要将一些道具(端口 5858)添加到launch.json - 阅读我上面提到的文档中的调试部分:

{
  "version": "0.1.0",
  "configurations": [
    {
      "name": "Attach", // or e.g. "Mocha Debug"
      "type": "node",
      "request": "attach",
      "port": 5858
    }
  ]
}

就是这样。在 vscode 中进入调试模式,在测试文件中放置断点,在下拉菜单中选择“附加”或“摩卡调试”并开始调试(F5)

ps 此外,VS 代码具有一流的 TypeScript 支持,可能对您有所帮助。

于 2015-12-07T20:50:23.183 回答