@@ -4,11 +4,12 @@ import path from 'path';
44import { TaskOutDirs } from 'Task' ;
55import { test , expect , describe } from 'vitest' ;
66import { mkdir , readdir , readFile , rm , writeFile } from 'fs/promises' ;
7- import { compare , CompareFileHandler , Options } from 'dir-compare' ;
7+ import { compare , CompareFileHandler , Difference , Options } from 'dir-compare' ;
88import { fileCompareHandlers } from 'dir-compare' ;
99import { isText } from 'istextorbinary' ;
1010import { strFromU8 } from 'fflate' ;
1111import { PkBookSpec , PkTestLogger } from '../../convertBooks' ;
12+ import { AssertionError } from 'assert' ;
1213
1314interface TestAppPaths {
1415 input : string ;
@@ -84,12 +85,42 @@ async function assertDirsEqual(actual: PathLike, expected: PathLike, excludeFilt
8485 compareTimeStamp : false ,
8586 excludeFilter
8687 } ;
87- await expect
88- . poll ( async ( ) => {
89- const result = await compare ( actual . toString ( ) , expected . toString ( ) , cmpOptions ) ;
90- return result . diffSet ?. filter ( ( diff ) => diff . state != 'equal' ) ;
91- } , pollOptions )
92- . toEqual ( [ ] ) ;
88+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
89+ const comparrison = await compare ( expected . toString ( ) , actual . toString ( ) , cmpOptions ) ;
90+ for ( const diff of comparrison . diffSet ?? [ ] ) {
91+ assertFileDiffEqual ( diff ) ;
92+ }
93+ // await expect
94+ // .poll(async () => {
95+ // const result = await compare(actual.toString(), expected.toString(), cmpOptions);
96+ // return result.diffSet?.filter((diff) => diff.state != 'equal');
97+ // }, pollOptions)
98+ // .toEqual([]);
99+ }
100+
101+ function assertFileDiffEqual ( diff : Difference ) {
102+ if ( diff . state != 'equal' ) {
103+ const message = fileDiffError ( diff ) ;
104+ throw new AssertionError ( { message } ) ;
105+ }
106+ }
107+
108+ function fileDiffError ( diff : Difference ) : string {
109+ const baseMessage = fileDiffErrorSummary ( diff ) ;
110+ const details = JSON . stringify ( diff , null , 2 ) ;
111+ const message = baseMessage + '\nDetails:\n' + details ;
112+ return message ;
113+ }
114+
115+ function fileDiffErrorSummary ( diff : Difference ) : string {
116+ if ( diff . state == 'left' ) {
117+ return `${ diff . type1 } '${ diff . name1 } ' is missing from output` ;
118+ } else if ( diff . state == 'right' ) {
119+ return `Unexpected ${ diff . type2 } '${ diff . name2 } ' in output` ;
120+ } else if ( diff . state == 'distinct' ) {
121+ return `Contents of ${ diff . type1 } '${ diff . name1 } ' does not match snapshot` ;
122+ }
123+ return `Unexpected diff result: ${ diff . state } ` ;
93124}
94125
95126function maskDocIds ( catalog : any ) {
0 commit comments