Skip to content

Commit ba631d2

Browse files
committed
test: use fs/promise API
1 parent 9900cee commit ba631d2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

test/downloader.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,42 +228,42 @@ describe('`download`', () => {
228228
const image = await download(expectedImage);
229229
try {
230230
expect(image).toMatchObject(expectedImage);
231-
expect(() => fs.accessSync(image.path)).not.toThrow();
231+
await expect(fs.promises.access(image.path)).resolves.not.toThrow();
232232
} finally {
233-
fs.rmSync(image.path, { force: true });
233+
await fs.promises.rm(image.path, { force: true });
234234
}
235235
});
236236

237237
it('should throw an error if directory cannot be created', async () => {
238238
const directory = '/restricted-dir';
239239
const image = parseImageParams(`${BASE_URL}/image.jpg`, { directory });
240-
await expect(() => download(image)).rejects.toThrow(DirectoryError);
240+
await expect(download(image)).rejects.toThrow(DirectoryError);
241241
});
242242

243243
it.each(['tmp', 'tmp/images'])(
244244
'should create the directory if it does not exist: `%s`',
245245
async (directory) => {
246246
// Prepare: ensure the directory does not exist
247-
fs.rmSync(directory, { recursive: true, force: true });
247+
await fs.promises.rm(directory, { recursive: true, force: true });
248248

249249
const image = parseImageParams(`${BASE_URL}/image.jpg`, { directory });
250250
const { path: actualPath } = await download(image);
251251

252252
try {
253253
// Check if the directory was created
254-
expect(fs.existsSync(directory)).toBe(true);
254+
await expect(fs.promises.access(directory)).resolves.not.toThrow();
255255
// Check if the file was created
256-
expect(() => fs.accessSync(actualPath)).not.toThrow();
256+
await expect(fs.promises.access(actualPath)).resolves.not.toThrow();
257257
} finally {
258-
fs.rmSync(directory, { recursive: true, force: true });
258+
await fs.promises.rm(directory, { recursive: true, force: true });
259259
}
260260
},
261261
);
262262

263263
it('should throw an error if the response is not an image', async () => {
264264
await expect(
265265
// `GET /` will return a 200 OK response with `OK` body
266-
() => download(parseImageParams(BASE_URL)),
266+
download(parseImageParams(BASE_URL)),
267267
).rejects.toThrow(RequestError);
268268
});
269269

@@ -272,7 +272,7 @@ describe('`download`', () => {
272272

273273
await expect(
274274
// `GET /unknown` will return a 404 Not Found response
275-
() => download(parseImageParams(url)),
275+
download(parseImageParams(url)),
276276
).rejects.toThrow(RequestError);
277277
});
278278

@@ -289,6 +289,6 @@ describe('`download`', () => {
289289
};
290290
});
291291

292-
await expect(() => download(image)).rejects.toThrow(Error);
292+
await expect(download(image)).rejects.toThrow(Error);
293293
});
294294
});

0 commit comments

Comments
 (0)