jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.21k stars 6.46k forks source link

process beforeExit event not called #10927

Open OoDeLally opened 3 years ago

OoDeLally commented 3 years ago

🐛 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
cowboyd commented 2 years ago

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

cowboyd commented 2 years ago

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 commented 2 years ago

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

eladchen commented 2 years ago

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

Are there any work arounds?

cowboyd commented 2 years ago

@eladchen I have not been able to find any 😢

xbc5 commented 2 years ago

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

cowboyd commented 2 years ago

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

github-actions[bot] commented 1 year ago

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.

cowboyd commented 1 year ago

👍🏻

vsDizzy commented 1 year ago

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
mccolljr commented 8 months ago

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.