node/test/fixtures/process/before-exit.mjs
Vinicius Lourenço 05bb4a716b
process: port on-exit-leak-free to core
PR-URL: https://github.com/nodejs/node/pull/53239
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
2024-07-11 17:57:20 +00:00

32 lines
704 B
JavaScript

import { strictEqual } from 'assert'
function setup() {
const obj = { foo: 'bar' }
process.finalization.registerBeforeExit(obj, shutdown)
}
let shutdownCalled = false
let timeoutFinished = false
function shutdown(obj, event) {
shutdownCalled = true
if (event === 'beforeExit') {
setTimeout(function () {
timeoutFinished = true
strictEqual(obj.foo, 'bar')
process.finalization.unregister(obj)
}, 100)
process.on('beforeExit', function () {
strictEqual(timeoutFinished, true)
})
} else {
throw new Error(`different event, expected beforeExit but got ${event}`)
}
}
setup()
process.on('exit', function () {
strictEqual(shutdownCalled, true)
})