@@ -1293,6 +1293,7 @@ namespace Harness {
1293
1293
export interface BaselineOptions {
1294
1294
Subfolder ?: string ;
1295
1295
Baselinefolder ?: string ;
1296
+ PrintDiff ?: true ;
1296
1297
}
1297
1298
1298
1299
export function localPath ( fileName : string , baselineFolder ?: string , subfolder ?: string ) {
@@ -1347,7 +1348,7 @@ namespace Harness {
1347
1348
return { expected, actual } ;
1348
1349
}
1349
1350
1350
- function writeComparison ( expected : string , actual : string , relativeFileName : string , actualFileName : string ) {
1351
+ function writeComparison ( expected : string , actual : string , relativeFileName : string , actualFileName : string , opts ?: BaselineOptions ) {
1351
1352
// For now this is written using TypeScript, because sys is not available when running old test cases.
1352
1353
// But we need to move to sys once we have
1353
1354
// Creates the directory including its parent if not already present
@@ -1381,7 +1382,14 @@ namespace Harness {
1381
1382
else {
1382
1383
IO . writeFile ( actualFileName , encodedActual ) ;
1383
1384
}
1384
- throw new Error ( `The baseline file ${ relativeFileName } has changed.` ) ;
1385
+ if ( require && opts && opts . PrintDiff ) {
1386
+ const Diff = require ( "diff" ) ;
1387
+ const patch = Diff . createTwoFilesPatch ( "Expected" , "Actual" , expected , actual , "The current baseline" , "The new version" ) ;
1388
+ throw new Error ( `The baseline file ${ relativeFileName } has changed.${ ts . ForegroundColorEscapeSequences . Grey } \n\n${ patch } ` ) ;
1389
+ }
1390
+ else {
1391
+ throw new Error ( `The baseline file ${ relativeFileName } has changed.` ) ;
1392
+ }
1385
1393
}
1386
1394
}
1387
1395
@@ -1391,7 +1399,7 @@ namespace Harness {
1391
1399
throw new Error ( "The generated content was \"undefined\". Return \"null\" if no baselining is required.\"" ) ;
1392
1400
}
1393
1401
const comparison = compareToBaseline ( actual , relativeFileName , opts ) ;
1394
- writeComparison ( comparison . expected , comparison . actual , relativeFileName , actualFileName ) ;
1402
+ writeComparison ( comparison . expected , comparison . actual , relativeFileName , actualFileName , opts ) ;
1395
1403
}
1396
1404
1397
1405
export function runMultifileBaseline ( relativeFileBase : string , extension : string , generateContent : ( ) => IterableIterator < [ string , string , number ] > | IterableIterator < [ string , string ] > | null , opts ?: BaselineOptions , referencedExtensions ?: string [ ] ) : void {
0 commit comments