alsotang / node-lessons

:closed_book:《Node.js 包教不包会》 by alsotang
16.54k stars 4.7k forks source link

兼容新版本依赖下,运行测试用例时重复监听同一端口的问题 #166

Open CHristopherkeith opened 5 years ago

CHristopherkeith commented 5 years ago

兼容高版本环境下的测试用例

高版本环境下: Node.js: 10.15.2 mocha: 6.1.4 should: 13.2.3 supertest: 4.0.2 express: 4.17.0

运行测试用例会占用3000端口,可能导致: 1.app已运行的情况下,会报端口已被占用的错误 2.app没有运行,测试用例运行后没有退出,继续监听端口

解决方法: 根据module.parent判断是否为运行测试用例,是的话则不监听端口