Chai-http test returns "Error: getaddrinfo EAI_AGAIN undefined" with Github Actions

Viewed 648

I'm learning how to unit test a REST API with chai-http. The test runs smoothly on local, but throws this error when running on github as a CI check on a PR:

  Jobs
    GET /jobs
    get jobs error =>  Error: getaddrinfo EAI_AGAIN undefined
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
  errno: -3001,
  code: 'EAI_AGAIN',
  syscall: 'getaddrinfo',
  hostname: 'undefined'
}

The code of the test:

// Import the dependencies for testing
const chai = require("chai");
const chaiHttp = require("chai-http");
const { app } = require("../index");

// Configure chai
chai.use(chaiHttp);
chai.should();

describe("Jobs", () => {
  describe("GET /jobs", () => {
    it("should get all jobs record", (done) => {
      chai
        .request(app)
        .get("/jobs")
        .end((err, res) => {
          res.should.have.status(200);
          res.body.should.be.a("array");
          done();
        });
    });
  });
});

As you can see I test the server importing it directly .request(app) but I have also tried pointing to localhost:port with the same error.

I see this is a problem with the hostname and the DNS, but I don't know how to setup the CI script and/or the test to work properly under Github.

Any insights about this? Thanks in advance.

0 Answers
Related