Test Time out - Quality Assurance

Hi, I am passing most of the tests in replit but it times out in the end, I already changed the this.timeout(10000); but I am getting still this error: `Functional Tests with Zombie.js
1) “before all” hook in “Functional Tests with Zombie.js”

22 passing (6s)
1 failing

  1. Functional Tests with Zombie.js
    “before all” hook in “Functional Tests with Zombie.js”:
    Error: Timeout: did not get to load all resources on this page
    at Timeout.timeout (node_modules/zombie/lib/eventloop.js:436:36)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7)`

Any chance I am doing something wrong? I am on the Simulate Actions Using a Headless Browser challenge

This is my code:

const chai = require('chai');
const assert = chai.assert;

const server = require('../server');

const chaiHttp = require('chai-http');
chai.use(chaiHttp);

suite('Functional Tests', function () {
  this.timeout(5000);
  suite('Integration tests with chai-http', function () {
    // #1
    test('Test GET /hello with no name', function (done) {
      chai
        .request(server)
        .get('/hello')
        .end(function (err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.text, 'hello Guest');
          done();
        });
    });
    // #2
    test('Test GET /hello with your name', function (done) {
      chai
        .request(server)
        .get('/hello?name=stephanie')
        .end(function (err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.text, 'hello stephanie');
          done();
        });
    });
    // #3
    test('Send {surname: "Colombo"}', function (done) {
      chai
        .request(server)
        .put('/travellers')
        .send({ "surname": "Colombo" })
        .end(function (err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.type, 'application/json');
          assert.equal(res.body.name, "Cristoforo");
          assert.equal(res.body.surname, "Colombo");
          done();
        });
    });
    // #4
    test('Send {surname: "da Verrazzano"}', function (done) {
      chai
        .request(server)
        .put('/travellers')
        .send({ "surname": "da Verrazzano" })
        .end(function (err, res) {
          assert.equal(res.status, 200);
          assert.equal(res.type, 'application/json');
          assert.equal(res.body.name, "Giovanni");
          assert.equal(res.body.surname, "da Verrazzano");
          done();
        });
    });
  });
});

const Browser = require('zombie');
Browser.site = 'https://boilerplate-mochachai.eriglesias.repl.co';
const browser = new Browser();

suite('Functional Tests with Zombie.js', function () {
  this.timeout(10000);

  suiteSetup(function(done) {
    return browser.visit('/', done);
  });
  
  suite('Headless browser', function () {
    test('should have a working "site" property', function() {
      assert.isNotNull(browser.site);
    });
  });

  suite('"Famous Italian Explorers" form', function () {
    // #5
    test('Submit the surname "Colombo" in the HTML form', function (done) {

      browser.fill('surname', 'Colombo').then(() => {
        browser.pressButton('submit', () => {
          browser.assert.success();
          browser.assert.text('span#name', 'Cristoforo');
          browser.assert.text('span#surname', 'Colombo');
          browser.assert.elements('span#dates', 1);
          done();
        });
      });
    });
    // #6
    test('Submit the surname "Vespucci" in the HTML form', function (done) {
      browser.fill('surname', 'Vespucci').then(() => {
        browser.pressButton('submit', () => {
          browser.assert.success();
          browser.assert.text('span#name', 'Amerigo');
          browser.assert.text('span#surname', 'Vespucci');
          browser.assert.elements('span#dates', 1);
          done();
        });
      });
    });
  });
});

You must be using an old boilerplate without the .keepOpen() method in the chain.

Add .keepOpen() after all the .request(server) calls.

chai
  .request(server)
  .keepOpen()

You can look at the starting code for more help to where it should be.

https://github.com/freeCodeCamp/boilerplate-mochachai/blob/main/tests/2_functional-tests.js


Please also add the link to your Replit (the editor, not the live URL) when asking for help.

1 Like

Hello lasjorg thank you for answering my question. I tried and added the .keepOpen() but I am still getting a time out in the tests with Zombie.js, the this.timeout was also increased to 10000 but nothing seems to work.

This is where the replit code is located: Replit code

Screenshot 2023-07-14 at 11.20.37

Try removing this.timeout(5000) (or whatever you have it set to). You may have to run it a few times, when it passes leave it running and submit the URL.

The tests are a little flaky on Replit. If it doesn’t work, doing it locally is an option (and always works in my experience).

yeah I get " Error: Timeout of 2000ms exceeded." when I remove the this.timeout I will consider doing it locally thanks again.

Did you change the code again? You need to keep the .keepOpen() calls as mentioned before.

I left the keepOpen() , and a timeout of 10000 but I am still getting this error :frowning: 1) Functional Tests with Zombie.js
“before all” hook in “Functional Tests with Zombie.js”:
Error: Timeout: did not get to load all resources on this page
at Timeout.timeout (node_modules/zombie/lib/eventloop.js:436:36)
at listOnTimeout (node:internal/timers:564:17)
at process.processTimers (node:internal/timers:507:7)

.keepOpen() has to be in the code no matter what. You are not supposed to remove the timeout and .keepOpen() only the timeout.

Anyway, as I said you can do this locally and it doesn’t take long to set up.

It’s working locally thanks for your help.