Skip to content

Commit 16df30d

Browse files
committed
🌿 Use sandbox for git working directory tests
1 parent 9b144b2 commit 16df30d

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
],
66
"tasks": {
77
"check": "deno check ./**/*.ts",
8-
"test": "deno test -A --parallel --shuffle --doc",
8+
"test": "deno test -A --shuffle --doc",
99
"test:coverage": "deno task test --coverage=.coverage",
1010
"coverage": "deno coverage .coverage",
1111
"update": "deno run --allow-env --allow-read --allow-write --allow-run=git,deno --allow-net=jsr.io,registry.npmjs.org jsr:@molt/cli **/*.ts",

denops/gin/git/finder_test.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { assertEquals, assertRejects } from "jsr:@std/assert@^1.0.0";
2-
import * as path from "jsr:@std/path@^1.0.0";
2+
import { sandbox } from "jsr:@lambdalisue/sandbox@^2.0.0";
3+
import $ from "jsr:@david/dax@^0.42.0";
4+
import { join } from "jsr:@std/path@^1.0.0";
35
import { findWorktree } from "./finder.ts";
46
import { ExecuteError } from "./process.ts";
57

68
Deno.test({
7-
name: "find() returns a root path of a git working directory",
9+
name: "findWorktree() returns a root path of a git working directory",
810
fn: async () => {
9-
const exp = path.resolve(
10-
path.fromFileUrl(import.meta.url),
11-
"../../../../",
12-
);
13-
assertEquals(await findWorktree("."), exp);
11+
await using sbox = await prepare();
12+
Deno.chdir(join("a", "b", "c"));
13+
assertEquals(await findWorktree("."), sbox.path);
1414
// An internal cache will be used for the following call
15-
assertEquals(await findWorktree("."), exp);
15+
assertEquals(await findWorktree("."), sbox.path);
1616
},
1717
sanitizeResources: false,
1818
sanitizeOps: false,
1919
});
2020

2121
Deno.test({
22-
name: "find() throws an error if the path is not in a git working directory",
22+
name:
23+
"findWorktree() throws an error if the path is not in a git working directory",
2324
fn: async () => {
2425
await assertRejects(async () => {
2526
await findWorktree("/");
@@ -32,3 +33,12 @@ Deno.test({
3233
sanitizeResources: false,
3334
sanitizeOps: false,
3435
});
36+
37+
async function prepare(): ReturnType<typeof sandbox> {
38+
const sbox = await sandbox();
39+
await $`git init`;
40+
await $`git commit --allow-empty -m 'Initial commit' --no-gpg-sign`;
41+
await $`git switch -c main`;
42+
await Deno.mkdir(join("a", "b", "c"), { recursive: true });
43+
return sbox;
44+
}

0 commit comments

Comments
 (0)