node.js - EADDRINUSE 127.0.0.1 :5858 during jest test debugging

标签 node.js debugging jestjs

在调试 Jest 时避免抛出以下错误测试:

Error: listen EADDRINUSE 127.0.0.1:5858
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at Agent.Server._listen2 (net.js:1262:14)
    at listen (net.js:1298:10)
    at doListening (net.js:1397:7)
    at _combinedTickCallback (internal/process/next_tick.js:77:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

我运行我的测试使用

node --harmony --debug-brk=5858 node_modules/.bin/jest

问题是 Jest 正在 fork 新进程来运行测试,而新进程正试图绑定(bind)到与父进程相同的调试端口(在本例中为 5858),而该端口已被父进程占用。

奇怪的是这个错误经常发生但并不总是发生。有时上面的命令实际上允许调试测试。

最佳答案

使用 --runInBand jest 选项。来自文档:

--runInBand, -i
Run all tests serially in the current process (rather than creating a worker pool of child processes that run tests). This is sometimes useful for debugging, but such use cases are pretty rare. [boolean]

它只是防止 Jest fork 。

node --harmony --debug-brk=5858 node_modules/.bin/jest --runInBand

关于node.js - EADDRINUSE 127.0.0.1 :5858 during jest test debugging,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41733634/

相关文章:

typescript - 如何配置 Jest 以转换包含无效语法的模块?

node.js - 使用 require() 时 IO.js 1.4.3 中的 Jest (JS) 段错误 11

react-native - Jest Redux 持久化 : TypeError: Cannot read property 'catch' of undefined at writeStagedState

c# - 在远程服务器上调试 Web 服务

node.js - Electron 应用程序 : Reference mainWindow object in another module?

javascript - Sequelize : how to get flattened data, 基于嵌套关联加入表时?

Javascript,异步并返回到完全相同的地方

python - 在 Spyder 中设置断点不起作用

c++ - Valgrind 调试结果不显示发生错误的行数

node.js - 解析管道响应有时会得到分块数据