never-dispose.mjs 649 B

123456789101112131415161718
  1. /** Test-only Cordis plugin whose disposer announces entry and never settles. */
  2. import { existsSync } from 'node:fs'
  3. /**
  4. * Register a disposer that keeps process shutdown pending until it is forced.
  5. * @param {import('cordis').Context} ctx - loader-mounted test plugin context.
  6. */
  7. export function apply(ctx) {
  8. const keepAlive = setInterval(() => {}, 60_000)
  9. ctx.effect(() => async () => {
  10. clearInterval(keepAlive)
  11. const armFile = process.env.DSH_TEST_SHUTDOWN_ARM_FILE
  12. if (armFile === undefined || !existsSync(armFile)) return
  13. process.stderr.write('dsh-test: never-dispose started\n')
  14. await new Promise(() => {})
  15. })
  16. }