From 3659608abe66efcfae1ba39528ec51af7503e00b Mon Sep 17 00:00:00 2001 From: Thom Lamb Date: Fri, 4 Sep 2026 13:40:18 -0500 Subject: [PATCH] test(images): release the sharp handle before teardown (#301) libvips caches input file mappings in memory after a pipeline finishes. On Windows, this keeps an open handle on the input file, and the OS refuses to delete a file with an open handle. The animated-WebP test triggers a pipeline rejection (correctly refusing a multi-page rotation), so the mapping stays in cache and afterEach cannot remove the test directory. Disabling the cache costs these tests nothing: each file is read exactly once during its test, so there is no reuse to cache. With caching disabled, Windows can delete the input files and afterEach succeeds. Co-Authored-By: Claude Opus 5 --- backend/tests/unit/imageRotation.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/tests/unit/imageRotation.test.ts b/backend/tests/unit/imageRotation.test.ts index a42c0ce..5c35a33 100644 --- a/backend/tests/unit/imageRotation.test.ts +++ b/backend/tests/unit/imageRotation.test.ts @@ -4,6 +4,13 @@ import path from 'path'; import sharp from 'sharp'; import { rotateInPlace } from '../../src/imageProcessing'; +// libvips keeps an input file mapped in its operation cache after a pipeline +// finishes, and Windows will not delete a file that still has an open handle — +// so the animated-WebP case, which is the one that ends in a rejection, left +// afterEach unable to remove its own temporary directory. Disabling the cache +// costs these six tests nothing: every one of them reads its file exactly once. +sharp.cache(false); + let dir = ''; beforeEach(async () => {