I had trouble testing my code that implement sharp
and memfs
. I has codes that download image and cropping it to certain dimension. I use sharp
to achieve the cropping. When it comes testing, I use jest
and memfs
. My test code has 2 parts:
- Download a image and save to mock volume/fileSystem that created with
memfs
. - Cropping the downloaded image to certain dimension with
sharp
.
Part 1 worked perfectly, was able to download image to the fake volume and asserted with jest
(exist in the fake volume).
But part 2 gave me error:[Error: Input file is missing]
.
const sizeToCrop = {
width: 378,
height: 538,
left: 422,
top: 0,
};
sharp(`./downloadedImage.jpg`)
.extract(sizeToCrop)
.toFile(`./CroppedImage.jpg`)
.then(() => {
console.log(`resolve!`);
})
.catch((err: Error) => {
console.log(err);
return Promise.reject();
});
// Error message: [Error: Input file is missing]
But when I test it with real volume. It worked fine.
Anyone has idea how to solve this?
Thank you.