@@ -4,11 +4,12 @@ import path from 'path';
4
4
import { TaskOutDirs } from 'Task' ;
5
5
import { test , expect , describe } from 'vitest' ;
6
6
import { 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' ;
8
8
import { fileCompareHandlers } from 'dir-compare' ;
9
9
import { isText } from 'istextorbinary' ;
10
10
import { strFromU8 } from 'fflate' ;
11
11
import { PkBookSpec , PkTestLogger } from '../../convertBooks' ;
12
+ import { AssertionError } from 'assert' ;
12
13
13
14
interface TestAppPaths {
14
15
input : string ;
@@ -84,12 +85,42 @@ async function assertDirsEqual(actual: PathLike, expected: PathLike, excludeFilt
84
85
compareTimeStamp : false ,
85
86
excludeFilter
86
87
} ;
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 } ` ;
93
124
}
94
125
95
126
function maskDocIds ( catalog : any ) {
0 commit comments