mocha supertest ECONNRESET

前端 未结 1 1980
执念已碎
执念已碎 2021-02-08 23:17

I\'m testing a Nodejs server with Mocha and Supertest. The test suite has grown to more than 1500 tests. Suddenly, although all of the code under test still works, my test suite

1条回答
  •  北海茫月
    2021-02-08 23:31

    I found the answer in this Google Groups post by Mike Gradek:

    We used mocha and supertest to issue these requests, and realized that we were actually spinning up new port bindings on every request instead of reusing existing bindings.

    So code that was written like so:

    var request = require('supertest');
    var app = require('../app');
    request(app).get(...);
    request(app).get(...);
    

    Became

    var request = require('supertest');
    var app = require('../app');
    var supertest = request(app);
    supertest.get(...);
    supertest.get(...);
    

    That solved the issue for us.

    And for me as well.

    0 讨论(0)
提交回复
热议问题