使用Mocha.js时,node.js套接字挂起

我正在使用节点v6.2.0并通过Mocha&Chai进行testing。

我写了一个API,当我用邮递员/网站/节点CLItesting它,它的工作很好,但是当我使用摩卡来testing它,我得到一个错误,说:

{[错误:连接ECONNREFUSED 127.0.0.1:4001]代码:'ECONNREFUSED',errno:'ECONNREFUSED',系统调用:'连接',地址:'127.0.0.1',端口:4001}

现在,事情是,在http://localhost:4001testing连接的先前testing工作正常…

这是testing代码 –

 describe('/api/getAlbums', function () { this.timeout(5000); it('should get an array of 4 objects', function (done) { http.get('http://localhost:4001/api/getAlbums?uid=some_uid', function (res) { console.log(`Got response: ${res.statusCode}`); done(); }).on('error', (e) => { console.log(`Got error: ${e.message}`); console.log('e', e); done(); }); }); }); 

再次,当我在CLI中运行相同的function(没有done(); ),它工作正常。

我去了很多文件,但找不到任何东西,很想得到你的帮助,谢谢。

问题的根源是nodemon。 看起来有一个同步问题。 我已经添加了“testing”文件夹nodemon.json的忽略,现在一切正常。