refactor: Use fs-extra instead of fs to simplify file access

* refactor: use fs-extra instead of fs

* tests: manual mocks for fs-extra base + ensureDir

* refactor: mockFileSystem + mockFs and mockFsExtra

* add remove mock and some further test tweaks

* test: FileDataAccessor tests passing

* refactor: remove try-catch due to fs-extra handlin

* refactor: fs-extra in atomicFileDataAccessor

* refactor: AtomicFileDataAccessor fs-extra

* test: fix coverage

* refactor: use read/writeJson from fs-extra

* refactor: less duplicate mocking code

* refactor: re-use opendir mocking code
This commit is contained in:
Jasper Vaneessen
2022-04-12 11:02:30 +02:00
committed by GitHub
parent dd568869ca
commit fe39f97ee0
12 changed files with 139 additions and 86 deletions

View File

@@ -1,9 +1,10 @@
import type { ResourceIdentifier } from '../../../../src/http/representation/ResourceIdentifier';
import { JsonFileStorage } from '../../../../src/storage/keyvalue/JsonFileStorage';
import type { ReadWriteLocker } from '../../../../src/util/locking/ReadWriteLocker';
import { mockFs } from '../../../util/Util';
import { mockFileSystem } from '../../../util/Util';
jest.mock('fs');
jest.mock('fs-extra');
describe('A JsonFileStorage', (): void => {
const rootFilePath = 'files/';
@@ -13,7 +14,7 @@ describe('A JsonFileStorage', (): void => {
let storage: JsonFileStorage;
beforeEach(async(): Promise<void> => {
cache = mockFs(rootFilePath);
cache = mockFileSystem(rootFilePath);
locker = {
withReadLock:
jest.fn(async(identifier: ResourceIdentifier, whileLocked: () => any): Promise<any> => await whileLocked()),