@@ -12,6 +12,10 @@ jest.mock('../tsDocGen')
1212// suppress console logs so that it doesn't clutter the test output
1313jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } )
1414
15+ beforeEach ( ( ) => {
16+ jest . clearAllMocks ( )
17+ } )
18+
1519const validConfigResponse = {
1620 propsGlobs : [
1721 {
@@ -90,8 +94,12 @@ it('should call getConfig with the passed config file location', async () => {
9094it ( 'should not proceed if config is not found' , async ( ) => {
9195 ; ( getConfig as jest . Mock ) . mockResolvedValue ( undefined )
9296
97+ const mockConsoleError = jest . fn ( )
98+ jest . spyOn ( console , 'error' ) . mockImplementation ( mockConsoleError )
99+
93100 await buildPropsData ( '/root/' , '/config' , false )
94101
102+ expect ( mockConsoleError ) . toHaveBeenCalledWith ( 'No config found, please run the `setup` command or manually create a pf-docs.config.mjs file' )
95103 expect ( writeFile ) . not . toHaveBeenCalled ( )
96104} )
97105
@@ -117,11 +125,12 @@ it('should call glob with the propGlobs in the config file and the cwd set to th
117125 expect ( glob ) . toHaveBeenNthCalledWith (
118126 1 ,
119127 [ '**/include/files/*' , '**/include/other/files/*' ] ,
120- { cwd : '/root/' , ignore : [ '**/exclude/files/*' ] } ,
128+ { cwd : '/root/' , ignore : [ '**/exclude/files/*' ] , absolute : true } ,
121129 )
122130 expect ( glob ) . toHaveBeenNthCalledWith ( 2 , [ '**/one/more/include/*' ] , {
123131 cwd : '/root/' ,
124132 ignore : [ ] ,
133+ absolute : true ,
125134 } )
126135 expect ( glob ) . toHaveBeenCalledTimes ( 2 )
127136} )
@@ -163,3 +172,39 @@ it('should call writeFile with the returned prop data in JSON form', async () =>
163172 JSON . stringify ( propsData ) ,
164173 )
165174} )
175+
176+ it ( 'should log verbose messages when run in verbose mode' , async ( ) => {
177+ ; ( getConfig as jest . Mock ) . mockResolvedValue ( validConfigResponse )
178+ ; ( glob as unknown as jest . Mock ) . mockResolvedValueOnce ( [ 'files/one' ] )
179+ ; ( glob as unknown as jest . Mock ) . mockResolvedValueOnce ( [ 'files/two' ] )
180+ ; ( tsDocgen as jest . Mock ) . mockResolvedValueOnce ( validTsDocGenResponseOne )
181+ ; ( tsDocgen as jest . Mock ) . mockResolvedValueOnce ( validTsDocGenResponseTwo )
182+
183+ const mockConsoleLog = jest . fn ( )
184+ jest . spyOn ( console , 'log' ) . mockImplementation ( mockConsoleLog )
185+
186+ await buildPropsData ( '/root/' , '/config' , true )
187+
188+ // Check verbose logging messages
189+ expect ( mockConsoleLog ) . toHaveBeenCalledWith ( 'Beginning props data build' )
190+ expect ( mockConsoleLog ) . toHaveBeenCalledWith ( 'Found 2 files to parse' )
191+ expect ( mockConsoleLog ) . toHaveBeenCalledWith ( 'Parsing props from files/one' )
192+ expect ( mockConsoleLog ) . toHaveBeenCalledWith ( 'Parsing props from files/two' )
193+ expect ( mockConsoleLog ) . toHaveBeenCalledWith ( `Writing props data to ${ process . cwd ( ) } /output/dir/props.json` )
194+ } )
195+
196+ it ( 'should not log verbose messages when not run in verbose mode' , async ( ) => {
197+ ; ( getConfig as jest . Mock ) . mockResolvedValue ( validConfigResponse )
198+ ; ( glob as unknown as jest . Mock ) . mockResolvedValueOnce ( [ 'files/one' ] )
199+ ; ( glob as unknown as jest . Mock ) . mockResolvedValueOnce ( [ 'files/two' ] )
200+ ; ( tsDocgen as jest . Mock ) . mockResolvedValueOnce ( validTsDocGenResponseOne )
201+ ; ( tsDocgen as jest . Mock ) . mockResolvedValueOnce ( validTsDocGenResponseTwo )
202+
203+ const mockConsoleLog = jest . fn ( )
204+ jest . spyOn ( console , 'log' ) . mockImplementation ( mockConsoleLog )
205+
206+ await buildPropsData ( '/root/' , '/config' , false )
207+
208+ // Should not have any verbose logging calls
209+ expect ( mockConsoleLog ) . not . toHaveBeenCalled ( )
210+ } )
0 commit comments