玩笑测试调试期间EADDRINUSE 127.0.0.1:5858 [英] EADDRINUSE 127.0.0.1:5858 during jest test debugging
问题描述
为避免在调试 Jest 测试期间抛出以下错误,请注意:
Hot to avoid following error to be throw during debugging of Jest tests:
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分叉了新进程来运行测试,并且新进程试图绑定到与父进程相同的调试端口(在本例中为5858),并且该端口已被父进程占用.
The problem is that Jest is forking new process to run tests and the new process is trying to bind to the same debug port (5858 in this case) as parent process and the port is already occupied by the parent process.
奇怪的是,此错误经常发生,但并非总是如此.有时上述命令实际上允许调试测试.
Weird thing is that this error happens often but not always. Sometime the command above actually allowed to debug the tests.
推荐答案
使用-runInBand
jest
选项.来自文档:
Use --runInBand
jest
option. From documentation:
-runInBand,-i
在当前过程中依次运行所有测试(而不是创建一个孩子的工人池运行测试的流程).有时候是对于调试很有用,但是这种用例是很少见[布尔]
--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分叉.
It simply prevents Jest from forking.
node --harmony --debug-brk=5858 node_modules/.bin/jest --runInBand
这篇关于玩笑测试调试期间EADDRINUSE 127.0.0.1:5858的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!