Skip to content

test: restore working directory before removing tempdir in helper.test - #931

Open
SameRainbows wants to merge 1 commit into
fastify:mainfrom
SameRainbows:fix/restore-cwd-before-tempdir-cleanup
Open

SameRainbows wants to merge 1 commit into
fastify:mainfrom
SameRainbows:fix/restore-cwd-before-tempdir-cleanup

Conversation

@SameRainbows

Copy link
Copy Markdown

Description

In test/helper.test.js, fs.promises.rm(testdir) was registered in t.after before process.chdir(cwd). Because node:test executes t.after hooks in registration order, directory removal was attempted while process.cwd() was still set to testdir.

On Windows, attempting to delete the active working directory fails with EBUSY. The rejection aborted teardown and left process.cwd() pointing at the temp folder, which caused subsequent tests in test/helper.test.js (such as setting plugin options) to fail when looking up ./examples/plugin-with-custom-options.js.

Moving process.chdir(cwd) ahead of fs.promises.rm(testdir) inside a single t.after block ensures the working directory is restored before the temp directory is removed.

Validation

  • node --test test/helper.test.js: all 10 tests pass cleanly on Windows (previously failed at test 2).
  • npm run lint: clean with 0 warnings or errors.

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 <avveralabs@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant