mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-05-16 12:31:16 +00:00
feat(tests): add Deno-based tests for checking CLI functionality in the same-codebase between platforms.
This commit is contained in:
33
src/apps/cli/testdeno/helpers/temp.ts
Normal file
33
src/apps/cli/testdeno/helpers/temp.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { join } from "@std/path";
|
||||
|
||||
/**
|
||||
* A temporary directory that cleans itself up via `await using`.
|
||||
* Requires TypeScript 5.2+ / Deno 1.40+ for the AsyncDisposable protocol.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* await using tmp = await TempDir.create();
|
||||
* const file = tmp.join("data.json");
|
||||
* ```
|
||||
*/
|
||||
export class TempDir implements AsyncDisposable {
|
||||
readonly path: string;
|
||||
|
||||
private constructor(path: string) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
static async create(prefix = "livesync-deno-test"): Promise<TempDir> {
|
||||
const path = await Deno.makeTempDir({ prefix: `${prefix}.` });
|
||||
return new TempDir(path);
|
||||
}
|
||||
|
||||
/** Return an OS path joined to the temp directory root. */
|
||||
join(...parts: string[]): string {
|
||||
return join(this.path, ...parts);
|
||||
}
|
||||
|
||||
async [Symbol.asyncDispose](): Promise<void> {
|
||||
await Deno.remove(this.path, { recursive: true }).catch(() => {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user