@@ -11,7 +11,7 @@ import {
1111 initEnvironment
1212} from '../../shared/core'
1313import { shouldSkipDuringMerge , stageFiles } from '../../shared/git'
14- import { fs , which , $ } from 'zx'
14+ import { fs , which , $ , path } from 'zx'
1515
1616// Mock dependencies
1717vi . mock ( '../../shared/core' , ( ) => ( {
@@ -52,6 +52,9 @@ vi.mock('zx', () => ({
5252 which : vi . fn ( ) ,
5353 $ : {
5454 verbose : false
55+ } ,
56+ path : {
57+ match : vi . fn ( )
5558 }
5659} ) )
5760
@@ -382,6 +385,58 @@ describe('workflow.ts', () => {
382385
383386 expect ( exec ) . toHaveBeenCalledTimes ( 2 )
384387 } )
388+
389+ it ( 'should filter files based on includePatterns (regex)' , async ( ) => {
390+ vi . mocked ( isSkipped ) . mockReturnValue ( false )
391+ vi . mocked ( fs . pathExists ) . mockResolvedValue ( true )
392+ vi . mocked ( exec ) . mockResolvedValue ( { } as any )
393+
394+ const regexTool : ToolConfig = {
395+ ...mockTool ,
396+ type : 'node' ,
397+ command : 'check' ,
398+ extensions : [ '.json' ] , // Add extension to match file extension check first
399+ includePatterns : [ / s r c \/ l o c a l e s \/ .* \. j s o n $ / ]
400+ }
401+
402+ const files = [ 'apps/app1/src/locales/en.json' , 'other/file.json' ]
403+ await runQualityChecks ( files , [ regexTool ] )
404+
405+ // Should run only for matched file
406+ expect ( exec ) . toHaveBeenCalledTimes ( 1 )
407+ const callArgs = vi . mocked ( exec ) . mock . calls [ 0 ] [ 0 ]
408+ expect ( callArgs ) . toContain ( 'apps/app1/src/locales/en.json' )
409+ expect ( callArgs ) . not . toContain ( 'other/file.json' )
410+ } )
411+
412+ it ( 'should filter files based on includePatterns (glob)' , async ( ) => {
413+ vi . mocked ( isSkipped ) . mockReturnValue ( false )
414+ vi . mocked ( fs . pathExists ) . mockResolvedValue ( true )
415+ vi . mocked ( exec ) . mockResolvedValue ( { } as any )
416+
417+ // Mock path.match behavior
418+ // @ts -ignore
419+ vi . mocked ( path . match ) . mockImplementation ( ( pattern , file ) => {
420+ // Simple mock: check if file ends with .json and path contains /locales/
421+ return file . endsWith ( '.json' ) && file . includes ( '/locales/' )
422+ } )
423+
424+ const globTool : ToolConfig = {
425+ ...mockTool ,
426+ type : 'node' ,
427+ command : 'check' ,
428+ extensions : [ '.json' ] , // Add extension to match file extension check first
429+ includePatterns : [ 'apps/*/src/locales/*.json' ]
430+ }
431+
432+ const files = [ 'apps/app1/src/locales/en.json' , 'other/file.json' ]
433+ await runQualityChecks ( files , [ globTool ] )
434+
435+ expect ( exec ) . toHaveBeenCalledTimes ( 1 )
436+ const callArgs = vi . mocked ( exec ) . mock . calls [ 0 ] [ 0 ]
437+ expect ( callArgs ) . toContain ( 'apps/app1/src/locales/en.json' )
438+ expect ( callArgs ) . not . toContain ( 'other/file.json' )
439+ } )
385440 } )
386441
387442 describe ( 'runHook' , ( ) => {
0 commit comments