Skip to content

Commit

Permalink
Add tests for sandboxSync()
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Sep 23, 2024
1 parent 238d370 commit 3f98d88
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion sandbox_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 3f98d88

Please sign in to comment.