@@ -2,13 +2,21 @@ import { randomUUID } from "crypto";
22import { pathExists } from "./fileSystem" ;
33import { getUserPackageManager } from "./getUserPkgManager" ;
44import * as pathModule from "path" ;
5+ import { Mock } from "vitest" ;
56
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+ } ;
911
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 ) ,
1220} ) ) ;
1321
1422describe ( getUserPackageManager . name , ( ) => {
@@ -18,7 +26,13 @@ describe(getUserPackageManager.name, () => {
1826 path = randomUUID ( ) ;
1927 } ) ;
2028
21- afterEach ( jest . clearAllMocks ) ;
29+ afterEach ( ( ) => {
30+ vi . clearAllMocks ( ) ;
31+ } ) ;
32+
33+ afterAll ( ( ) => {
34+ vi . restoreAllMocks ( ) ;
35+ } )
2236
2337 describe ( `should use ${ pathExists . name } to check for package manager artifacts` , ( ) => {
2438 it ( 'should join the path with the artifact name' , async ( ) => {
@@ -32,41 +46,41 @@ describe(getUserPackageManager.name, () => {
3246 it ( `should call ${ pathExists . name } with the path.join result` , async ( ) => {
3347 const expected = randomUUID ( ) ;
3448
35- ( pathModule . join as jest . Mock ) . mockReturnValueOnce ( expected ) ;
49+ ( pathModule . join as Mock ) . mockReturnValueOnce ( expected ) ;
3650
3751 await getUserPackageManager ( path ) ;
3852
3953 expect ( pathExists ) . toBeCalledWith ( expected ) ;
4054 } ) ;
4155
4256 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' ) ) ;
4458
4559 expect ( await getUserPackageManager ( path ) ) . toBe ( 'yarn' ) ;
4660 } ) ;
4761
4862 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' ) ) ;
5064
5165 expect ( await getUserPackageManager ( path ) ) . toBe ( 'pnpm' ) ;
5266 } ) ;
5367
5468 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' ) ) ;
5670
5771 expect ( await getUserPackageManager ( path ) ) . toBe ( 'npm' ) ;
5872 } ) ;
5973
6074 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' ) ) ;
6276
6377 expect ( await getUserPackageManager ( path ) ) . toBe ( 'npm' ) ;
6478 } ) ;
6579 } ) ;
6680
6781 describe ( `if doesn't found artifacts, should use process.env.npm_config_user_agent to detect package manager` , ( ) => {
6882 beforeEach ( ( ) => {
69- ( pathExists as jest . Mock ) . mockResolvedValue ( false ) ;
83+ ( pathExists as Mock ) . mockResolvedValue ( false ) ;
7084 } )
7185
7286 it ( 'should return "yarn" if process.env.npm_config_user_agent starts with "yarn"' , async ( ) => {
0 commit comments