@@ -5,8 +5,12 @@ import process from 'node:process';
55import tmp from 'tmp' ;
66import { afterAll , beforeAll , describe , expect , test , vi } from 'vitest' ;
77
8+ function escapeRegex ( string : string ) : string {
9+ return string . replaceAll ( / [ / \- \\ ^ $ * + ? . ( ) | [ \] { } ] / g, String . raw `\$&` ) ;
10+ }
11+
812function regexOutput ( fieldName : string , value : string ) : RegExp {
9- return new RegExp ( `${ fieldName } <<(?<delim>ghadelimiter_.+)\\n${ value } \\n\\k<delim>` ) ;
13+ return new RegExp ( `${ fieldName } <<(?<delim>ghadelimiter_.+)\\n${ escapeRegex ( value ) } \\n\\k<delim>` ) ;
1014}
1115
1216describe ( 'main action' , ( ) => {
@@ -70,18 +74,23 @@ describe('main action', () => {
7074
7175 const expectedPngOutput = [
7276 regexOutput ( 'deleted-png' , '' ) ,
77+ regexOutput ( 'deleted-png-json' , JSON . stringify ( [ ] ) ) ,
7378 regexOutput ( 'png' , 'added_img.png changed_img.png' ) ,
79+ regexOutput ( 'png-json' , JSON . stringify ( [ 'added_img.png' , 'changed_img.png' ] ) ) ,
7480 regexOutput ( 'any-png' , 'true' ) ,
7581 ] ;
7682
7783 const expectedTxtOutput = [
7884 regexOutput ( 'deleted-txt' , 'deleted_text.txt' ) ,
85+ regexOutput ( 'deleted-txt-json' , JSON . stringify ( [ 'deleted_text.txt' ] ) ) ,
7986 regexOutput ( 'txt' , 'added_text.txt changed_text.txt' ) ,
87+ regexOutput ( 'txt-json' , JSON . stringify ( [ 'added_text.txt' , 'changed_text.txt' ] ) ) ,
8088 regexOutput ( 'any-txt' , 'true' ) ,
8189 ] ;
8290
8391 const expectedMissingOutput = [
8492 regexOutput ( 'missing' , '' ) ,
93+ regexOutput ( 'missing-json' , JSON . stringify ( [ ] ) ) ,
8594 regexOutput ( 'any-missing' , 'false' ) ,
8695 regexOutput ( 'any-matches' , 'true' ) ,
8796 ] ;
0 commit comments