1- import { describe , it , expect , jest , afterEach , beforeAll , beforeEach } from '@jest/globals' ;
1+ import { describe , it , expect , jest , afterEach , beforeEach } from '@jest/globals' ;
22import fs from 'fs' ;
33import path from 'path' ;
44import { updateLockFile } from '../../bump/updateLockFile' ;
55import { packageManager , type PackageManagerResult } from '../../packageManager/packageManager' ;
6+ import { initMockLogs } from '../../__fixtures__/mockLogs' ;
67
78jest . mock ( 'fs' ) ;
89jest . mock ( '../../packageManager/packageManager' ) ;
@@ -15,16 +16,10 @@ jest.mock('../../env', () => ({
1516} ) ) ;
1617
1718describe ( 'updateLockFile' , ( ) => {
19+ const logs = initMockLogs ( { alsoLog : [ 'error' ] } ) ;
1820 const mockRoot = path . resolve ( '/mock/root' ) ;
1921 const mockFs = fs as jest . Mocked < typeof fs > ;
2022 const mockPackageManager = packageManager as jest . MockedFunction < typeof packageManager > ;
21- let consoleLogSpy : jest . SpiedFunction < typeof console . log > ;
22- let consoleWarnSpy : jest . SpiedFunction < typeof console . warn > ;
23-
24- beforeAll ( ( ) => {
25- consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => undefined ) ;
26- consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => undefined ) ;
27- } ) ;
2823
2924 beforeEach ( ( ) => {
3025 mockPackageManager . mockResolvedValue ( { success : true } as PackageManagerResult ) ;
@@ -40,7 +35,7 @@ describe('updateLockFile', () => {
4035
4136 await updateLockFile ( { path : mockRoot } ) ;
4237
43- expect ( consoleLogSpy ) . toHaveBeenCalledWith ( 'Updating package-lock.json after bumping packages' ) ;
38+ expect ( logs . mocks . log ) . toHaveBeenCalledWith ( 'Updating package-lock.json after bumping packages' ) ;
4439 expect ( mockPackageManager ) . toHaveBeenCalledWith ( 'npm' , [ 'install' , '--package-lock-only' , '--ignore-scripts' ] , {
4540 stdio : 'inherit' ,
4641 cwd : mockRoot ,
@@ -52,7 +47,7 @@ describe('updateLockFile', () => {
5247
5348 await updateLockFile ( { path : mockRoot } ) ;
5449
55- expect ( consoleLogSpy ) . toHaveBeenCalledWith ( 'Updating pnpm-lock.yaml after bumping packages' ) ;
50+ expect ( logs . mocks . log ) . toHaveBeenCalledWith ( 'Updating pnpm-lock.yaml after bumping packages' ) ;
5651 expect ( mockPackageManager ) . toHaveBeenCalledWith ( 'pnpm' , [ 'install' , '--lockfile-only' , '--ignore-scripts' ] , {
5752 stdio : 'inherit' ,
5853 cwd : mockRoot ,
@@ -72,7 +67,7 @@ describe('updateLockFile', () => {
7267 stdio : 'inherit' ,
7368 cwd : mockRoot ,
7469 } ) ;
75- expect ( consoleLogSpy ) . toHaveBeenCalledWith ( 'Updating yarn.lock after bumping packages' ) ;
70+ expect ( logs . mocks . log ) . toHaveBeenCalledWith ( 'Updating yarn.lock after bumping packages' ) ;
7671 } ) ;
7772
7873 it ( 'skips yarn.lock update for yarn v1' , async ( ) => {
@@ -83,8 +78,8 @@ describe('updateLockFile', () => {
8378
8479 expect ( mockPackageManager ) . toHaveBeenCalledWith ( 'yarn' , [ '--version' ] , { cwd : mockRoot } ) ;
8580 expect ( mockPackageManager ) . toHaveBeenCalledTimes ( 1 ) ;
86- expect ( consoleLogSpy ) . not . toHaveBeenCalled ( ) ;
87- expect ( consoleWarnSpy ) . not . toHaveBeenCalled ( ) ;
81+ expect ( logs . mocks . log ) . not . toHaveBeenCalled ( ) ;
82+ expect ( logs . mocks . warn ) . not . toHaveBeenCalled ( ) ;
8883 } ) ;
8984
9085 it ( 'warns when yarn version check fails' , async ( ) => {
@@ -93,7 +88,7 @@ describe('updateLockFile', () => {
9388
9489 await updateLockFile ( { path : mockRoot } ) ;
9590
96- expect ( consoleWarnSpy ) . toHaveBeenCalledWith ( 'Failed to get yarn version. Continuing...' ) ;
91+ expect ( logs . mocks . warn ) . toHaveBeenCalledWith ( 'Failed to get yarn version. Continuing...' ) ;
9792 } ) ;
9893
9994 it ( 'warns when lock file update fails' , async ( ) => {
@@ -102,7 +97,7 @@ describe('updateLockFile', () => {
10297
10398 await updateLockFile ( { path : mockRoot } ) ;
10499
105- expect ( consoleWarnSpy ) . toHaveBeenCalledWith ( 'Updating package-lock.json failed. Continuing...' ) ;
100+ expect ( logs . mocks . warn ) . toHaveBeenCalledWith ( 'Updating package-lock.json failed. Continuing...' ) ;
106101 } ) ;
107102
108103 it ( 'does nothing when no lock file exists' , async ( ) => {
@@ -111,6 +106,6 @@ describe('updateLockFile', () => {
111106 await updateLockFile ( { path : mockRoot } ) ;
112107
113108 expect ( mockPackageManager ) . not . toHaveBeenCalled ( ) ;
114- expect ( consoleLogSpy ) . not . toHaveBeenCalled ( ) ;
109+ expect ( logs . mocks . log ) . not . toHaveBeenCalled ( ) ;
115110 } ) ;
116111} ) ;
0 commit comments