@@ -32,6 +32,10 @@ public void SetUp()
3232 _fileSystem = new Mock < IFileSystem > ( ) ;
3333 _fileSystem . Setup ( x => x . MapPath ( It . IsAny < string > ( ) ) ) . Returns < string > ( x => x ) ;
3434
35+ // Per default the output file should not exist, then individual tests
36+ // can choose otherwise.
37+ _fileSystem . Setup ( x => x . FileExists ( It . IsAny < string > ( ) ) ) . Returns ( false ) ;
38+
3539 _fileCacheHash = new Mock < IFileCacheHash > ( ) ;
3640
3741 _babel = new Babel (
@@ -152,6 +156,29 @@ public void ShouldSaveTransformationResult()
152156 StringAssert . EndsWith ( "React.DOM.div('Hello World')" , result ) ;
153157 }
154158
159+ [ Test ]
160+ public void ShouldSkipTransformationIfCacheIsValid ( )
161+ {
162+ _fileSystem . Setup ( x => x . ReadAsString ( "foo.jsx" ) ) . Returns ( "<div>Hello World</div>" ) ;
163+ _fileSystem . Setup ( x => x . FileExists ( It . IsAny < string > ( ) ) ) . Returns ( true ) ;
164+ _fileCacheHash . Setup ( x => x . ValidateHash ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) ) . Returns ( true ) ;
165+ _environment . Setup ( x => x . ExecuteWithBabel < JavaScriptWithSourceMap > (
166+ "ReactNET_transform_sourcemap" ,
167+ It . IsAny < string > ( ) ,
168+ It . IsAny < string > ( ) , // Babel config
169+ "foo.jsx" // File name
170+ ) ) . Returns ( new JavaScriptWithSourceMap { Code = "React.DOM.div('Hello World')" } ) ;
171+
172+ string result = null ;
173+ _fileSystem . Setup ( x => x . WriteAsString ( "foo.generated.js" , It . IsAny < string > ( ) ) ) . Callback (
174+ ( string filename , string contents ) => result = contents
175+ ) ;
176+
177+ var resultFilename = _babel . TransformAndSaveFile ( "foo.jsx" ) ;
178+ Assert . AreEqual ( "foo.generated.js" , resultFilename ) ;
179+ Assert . IsNull ( result , "There should be no result. Cached result should have been used." ) ;
180+ }
181+
155182 private void SetUpEmptyCache ( )
156183 {
157184 _cache . Setup ( x => x . Get < JavaScriptWithSourceMap > ( "JSX_v3_foo.jsx" , null ) ) . Returns ( ( JavaScriptWithSourceMap ) null ) ;
0 commit comments