Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mocha supertest ECONNRESET

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 fails with this error:

{ [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

If I comment out some tests that run earlier, the tests that cause the error change. What is causing this insanity?

like image 1000
Christian Smith Avatar asked Feb 22 '14 01:02

Christian Smith


People also ask

What is the difference between Mocha and Chai in Supertest?

Mocha fits in nicely with SuperTest, helping you organize your tests in your team's preferred way. Chai is an assertion library that you can pair with other testing frameworks like Mocha. While not strictly necessary for writing a test suite, it provides a more expressive and readable style for your tests.

How does Mocha report my test results?

If everything works as expected, Mocha will execute your tests and show your test results. The default reporter shows the description of your tests, grouped by the describe method, and displays the results and the execution time for each test.

What is Mocha testing framework?

The Mocha testing framework organizes and runs your tests in the way your team prefers, whether its TDD or BDD style. Chai's assertions fit in nicely with Mocha to validate your API responses.

How do I set up Supertest and Mocha in NPM?

First, create a new project inside an empty directory and initialize it by running npm init-y to create a default package.json file. For now, you don't have to edit this file. With the project initialized, you can set up the latest versions of SuperTest, Mocha, and Chai libraries with the following command:


1 Answers

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.

like image 138
Christian Smith Avatar answered Sep 29 '22 08:09

Christian Smith