From 79e347fc9be48d28ef94cc8837cafb1d94946128 Mon Sep 17 00:00:00 2001 From: SameRainbows Date: Tue, 10 Nov 2026 04:07:52 +0300 Subject: [PATCH] test: restore working directory before removing tempdir In test/helper.test.js, fs.promises.rm(testdir) was registered in t.after before process.chdir(cwd). Because node:test runs t.after callbacks in registration order, the directory removal was attempted while process.cwd() was still set to testdir. On Windows, attempting to remove the current working directory fails with EBUSY/EPERM, which caused the teardown to fail and left the process in testdir, breaking subsequent test cases that rely on repository-relative paths. Moving process.chdir(cwd) before the rm call ensures the working directory is restored first, allowing tempdir cleanup to succeed cleanly. Signed-off-by: SameRainbows --- test/helper.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/helper.test.js b/test/helper.test.js index fc2b91c5..d8d1a478 100644 --- a/test/helper.test.js +++ b/test/helper.test.js @@ -21,7 +21,11 @@ test('should return the fastify instance', async t => { test('should reload the env at each build', async t => { const testdir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'fastify-cli-')) + const cwd = process.cwd() + + process.chdir(testdir) t.after(async () => { + process.chdir(cwd) await fs.promises.rm(testdir, { recursive: true, force: true }) }) @@ -32,10 +36,6 @@ test('should reload the env at each build', async t => { ) const argv = [path.join(testdir, 'plugin.js')] - const cwd = process.cwd() - - process.chdir(testdir) - t.after(() => { process.chdir(cwd) }) { await writeFile(path.join(testdir, '.env'), 'GREETING=one')