mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00
Media E2E tests: Add error handling for upload cleanup
Previously, `fs.rmdir` was called multiple times on the same path, even when the path was already deleted. This causes test failures in Node 16. This commit extracts the cleanup code into a utility function and ensures that no error is thrown when the given path is already deleted. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
20f527eb80
commit
79065b8d3f
3 changed files with 31 additions and 6 deletions
|
@ -26,6 +26,7 @@ import { join } from 'path';
|
|||
import { PrivateApiModule } from '../../src/api/private/private-api.module';
|
||||
import { UsersService } from '../../src/users/users.service';
|
||||
import { ConsoleLoggerService } from '../../src/logger/console-logger.service';
|
||||
import { ensureDeleted } from '../utils';
|
||||
|
||||
describe('Media', () => {
|
||||
let app: NestExpressApplication;
|
||||
|
@ -95,7 +96,7 @@ describe('Media', () => {
|
|||
});
|
||||
describe('fails:', () => {
|
||||
beforeEach(async () => {
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
await ensureDeleted(uploadPath);
|
||||
});
|
||||
it('MIME type not supported', async () => {
|
||||
await request(app.getHttpServer())
|
||||
|
@ -125,14 +126,14 @@ describe('Media', () => {
|
|||
.expect(500);
|
||||
});
|
||||
afterEach(async () => {
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
await ensureDeleted(uploadPath);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
// Delete the upload folder
|
||||
await fs.rmdir(uploadPath, { recursive: true });
|
||||
await ensureDeleted(uploadPath);
|
||||
await app.close();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue