backend-test-utils: add resolve and clear for DirectoryMocker + renames

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-09-21 10:55:14 +02:00
parent d96fb0642f
commit 4c5d3940cb
@@ -75,7 +75,7 @@ export class DirectoryMocker {
process.on('beforeExit', mocker.#cleanupSync);
try {
afterAll(mocker.removeContent);
afterAll(mocker.cleanup);
} catch {
/* ignore */
}
@@ -105,12 +105,16 @@ export class DirectoryMocker {
this.#root = root;
}
get dir() {
get path() {
return this.#root;
}
resolve(...paths: string[]) {
return resolvePath(this.#root, ...paths);
}
async setContent(root: MockDirectory) {
await this.removeContent();
await this.cleanup();
return this.addContent(root);
}
@@ -182,7 +186,11 @@ export class DirectoryMocker {
return read(root);
}
removeContent = async () => {
clear = async () => {
await this.setContent({});
};
cleanup = async () => {
await fs.rm(this.#root, { recursive: true, force: true });
};