@@ -2,13 +2,21 @@ import { randomUUID } from "crypto";
2
2
import { pathExists } from "./fileSystem" ;
3
3
import { getUserPackageManager } from "./getUserPkgManager" ;
4
4
import * as pathModule from "path" ;
5
+ import { Mock } from "vitest" ;
5
6
6
- jest . mock ( 'path' , ( ) => ( {
7
- join : jest . fn ( ) . mockImplementation ( ( ...paths : string [ ] ) => paths . join ( '/' ) ) ,
8
- } ) )
7
+ vi . mock ( 'path' , ( ) => {
8
+ const path = {
9
+ join : vi . fn ( ) . mockImplementation ( ( ...paths : string [ ] ) => paths . join ( '/' ) ) ,
10
+ } ;
9
11
10
- jest . mock ( './fileSystem' , ( ) => ( {
11
- pathExists : jest . fn ( ) . mockResolvedValue ( false ) ,
12
+ return {
13
+ ...path ,
14
+ default : path ,
15
+ }
16
+ } )
17
+
18
+ vi . mock ( './fileSystem.ts' , ( ) => ( {
19
+ pathExists : vi . fn ( ) . mockResolvedValue ( false ) ,
12
20
} ) ) ;
13
21
14
22
describe ( getUserPackageManager . name , ( ) => {
@@ -18,7 +26,13 @@ describe(getUserPackageManager.name, () => {
18
26
path = randomUUID ( ) ;
19
27
} ) ;
20
28
21
- afterEach ( jest . clearAllMocks ) ;
29
+ afterEach ( ( ) => {
30
+ vi . clearAllMocks ( ) ;
31
+ } ) ;
32
+
33
+ afterAll ( ( ) => {
34
+ vi . restoreAllMocks ( ) ;
35
+ } )
22
36
23
37
describe ( `should use ${ pathExists . name } to check for package manager artifacts` , ( ) => {
24
38
it ( 'should join the path with the artifact name' , async ( ) => {
@@ -32,41 +46,41 @@ describe(getUserPackageManager.name, () => {
32
46
it ( `should call ${ pathExists . name } with the path.join result` , async ( ) => {
33
47
const expected = randomUUID ( ) ;
34
48
35
- ( pathModule . join as jest . Mock ) . mockReturnValueOnce ( expected ) ;
49
+ ( pathModule . join as Mock ) . mockReturnValueOnce ( expected ) ;
36
50
37
51
await getUserPackageManager ( path ) ;
38
52
39
53
expect ( pathExists ) . toBeCalledWith ( expected ) ;
40
54
} ) ;
41
55
42
56
it ( 'should return "yarn" if yarn.lock exists' , async ( ) => {
43
- ( pathExists as jest . Mock ) . mockImplementation ( ( path : string ) => path . endsWith ( 'yarn.lock' ) ) ;
57
+ ( pathExists as Mock ) . mockImplementation ( ( path : string ) => path . endsWith ( 'yarn.lock' ) ) ;
44
58
45
59
expect ( await getUserPackageManager ( path ) ) . toBe ( 'yarn' ) ;
46
60
} ) ;
47
61
48
62
it ( 'should return "pnpm" if pnpm-lock.yaml exists' , async ( ) => {
49
- ( pathExists as jest . Mock ) . mockImplementation ( async ( path : string ) => path . endsWith ( 'pnpm-lock.yaml' ) ) ;
63
+ ( pathExists as Mock ) . mockImplementation ( async ( path : string ) => path . endsWith ( 'pnpm-lock.yaml' ) ) ;
50
64
51
65
expect ( await getUserPackageManager ( path ) ) . toBe ( 'pnpm' ) ;
52
66
} ) ;
53
67
54
68
it ( 'should return "npm" if package-lock.json exists' , async ( ) => {
55
- ( pathExists as jest . Mock ) . mockImplementation ( ( path : string ) => path . endsWith ( 'package-lock.json' ) ) ;
69
+ ( pathExists as Mock ) . mockImplementation ( ( path : string ) => path . endsWith ( 'package-lock.json' ) ) ;
56
70
57
71
expect ( await getUserPackageManager ( path ) ) . toBe ( 'npm' ) ;
58
72
} ) ;
59
73
60
74
it ( 'should return "npm" if npm-shrinkwrap.json exists' , async ( ) => {
61
- ( pathExists as jest . Mock ) . mockImplementation ( ( path : string ) => path . endsWith ( 'npm-shrinkwrap.json' ) ) ;
75
+ ( pathExists as Mock ) . mockImplementation ( ( path : string ) => path . endsWith ( 'npm-shrinkwrap.json' ) ) ;
62
76
63
77
expect ( await getUserPackageManager ( path ) ) . toBe ( 'npm' ) ;
64
78
} ) ;
65
79
} ) ;
66
80
67
81
describe ( `if doesn't found artifacts, should use process.env.npm_config_user_agent to detect package manager` , ( ) => {
68
82
beforeEach ( ( ) => {
69
- ( pathExists as jest . Mock ) . mockResolvedValue ( false ) ;
83
+ ( pathExists as Mock ) . mockResolvedValue ( false ) ;
70
84
} )
71
85
72
86
it ( 'should return "yarn" if process.env.npm_config_user_agent starts with "yarn"' , async ( ) => {
0 commit comments