在调试 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/