jest icon indicating copy to clipboard operation
jest copied to clipboard

process beforeExit event not called

Open OoDeLally opened this issue 5 years ago • 16 comments

🐛 Bug Report

beforeExit event is never called.

We are using this event to release resources of a Rust library upon object's garbage collection, using https://github.com/node-ffi-napi/weak-napi.

To Reproduce

process.on('beforeExit', () => {
    console.log('beforeExit')
})


describe('mytest', () => {

    it('should do stuff', () => {
        console.log('hey')
    })
})

Expected behavior

We should see beforeExit logged.

The same test works fine with Mocha, where beforeExit is successfully called.

envinfo

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 12.19.1 - ~/.nvm/versions/node/v12.19.1/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.1/bin/npm

OoDeLally avatar Dec 07 '20 16:12 OoDeLally

Just hit this. Any thoughts? It seems not so great that this doesn't work.

cowboyd avatar Jan 20 '22 12:01 cowboyd

As part of my other bug report I went ahead and added a reproduction for this bug as well since they might be related? https://github.com/cowboyd/jest-suite-hooks-on-sigint

cowboyd avatar Jan 21 '22 12:01 cowboyd

@OoDeLally It should also be noted that the same holds true for the exit event.

cowboyd avatar Jan 21 '22 12:01 cowboyd

Any thoughts on how we can contribute to the resolution of this?

Are there any work arounds?

eladchen avatar Mar 13 '22 16:03 eladchen

@eladchen I have not been able to find any 😢

cowboyd avatar Mar 13 '22 21:03 cowboyd

This is still the case in 27.5.1, it really shouldn't be.

xbc5 avatar Jun 07 '22 17:06 xbc5

Strong agree. Hopefully with Facebook setting this project free this will get some attention.

cowboyd avatar Jun 08 '22 11:06 cowboyd

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jun 08 '23 12:06 github-actions[bot]

👍🏻

cowboyd avatar Jun 08 '23 17:06 cowboyd

Just faced this with pino transport which runs in a worker thread and listens to the 'beforeExit' event:

Jest has detected the following 1 open handle potentially keeping Jest from exiting

vsDizzy avatar Sep 27 '23 23:09 vsDizzy

I just ran into this. We use this handler to ensure that certain child processes spawned by a service is killed when the program exits, but it doesn't work under jest.

mccolljr avatar Feb 21 '24 15:02 mccolljr

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Feb 20 '25 16:02 github-actions[bot]

Not stale

mccolljr avatar Feb 20 '25 16:02 mccolljr

Jest is stale, I switched to node --test and it can also run TypeScript files.

vsDizzy avatar Feb 20 '25 16:02 vsDizzy

how to fix pino memory leak with jest ?

sibelius avatar Oct 31 '25 16:10 sibelius

Disappointing that this has been open for 5 years and nobody from the Jest team has responded to it 🫤

rix0rrr avatar Nov 27 '25 10:11 rix0rrr