@@ -1293,6 +1293,7 @@ namespace Harness {
12931293 export interface BaselineOptions {
12941294 Subfolder ?: string ;
12951295 Baselinefolder ?: string ;
1296+ PrintDiff ?: true ;
12961297 }
12971298
12981299 export function localPath ( fileName : string , baselineFolder ?: string , subfolder ?: string ) {
@@ -1347,7 +1348,7 @@ namespace Harness {
13471348 return { expected, actual } ;
13481349 }
13491350
1350- function writeComparison ( expected : string , actual : string , relativeFileName : string , actualFileName : string ) {
1351+ function writeComparison ( expected : string , actual : string , relativeFileName : string , actualFileName : string , opts ?: BaselineOptions ) {
13511352 // For now this is written using TypeScript, because sys is not available when running old test cases.
13521353 // But we need to move to sys once we have
13531354 // Creates the directory including its parent if not already present
@@ -1381,7 +1382,14 @@ namespace Harness {
13811382 else {
13821383 IO . writeFile ( actualFileName , encodedActual ) ;
13831384 }
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+ }
13851393 }
13861394 }
13871395
@@ -1391,7 +1399,7 @@ namespace Harness {
13911399 throw new Error ( "The generated content was \"undefined\". Return \"null\" if no baselining is required.\"" ) ;
13921400 }
13931401 const comparison = compareToBaseline ( actual , relativeFileName , opts ) ;
1394- writeComparison ( comparison . expected , comparison . actual , relativeFileName , actualFileName ) ;
1402+ writeComparison ( comparison . expected , comparison . actual , relativeFileName , actualFileName , opts ) ;
13951403 }
13961404
13971405 export function runMultifileBaseline ( relativeFileBase : string , extension : string , generateContent : ( ) => IterableIterator < [ string , string , number ] > | IterableIterator < [ string , string ] > | null , opts ?: BaselineOptions , referencedExtensions ?: string [ ] ) : void {
0 commit comments