1- import { logger , rosStackDelete , rosStackDeploy } from '../../src/common' ;
1+ import { rosStackDelete , rosStackDeploy } from '../../src/common' ;
22import { context } from '../fixtures/contextFixture' ;
33import { lang } from '../../src/lang' ;
44
@@ -8,6 +8,9 @@ const mockedUpdateStack = jest.fn();
88const mockedListStacks = jest . fn ( ) ;
99const mockedGetStack = jest . fn ( ) ;
1010const mockedDeleteStack = jest . fn ( ) ;
11+ const mockedLoggerInfo = jest . fn ( ) ;
12+ const mockedLoggerWarn = jest . fn ( ) ;
13+ const mockedLoggerError = jest . fn ( ) ;
1114
1215jest . mock ( 'node:async_hooks' , ( ) => ( {
1316 AsyncLocalStorage : jest . fn ( ) . mockImplementation ( ( ) => ( {
@@ -28,7 +31,13 @@ jest.mock('@alicloud/ros20190910', () => ({
2831 } ) ) ,
2932} ) ) ;
3033
31- jest . mock ( '../../src/common/logger' ) ;
34+ jest . mock ( '../../src/common/logger' , ( ) => ( {
35+ logger : {
36+ info : ( ...args : unknown [ ] ) => mockedLoggerInfo ( ...args ) ,
37+ warn : ( ...args : unknown [ ] ) => mockedLoggerWarn ( ...args ) ,
38+ error : ( ...args : unknown [ ] ) => mockedLoggerError ( ...args ) ,
39+ } ,
40+ } ) ) ;
3241
3342describe ( 'Unit test for rosClient' , ( ) => {
3443 beforeEach ( ( ) => {
@@ -46,7 +55,7 @@ describe('Unit test for rosClient', () => {
4655 await rosStackDeploy ( stackName , { } ) ;
4756
4857 expect ( mockedCreateStack ) . toHaveBeenCalled ( ) ;
49- expect ( logger . info ) . toHaveBeenCalledWith ( expect . stringContaining ( 'createStack success' ) ) ;
58+ expect ( mockedLoggerInfo ) . toHaveBeenCalledWith ( expect . stringContaining ( 'createStack success' ) ) ;
5059 } ) ;
5160
5261 it ( 'should update an existing stack if it exists' , async ( ) => {
@@ -62,7 +71,7 @@ describe('Unit test for rosClient', () => {
6271 await rosStackDeploy ( stackName , { } ) ;
6372
6473 expect ( mockedUpdateStack ) . toHaveBeenCalled ( ) ;
65- expect ( logger . info ) . toHaveBeenCalledWith ( expect . stringContaining ( 'stackUpdate success' ) ) ;
74+ expect ( mockedLoggerInfo ) . toHaveBeenCalledWith ( expect . stringContaining ( 'stackUpdate success' ) ) ;
6675 } ) ;
6776
6877 it ( 'should throw an error if the stack is in progress' , async ( ) => {
@@ -93,7 +102,7 @@ describe('Unit test for rosClient', () => {
93102
94103 await rosStackDeploy ( stackName , { } ) ;
95104
96- expect ( logger . warn ) . toHaveBeenCalledWith ( `${ lang . __ ( 'UPDATE_COMPLETELY_SAME_STACK' ) } ` ) ;
105+ expect ( mockedLoggerWarn ) . toHaveBeenCalledWith ( `${ lang . __ ( 'UPDATE_COMPLETELY_SAME_STACK' ) } ` ) ;
97106 } ) ;
98107
99108 it ( 'should throw error when deploy stack failed' , async ( ) => {
@@ -121,15 +130,15 @@ describe('Unit test for rosClient', () => {
121130
122131 await rosStackDelete ( context ) ;
123132
124- expect ( logger . info ) . toHaveBeenCalledWith ( 'stack status: DELETE_COMPLETE' ) ;
125- expect ( logger . info ) . toHaveBeenCalledWith ( 'Stack: testStack deleted!🗑 ' ) ;
133+ expect ( mockedLoggerInfo ) . toHaveBeenCalledWith ( 'stack status: DELETE_COMPLETE' ) ;
134+ expect ( mockedLoggerInfo ) . toHaveBeenCalledWith ( 'Stack: testStack deleted!🗑 ' ) ;
126135 } ) ;
127136
128137 it ( 'should throw an error when the stack does not exist' , async ( ) => {
129138 mockedListStacks . mockResolvedValue ( { statusCode : 404 , body : { stacks : [ ] } } ) ;
130139 await rosStackDelete ( context ) ;
131140
132- expect ( logger . warn ) . toHaveBeenCalledWith ( 'Stack: testStack not exists, skipped! 🚫' ) ;
141+ expect ( mockedLoggerWarn ) . toHaveBeenCalledWith ( 'Stack: testStack not exists, skipped! 🚫' ) ;
133142 } ) ;
134143
135144 it ( 'should throw error when delete stack failed' , async ( ) => {
@@ -142,7 +151,7 @@ describe('Unit test for rosClient', () => {
142151 await expect ( rosStackDelete ( context ) ) . rejects . toThrow (
143152 JSON . stringify ( { statusCode : 400 , Message : 'DELETE_FAILED' } ) ,
144153 ) ;
145- expect ( logger . error ) . toHaveBeenCalledWith (
154+ expect ( mockedLoggerError ) . toHaveBeenCalledWith (
146155 expect . stringContaining ( 'Stack: testStack delete failed! ❌' ) ,
147156 ) ;
148157 } ) ;
0 commit comments