11const fs = require ( 'fs' ) ;
22const path = require ( 'path' ) ;
3+ const os = require ( 'os' )
34
45export default class TestUtils {
56
67 private packageName : string | null = null ;
78
89 private testName : string | null = null ;
910
11+ private isWindowsEnv = os . platform ( ) === 'win32'
12+
1013 constructor ( packageName : string , testName : string ) {
1114 this . packageName = packageName ;
1215 this . testName = testName ;
@@ -89,13 +92,18 @@ export default class TestUtils {
8992 fs . writeFileSync ( tmpFilePath , `${ fileContentToSave . trim ( ) } \n` ) ;
9093 }
9194
92- public testToBe ( actual : any , expected : any , tmpFileName : string = null ) : void {
93- this . saveTmpFile ( tmpFileName , actual ) ;
94- expect ( actual ) . toBe ( expected ) ;
95+ public testToBe ( actual : any , expected : any , tmpFileName : string | null = null ) : void {
96+ if ( tmpFileName ) {
97+ this . saveTmpFile ( tmpFileName , actual ) ;
98+ }
99+ expect ( this . unitWhiteSpace ( actual ) ) . toBe ( this . unitWhiteSpace ( expected ) ) ;
95100 }
96101
97- public testMatchObject ( actual : Record < any , any > , expected : Record < any , any > , tmpFileName : string = null ) : void {
98- this . saveTmpFile ( tmpFileName , actual ) ;
102+ public testMatchObject ( actual : Record < any , any > , expected : Record < any , any > , tmpFileName : string | null = null ) : void {
103+ if ( tmpFileName ) {
104+ this . saveTmpFile ( tmpFileName , actual ) ;
105+ }
106+
99107 expect ( actual ) . toMatchObject ( expected ) ;
100108 }
101109
@@ -120,4 +128,12 @@ export default class TestUtils {
120128 this . testToBe ( actualContent , this . getExpectedFile ( expecedFile ) , expecedFile ) ;
121129 }
122130
131+ private unitWhiteSpace ( content : string ) {
132+ if ( typeof content !== 'string' || ! this . isWindowsEnv ) {
133+ return content ;
134+ } ;
135+
136+ return content . replace ( / \s + / g, ' ' ) ;
137+ }
138+
123139}
0 commit comments