88 */
99
1010using System ;
11- using System . Collections . Generic ;
1211using Moq ;
1312using NUnit . Framework ;
1413using React . Exceptions ;
@@ -21,7 +20,7 @@ public class JsxTransformerTests
2120 private Mock < IReactEnvironment > _environment ;
2221 private Mock < ICache > _cache ;
2322 private Mock < IFileSystem > _fileSystem ;
24- private Mock < IFileCacheHash > _fileCacheHash ;
23+ private Mock < IFileCacheHash > _fileCacheHash ;
2524 private JsxTransformer _jsxTransformer ;
2625
2726 [ SetUp ]
@@ -85,13 +84,10 @@ public void ShouldThrowIfEngineNotSupported()
8584 [ Test ]
8685 public void ShouldUseCacheProvider ( )
8786 {
88- _cache . Setup ( x => x . GetOrInsert (
89- /*key*/ "JSX_foo.jsx" ,
90- /*slidingExpiration*/ It . IsAny < TimeSpan > ( ) ,
91- /*getData*/ It . IsAny < Func < string > > ( ) ,
92- /*cacheDependencyKeys*/ It . IsAny < IEnumerable < string > > ( ) ,
93- /*cacheDependencyFiles*/ It . IsAny < IEnumerable < string > > ( )
94- ) ) . Returns ( "/* cached */" ) ;
87+ _cache . Setup ( x => x . Get < JavaScriptWithSourceMap > ( "JSX_v2_foo.jsx" , null ) ) . Returns ( new JavaScriptWithSourceMap
88+ {
89+ Code = "/* cached */"
90+ } ) ;
9591
9692 var result = _jsxTransformer . TransformJsxFile ( "foo.jsx" ) ;
9793 Assert . AreEqual ( "/* cached */" , result ) ;
@@ -104,7 +100,7 @@ public void ShouldUseFileSystemCacheIfHashValid()
104100 _fileSystem . Setup ( x => x . FileExists ( "foo.generated.js" ) ) . Returns ( true ) ;
105101 _fileSystem . Setup ( x => x . ReadAsString ( "foo.generated.js" ) ) . Returns ( "/* filesystem cached */" ) ;
106102 _fileCacheHash . Setup ( x => x . ValidateHash ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) ) . Returns ( true ) ;
107-
103+
108104 var result = _jsxTransformer . TransformJsxFile ( "foo.jsx" ) ;
109105 Assert . AreEqual ( "/* filesystem cached */" , result ) ;
110106 }
@@ -117,13 +113,14 @@ public void ShouldTransformJsxIfFileCacheHashInvalid()
117113 _fileSystem . Setup ( x => x . ReadAsString ( "foo.generated.js" ) ) . Returns ( "/* filesystem cached invalid */" ) ;
118114 _fileSystem . Setup ( x => x . ReadAsString ( "foo.jsx" ) ) . Returns ( "<div>Hello World</div>" ) ;
119115 _fileCacheHash . Setup ( x => x . ValidateHash ( It . IsAny < string > ( ) , It . IsAny < string > ( ) ) ) . Returns ( false ) ;
120-
121- _jsxTransformer . TransformJsxFile ( "foo.jsx" ) ;
122- _environment . Verify ( x => x . ExecuteWithLargerStackIfRequired < string > (
123- "ReactNET_transform" ,
124- "<div>Hello World</div>" ,
116+ _environment . Setup ( x => x . ExecuteWithLargerStackIfRequired < JavaScriptWithSourceMap > (
117+ "ReactNET_transform_sourcemap" ,
118+ It . IsAny < string > ( ) ,
125119 false
126- ) ) ;
120+ ) ) . Returns ( new JavaScriptWithSourceMap { Code = "React.DOM.div('Hello World')" } ) ;
121+
122+ var result = _jsxTransformer . TransformJsxFile ( "foo.jsx" ) ;
123+ Assert . AreEqual ( "React.DOM.div('Hello World')" , result ) ;
127124 }
128125
129126 [ Test ]
@@ -132,24 +129,25 @@ public void ShouldTransformJsxIfNoCache()
132129 SetUpEmptyCache ( ) ;
133130 _fileSystem . Setup ( x => x . FileExists ( "foo.generated.js" ) ) . Returns ( false ) ;
134131 _fileSystem . Setup ( x => x . ReadAsString ( "foo.jsx" ) ) . Returns ( "<div>Hello World</div>" ) ;
135-
136- _jsxTransformer . TransformJsxFile ( "foo.jsx" ) ;
137- _environment . Verify ( x => x . ExecuteWithLargerStackIfRequired < string > (
138- "ReactNET_transform" ,
139- "<div>Hello World</div>" ,
132+ _environment . Setup ( x => x . ExecuteWithLargerStackIfRequired < JavaScriptWithSourceMap > (
133+ "ReactNET_transform_sourcemap" ,
134+ It . IsAny < string > ( ) ,
140135 false
141- ) ) ;
136+ ) ) . Returns ( new JavaScriptWithSourceMap { Code = "React.DOM.div('Hello World')" } ) ;
137+
138+ var result = _jsxTransformer . TransformJsxFile ( "foo.jsx" ) ;
139+ Assert . AreEqual ( "React.DOM.div('Hello World')" , result ) ;
142140 }
143141
144142 [ Test ]
145143 public void ShouldSaveTransformationResult ( )
146144 {
147145 _fileSystem . Setup ( x => x . ReadAsString ( "foo.jsx" ) ) . Returns ( "<div>Hello World</div>" ) ;
148- _environment . Setup ( x => x . ExecuteWithLargerStackIfRequired < string > (
149- "ReactNET_transform " ,
150- "<div>Hello World</div>" ,
146+ _environment . Setup ( x => x . ExecuteWithLargerStackIfRequired < JavaScriptWithSourceMap > (
147+ "ReactNET_transform_sourcemap " ,
148+ It . IsAny < string > ( ) ,
151149 false
152- ) ) . Returns ( "React.DOM.div('Hello World')" ) ;
150+ ) ) . Returns ( new JavaScriptWithSourceMap { Code = "React.DOM.div('Hello World')" } ) ;
153151
154152 string result = null ;
155153 _fileSystem . Setup ( x => x . WriteAsString ( "foo.generated.js" , It . IsAny < string > ( ) ) ) . Callback (
@@ -163,20 +161,7 @@ public void ShouldSaveTransformationResult()
163161
164162 private void SetUpEmptyCache ( )
165163 {
166- _cache . Setup ( x => x . GetOrInsert (
167- /*key*/ "JSX_foo.jsx" ,
168- /*slidingExpiration*/ It . IsAny < TimeSpan > ( ) ,
169- /*getData*/ It . IsAny < Func < string > > ( ) ,
170- /*cacheDependencyKeys*/ It . IsAny < IEnumerable < string > > ( ) ,
171- /*cacheDependencyFiles*/ It . IsAny < IEnumerable < string > > ( )
172- ) )
173- . Returns ( (
174- string key ,
175- TimeSpan slidingExpiration ,
176- Func < string > getData ,
177- IEnumerable < string > cacheDependencyFiles ,
178- IEnumerable < string > cacheDependencyKeys
179- ) => getData ( ) ) ;
164+ _cache . Setup ( x => x . Get < JavaScriptWithSourceMap > ( "JSX_v2_foo.jsx" , null ) ) . Returns ( ( JavaScriptWithSourceMap ) null ) ;
180165 }
181166 }
182167}
0 commit comments