У меня есть веб-приложение с около 4000 тестов маршрутов.Сейчас я вижу регулярные сбои без согласованности: 1 сбой, 3 сбоя, проход - 2 примера:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/markry/workspace/personal/supertest-example/tests.spec.js)
Uncaught TypeError: Cannot read property 'body' of undefined
Рабочий пример может быть выполнен с использованием: https://github.com/joshmatz/supertest-example и переносом цикла forвокруг теста.
for (step = 0; step < 5000; step++) {
it('should have return version number', function(done) {
request(app)
.get('/api')
.end(function(err, res) {
expect(res.body.version).to.be.ok;
expect(res.statusCode).to.be.equal(200);
done();
});
});
}
Это ограничение хоста?Как я могу отладить это?
Спасибо:)
----- ОБНОВЛЕНИЕ -----
Если я использую SuperAgent (https://github.com/visionmedia/superagent) IПолучите 100% надежность с нижеуказанным:
for (step = 0; step < 5000; step++) {
it('should have return version number', function(done) {
request
.get('http://localhost:3000/api')
.end(function(err, res) {
expect(res.body.version).to.be.ok;
expect(res.statusCode).to.be.equal(200);
done();
});
});
}
Также добавил этот фрагмент к server.js:
// take the port or set it to 3000
const port = process.env.PORT || 3000;
console.log('port=' + port)
// start the server
app.listen(port);
Я изменяю свои тесты для использования SuperAgent:)