From 057f00b7532f6a9e9d8465c89d23917ff22fc287 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Sat, 29 Aug 2026 17:17:32 +0200 Subject: [PATCH] test: use fs.watch for the async leak fixture --- test/e2e/test/detect-async-leaks.test.ts | 40 +++++++++++++----------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/test/e2e/test/detect-async-leaks.test.ts b/test/e2e/test/detect-async-leaks.test.ts index 09b25ee27cae..c36fa2869002 100644 --- a/test/e2e/test/detect-async-leaks.test.ts +++ b/test/e2e/test/detect-async-leaks.test.ts @@ -212,35 +212,39 @@ test('fetch', async () => { `) }) -test('fs handle', async () => { +test('fs watcher', async () => { const { stderr } = await runInlineTests({ 'packages/example/test/example.test.ts': ` - import { readFile } from 'node:fs' + import { watch } from 'node:fs' - test('leaking fs handle', () => { - readFile(import.meta.filename, () => {}); + test('leaking fs watcher', () => { + watch(import.meta.filename, () => {}); }) `, 'packages/example/test/example-2.test.ts': ` - import { readFile } from 'node:fs' + import { watch } from 'node:fs' - test('not a leak', async () => { - await new Promise(resolve => readFile(import.meta.filename, () => { resolve() })); + test('not a leak', () => { + watch(import.meta.filename, () => {}).close(); }) `, }) - // This might be racy. Sometimes readFile fires two FSREQCALLBACK's, sometimes just one. - expect(stderr).toContain(`\ -FSREQCALLBACK leaking in packages/example/test/example.test.ts - 3| - 4| test('leaking fs handle', () => { - 5| readFile(import.meta.filename, () => {}); - | ^ - 6| }) - 7| - ❯ packages/example/test/example.test.ts:5:9 -`) + expect(stderr).toMatchInlineSnapshot(` + " + ⎯⎯⎯⎯⎯⎯⎯ Async Leaks 1 ⎯⎯⎯⎯⎯⎯⎯⎯ + + FSEVENTWRAP leaking in packages/example/test/example.test.ts + 3| + 4| test('leaking fs watcher', () => { + 5| watch(import.meta.filename, () => {}); + | ^ + 6| }) + 7| + ❯ packages/example/test/example.test.ts:5:9 + + " + `) }) test('http server', async () => {