1
1
import * as assert from "assert/strict" ;
2
2
import * as fs from "fs" ;
3
3
import * as path from "node:path" ;
4
- import { runInTempDir } from "./test_utils" ;
4
+ import { runInTempDir , writeJson } from "./test_utils" ;
5
5
import { findProjectDir } from "../src/utils" ;
6
6
7
7
describe ( "findProjectDir" , ( ) => {
@@ -16,13 +16,15 @@ describe("findProjectDir", () => {
16
16
assert . strictEqual ( result . pkgManagerName , "npm" ) ;
17
17
} ) ;
18
18
} ) ;
19
+
19
20
it ( "should return yarn if yarn.lock is found" , async ( ) => {
20
21
await runInTempDir ( async ( tempDir ) => {
21
22
await fs . promises . writeFile ( path . join ( tempDir , "yarn.lock" ) , "" , "utf-8" ) ;
22
23
const result = await findProjectDir ( tempDir ) ;
23
24
assert . strictEqual ( result . pkgManagerName , "yarn" ) ;
24
25
} ) ;
25
26
} ) ;
27
+
26
28
it ( "should return pnpm if pnpm-lock.yaml is found" , async ( ) => {
27
29
await runInTempDir ( async ( tempDir ) => {
28
30
await fs . promises . writeFile (
@@ -34,13 +36,15 @@ describe("findProjectDir", () => {
34
36
assert . strictEqual ( result . pkgManagerName , "pnpm" ) ;
35
37
} ) ;
36
38
} ) ;
39
+
37
40
it ( "should return bun if bun.lockb is found" , async ( ) => {
38
41
await runInTempDir ( async ( tempDir ) => {
39
42
await fs . promises . writeFile ( path . join ( tempDir , "bun.lockb" ) , "" , "utf-8" ) ;
40
43
const result = await findProjectDir ( tempDir ) ;
41
44
assert . strictEqual ( result . pkgManagerName , "bun" ) ;
42
45
} ) ;
43
46
} ) ;
47
+
44
48
it ( "should return bun if bun.lockb and yarn.lock are found" , async ( ) => {
45
49
// bun allow to save bun.lockb and yarn.lock
46
50
// https://bun.sh/docs/install/lockfile
@@ -51,4 +55,16 @@ describe("findProjectDir", () => {
51
55
assert . strictEqual ( result . pkgManagerName , "bun" ) ;
52
56
} ) ;
53
57
} ) ;
58
+
59
+ it ( "should set project dir to nearest package.json" , async ( ) => {
60
+ await runInTempDir ( async ( tempDir ) => {
61
+ const sub = path . join ( tempDir , "sub" ) ;
62
+ await fs . promises . mkdir ( sub ) ;
63
+
64
+ await writeJson ( path . join ( tempDir , "package.json" ) , { } ) ;
65
+ await writeJson ( path . join ( sub , "package.json" ) , { } ) ;
66
+ const result = await findProjectDir ( sub ) ;
67
+ assert . strictEqual ( result . projectDir , sub ) ;
68
+ } ) ;
69
+ } ) ;
54
70
} ) ;
0 commit comments