1
1
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" ;
3
5
import { findWorktree } from "./finder.ts" ;
4
6
import { ExecuteError } from "./process.ts" ;
5
7
6
8
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" ,
8
10
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 ) ;
14
14
// An internal cache will be used for the following call
15
- assertEquals ( await findWorktree ( "." ) , exp ) ;
15
+ assertEquals ( await findWorktree ( "." ) , sbox . path ) ;
16
16
} ,
17
17
sanitizeResources : false ,
18
18
sanitizeOps : false ,
19
19
} ) ;
20
20
21
21
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" ,
23
24
fn : async ( ) => {
24
25
await assertRejects ( async ( ) => {
25
26
await findWorktree ( "/" ) ;
@@ -32,3 +33,12 @@ Deno.test({
32
33
sanitizeResources : false ,
33
34
sanitizeOps : false ,
34
35
} ) ;
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