Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
Mocha and Chai test never starts when running an Express app

I'm trying to test an Express API with Mocha and Chai. My structure is as follows: server.js

const express = require('express');
...

const loadCredentials = () => ({
  ...
})

const application = () => {
  console.log('This is a log i should always see');
  const app = express();
  app.use('/api', authentication, authorization('@data/accounts'), router);
  ...
  return app;
};

if (require.main === module) {
  application.listen(443)
  ...
}

module.exports = { application };

test.js

const { application } = require('../server/src/server');
describe('Some async test', async () => {
  it(, async () => {
    console.log('I should really see this log!!');
    server = application();
    const res = await chai.request(server).get('/api');
    ...test stuff...
  }
}

When I lerna run test (which runs mocha ./test.js --timeout 60000) the test never executes.

lerna notice cli v3.10.7
lerna info Executing command in 1 package: "yarn run test"

However, if I disable the call to application, the test starts (and fails because server is undefined). I also tried refactoring application and passing an express() parameter to application(app) from the test, and I get the same behavior.

The test runs if I run it from WebStorm as an individual test. Needless to say the server works when I yarn run it. Any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda