Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

316
Visualizações
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;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

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/)
    })
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda