Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

3.5K
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!