@@ -26,34 +26,34 @@ type TestFile = {
2626} ;
2727const TEST_FILES : TestFile [ ] = [
2828 {
29+ diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file2_deleted.txt%0A@@ -1,4 +1,3 @@%0A A%0A-B%0A C%0A D%0A" ,
2930 path : "file2_deleted.txt" ,
3031 tolerance : "worse" ,
31- diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file2_deleted.txt%0A@@ -1,4 +1,3 @@%0A A%0A-B%0A C%0A D%0A" ,
3232 } ,
3333 {
34+ diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file3_same.txt%0A" ,
3435 path : "file3_same.txt" ,
3536 tolerance : "same" ,
36- diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file3_same.txt%0A" ,
3737 } ,
3838 {
39+ diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file4_added.txt%0A@@ -1,4 +1,5 @@%0A A%0A B%0A C%0A D%0A+E%0A" ,
3940 path : "file4_added.txt" ,
4041 tolerance : "better" ,
41- diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file4_added.txt%0A@@ -1,4 +1,5 @@%0A A%0A B%0A C%0A D%0A+E%0A" ,
4242 } ,
4343 {
44+ diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file5_mixed.txt%0A@@ -1,4 +1,4 @@%0A A%0A B%0A-C%0A D%0A+E%0A" ,
4445 path : "file5_mixed.txt" ,
4546 tolerance : "mixed" ,
46- diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file5_mixed.txt%0A@@ -1,4 +1,4 @@%0A A%0A B%0A-C%0A D%0A+E%0A" ,
4747 } ,
4848 {
49+ diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file6_mixed_added.txt%0A@@ -1,4 +1,5 @@%0A A%0A B%0A-C%0A D%0A+E%0A+F%0A" ,
4950 path : "file6_mixed_added.txt" ,
5051 tolerance : "mixed-better" ,
51- diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file6_mixed_added.txt%0A@@ -1,4 +1,5 @@%0A A%0A B%0A-C%0A D%0A+E%0A+F%0A" ,
5252 } ,
5353 {
54+ diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file7_mixed_deleted.txt%0A@@ -1,4 +1,3 @@%0A A%0A B%0A-C%0A-D%0A+E%0A" ,
5455 path : "file7_mixed_deleted.txt" ,
5556 tolerance : "mixed-worse" ,
56- diff : "===================================================================%0A--- FIXTURES/file1_basic.txt%0A+++ FIXTURES/file7_mixed_deleted.txt%0A@@ -1,4 +1,3 @@%0A A%0A B%0A-C%0A-D%0A+E%0A" ,
5757 } ,
5858] ;
5959
@@ -95,8 +95,8 @@ describe("run action", () => {
9595 } ;
9696
9797 const parseOutput = ( actionOutput : string ) : ActionOutputs => {
98- let passed : boolean | undefined = undefined ;
99- let output : string | undefined = undefined ;
98+ let passed : boolean | undefined ;
99+ let output : string | undefined ;
100100 for ( const line of actionOutput . split ( "\n" ) ) {
101101 if ( line . startsWith ( "::set-output name=passed::" ) ) {
102102 passed = line . split ( "::set-output name=passed::" ) [ 1 ] === "true" ;
@@ -108,7 +108,7 @@ describe("run action", () => {
108108 if ( passed === undefined || output === undefined ) {
109109 throw new Error ( "Action did not return expected output" ) ;
110110 }
111- return { passed , output } ;
111+ return { output , passed } ;
112112 } ;
113113
114114 const runAction = (
@@ -122,7 +122,7 @@ describe("run action", () => {
122122 process . env . INPUT_TOLERANCE = tolerance . toString ( ) ;
123123 process . env . INPUT_MODE = mode . toString ( ) ;
124124 process . env . GITHUB_OUTPUT = "" ;
125- const main = path . join ( __dirname , ".." , "lib " , "main .js" ) ;
125+ const main = path . join ( __dirname , ".." , "dist " , "index .js" ) ;
126126 const options : cp . ExecSyncOptions = {
127127 env : process . env ,
128128 } ;
@@ -160,25 +160,25 @@ describe("run action", () => {
160160 const cases = ( ( ) : Case [ ] => {
161161 const cases : Case [ ] = [
162162 {
163+ expectError : true ,
164+ mode : "strict" ,
163165 name : "an unknown file" ,
164166 newFile : "do not exist . whatever" ,
165- mode : "strict" ,
166167 tolerance : "same" ,
167- expectError : true ,
168168 } ,
169169 {
170+ expectError : true ,
171+ mode : "mixed" as unknown as Mode ,
170172 name : "an unknown mode" ,
171173 newFile : TEST_FILES [ 0 ] . path ,
172- mode : "mixed" as unknown as Mode ,
173174 tolerance : "same" ,
174- expectError : true ,
175175 } ,
176176 {
177+ expectError : true ,
178+ mode : "addition" ,
177179 name : "an unknown tolerance" ,
178180 newFile : TEST_FILES [ 0 ] . path ,
179- mode : "addition" ,
180181 tolerance : "high" as unknown as Tolerance ,
181- expectError : true ,
182182 } ,
183183 ] ;
184184
@@ -195,13 +195,13 @@ describe("run action", () => {
195195 result = "an error" ;
196196 }
197197 cases . push ( {
198+ expectError,
199+ expectedOutput : file . diff ,
200+ expectedPass,
201+ mode : mode ,
198202 name : `file ${ file . path } , mode ${ mode } , tolerance ${ tolerance } and expecting ${ result } ` ,
199203 newFile : file . path ,
200204 tolerance : tolerance ,
201- mode : mode ,
202- expectedPass,
203- expectedOutput : file . diff ,
204- expectError,
205205 } ) ;
206206 }
207207 }
@@ -210,34 +210,31 @@ describe("run action", () => {
210210 return cases ;
211211 } ) ( ) ;
212212
213- test . each ( cases ) (
214- "with $name" ,
215- ( {
216- newFile,
213+ test . each ( cases ) ( "with $name" , ( {
214+ newFile,
215+ tolerance,
216+ mode,
217+ expectedPass,
218+ expectedOutput,
219+ expectError,
220+ } : Case ) => {
221+ if ( expectError ) {
222+ expect ( ( ) => {
223+ runAction ( BASE_FILE , newFile , tolerance , mode ) ;
224+ } ) . toThrow ( ) ;
225+ return ;
226+ }
227+ const { passed, output } = runAction (
228+ BASE_FILE ,
229+ path . join ( FIXTURES_FOLDER , newFile ) ,
217230 tolerance ,
218231 mode ,
219- expectedPass,
232+ ) ;
233+ expect ( passed ) . toBe ( expectedPass ) ;
234+ expect ( output . replace ( new RegExp ( FIXTURES_FOLDER , "g" ) , "FIXTURES" ) ) . toBe (
220235 expectedOutput ,
221- expectError,
222- } : Case ) => {
223- if ( expectError ) {
224- expect ( ( ) => {
225- runAction ( BASE_FILE , newFile , tolerance , mode ) ;
226- } ) . toThrow ( ) ;
227- return ;
228- }
229- const { passed, output } = runAction (
230- BASE_FILE ,
231- path . join ( FIXTURES_FOLDER , newFile ) ,
232- tolerance ,
233- mode ,
234- ) ;
235- expect ( passed ) . toBe ( expectedPass ) ;
236- expect ( output . replace ( new RegExp ( FIXTURES_FOLDER , "g" ) , "FIXTURES" ) ) . toBe (
237- expectedOutput ,
238- ) ;
239- } ,
240- ) ;
236+ ) ;
237+ } ) ;
241238} ) ;
242239
243240// TODO: missing tests for notifications?
0 commit comments