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

3.5K
Vistas
Jest - A worker process has failed to exit gracefully and has been force exited

I have a test file called integration.test.js

import app from "../app";
import request from "supertest";

describe("testing /users", () => {
  const app = request(app);
  // 5 test cases here. Both use app for api testing
})

describe("testing /images", () => {
  const app = request(app);
  // 6 test cases here. Both use app for api testing
})

describe("testing /blogs", () => {
  const app = request(app);
  // 7 test cases here. Both use app for api testing
})

When I run jest to run the test cases, it returns a warning

A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try runn
ing with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.

It also takes around 5 seconds to complete the testing, which seems to be slow

How can I fix the warning and the time of running the test cases?

app.js

import express from "express";

const app = express();
const PORT = process.env.PORT || 3000;

app.use(express.json());

app.get("/", (req, res) => {
  res.status(200).send("Hello");
});

app.post("/users", (req, res) => {...});
app.post("/images", (req, res) => {...});
app.post("/blogs", (req, res) => {...});


app.listen(PORT, () => {
  console.log(`Server running on ${PORT}`);
});

export default app;
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I am guessing it's related to asynchronous behaviour, maybe try to use async for test case.

Example:

const supertest = require('supertest')
const app = require('../app')
const api = supertest(app)

describe("testing /users", () => {
    test('get all users', async () => {
        await api
            .get('/api/users')
            .expect(200)
            .expect('Content-Type', /application\/json/)
    })
})
over 4 years ago · Santiago Trujillo Denunciar
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