From 3f98d880dd73a391584ecbd2fe835edc6f3e5ffc Mon Sep 17 00:00:00 2001 From: Alisue Date: Mon, 23 Sep 2024 20:46:54 +0900 Subject: [PATCH] Add tests for `sandboxSync()` --- sandbox_test.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/sandbox_test.ts b/sandbox_test.ts index b54971c..0f3e31e 100644 --- a/sandbox_test.ts +++ b/sandbox_test.ts @@ -5,7 +5,7 @@ import { assertRejects, } from "@std/assert"; import { existsSync } from "@std/fs/exists"; -import { sandbox } from "./sandbox.ts"; +import { sandbox, sandboxSync } from "./sandbox.ts"; function assertExists(path: string) { assert(existsSync(path), `${path} must exist`); @@ -42,6 +42,33 @@ Deno.test({ }, }); +Deno.test({ + name: + "sandboxSync() creates a sandbox directory and that directory is removed when disposed", + fn: () => { + using sbox = sandboxSync(); + assertExists(sbox.path); + + sbox[Symbol.dispose](); + assertNotExists(sbox.path); + }, +}); + +Deno.test({ + name: + "sandboxSync() changes the current working directory to the sandbox directory and back when disposed", + fn: () => { + const cwd = () => Deno.realPathSync(Deno.cwd()); + using sbox = sandboxSync(); + assertEquals(cwd(), sbox.path); + assertNotEquals(cwd(), sbox.origin); + + sbox[Symbol.dispose](); + assertNotEquals(cwd(), sbox.path); + assertEquals(cwd(), sbox.origin); + }, +}); + Deno.test({ name: "Deno.create() performs its operation in a sandbox directory", fn: async () => {