@@ -136,31 +136,6 @@ public void ShouldLoadResourcesWithoutPrecompilation()
136
136
jsEngine . Verify ( x => x . ExecuteResource ( "React.Core.Resources.react.generated.min.js" , reactCoreAssembly ) ) ;
137
137
}
138
138
139
- [ Fact ]
140
- public void ShouldLoadResourcesWithPrecompilationAndWithoutCache ( )
141
- {
142
- var reactCoreAssembly = typeof ( JavaScriptEngineFactory ) . GetTypeInfo ( ) . Assembly ;
143
-
144
- var jsEngine = new Mock < IJsEngine > ( ) ;
145
- jsEngine . Setup ( x => x . SupportsScriptPrecompilation ) . Returns ( true ) ;
146
- jsEngine . Setup ( x => x . Evaluate < int > ( "1 + 1" ) ) . Returns ( 2 ) ;
147
-
148
- var config = new Mock < IReactSiteConfiguration > ( ) ;
149
- config . Setup ( x => x . AllowJavaScriptPrecompilation ) . Returns ( true ) ;
150
- config . Setup ( x => x . LoadReact ) . Returns ( true ) ;
151
-
152
- var cache = new NullCache ( ) ;
153
-
154
- var fileSystem = new Mock < IFileSystem > ( ) ;
155
-
156
- var factory = CreateFactory ( config . Object , cache , fileSystem . Object , ( ) => jsEngine . Object ) ;
157
-
158
- factory . GetEngineForCurrentThread ( ) ;
159
-
160
- jsEngine . Verify ( x => x . ExecuteResource ( "React.Core.Resources.shims.js" , reactCoreAssembly ) ) ;
161
- jsEngine . Verify ( x => x . ExecuteResource ( "React.Core.Resources.react.generated.min.js" , reactCoreAssembly ) ) ;
162
- }
163
-
164
139
[ Fact ]
165
140
public void ShouldLoadResourcesWithPrecompilationAndEmptyCache ( )
166
141
{
@@ -227,49 +202,74 @@ public void ShouldLoadResourcesWithPrecompilationAndNotEmptyCache()
227
202
}
228
203
229
204
[ Fact ]
230
- public void ShouldLoadFilesThatDoNotRequireTransformWithoutPrecompilation ( )
205
+ public void ShouldThrowIfEngineNotSupportPrecompilationOfResources ( )
231
206
{
207
+ var reactCoreAssembly = typeof ( JavaScriptEngineFactory ) . GetTypeInfo ( ) . Assembly ;
208
+
232
209
var jsEngine = new Mock < IJsEngine > ( ) ;
233
- jsEngine . Setup ( x => x . SupportsScriptPrecompilation ) . Returns ( true ) ;
210
+ jsEngine . Setup ( x => x . Name ) . Returns ( "FooJsEngine" ) ;
211
+ jsEngine . Setup ( x => x . Version ) . Returns ( "1.2.3" ) ;
212
+ jsEngine . Setup ( x => x . SupportsScriptPrecompilation ) . Returns ( false ) ;
234
213
jsEngine . Setup ( x => x . Evaluate < int > ( "1 + 1" ) ) . Returns ( 2 ) ;
235
214
236
215
var config = new Mock < IReactSiteConfiguration > ( ) ;
237
- config . Setup ( x => x . ScriptsWithoutTransform ) . Returns ( new List < string > { "First.js" , "Second.js" } ) ;
238
- config . Setup ( x => x . AllowJavaScriptPrecompilation ) . Returns ( false ) ;
216
+ config . Setup ( x => x . AllowJavaScriptPrecompilation ) . Returns ( true ) ;
239
217
config . Setup ( x => x . LoadReact ) . Returns ( true ) ;
240
218
241
219
var cache = new Mock < ICache > ( ) ;
242
220
243
221
var fileSystem = new Mock < IFileSystem > ( ) ;
244
- fileSystem . Setup ( x => x . ReadAsString ( It . IsAny < string > ( ) ) ) . Returns < string > ( path => "CONTENTS_" + path ) ;
245
222
246
223
var factory = CreateFactory ( config , cache , fileSystem , ( ) => jsEngine . Object ) ;
247
224
248
- factory . GetEngineForCurrentThread ( ) ;
249
-
250
- jsEngine . Verify ( x => x . Execute ( "CONTENTS_First.js" , "First.js" ) ) ;
251
- jsEngine . Verify ( x => x . Execute ( "CONTENTS_Second.js" , "Second.js" ) ) ;
225
+ var ex = Assert . Throws < ReactScriptPrecompilationNotAvailableException > (
226
+ ( ) => factory . GetEngineForCurrentThread ( ) ) ;
227
+ Assert . Equal ( "The FooJsEngine version 1.2.3 does not support the script pre-compilation." , ex . Message ) ;
252
228
}
253
229
254
230
[ Fact ]
255
- public void ShouldLoadFilesThatDoNotRequireTransformWithPrecompilationAndWithoutCache ( )
231
+ public void ShouldThrowIfPrecompilationOfResourcesIsPerformedWithoutCache ( )
256
232
{
233
+ var reactCoreAssembly = typeof ( JavaScriptEngineFactory ) . GetTypeInfo ( ) . Assembly ;
234
+
257
235
var jsEngine = new Mock < IJsEngine > ( ) ;
258
236
jsEngine . Setup ( x => x . SupportsScriptPrecompilation ) . Returns ( true ) ;
259
237
jsEngine . Setup ( x => x . Evaluate < int > ( "1 + 1" ) ) . Returns ( 2 ) ;
260
238
261
239
var config = new Mock < IReactSiteConfiguration > ( ) ;
262
- config . Setup ( x => x . ScriptsWithoutTransform ) . Returns ( new List < string > { "First.js" , "Second.js" } ) ;
263
240
config . Setup ( x => x . AllowJavaScriptPrecompilation ) . Returns ( true ) ;
264
241
config . Setup ( x => x . LoadReact ) . Returns ( true ) ;
265
242
266
243
var cache = new NullCache ( ) ;
267
244
268
245
var fileSystem = new Mock < IFileSystem > ( ) ;
269
- fileSystem . Setup ( x => x . ReadAsString ( It . IsAny < string > ( ) ) ) . Returns < string > ( path => "CONTENTS_" + path ) ;
270
246
271
247
var factory = CreateFactory ( config . Object , cache , fileSystem . Object , ( ) => jsEngine . Object ) ;
272
248
249
+ var ex = Assert . Throws < ReactScriptPrecompilationNotAvailableException > (
250
+ ( ) => factory . GetEngineForCurrentThread ( ) ) ;
251
+ Assert . Equal ( "Usage of the script pre-compilation without caching does not make sense." , ex . Message ) ;
252
+ }
253
+
254
+ [ Fact ]
255
+ public void ShouldLoadFilesThatDoNotRequireTransformWithoutPrecompilation ( )
256
+ {
257
+ var jsEngine = new Mock < IJsEngine > ( ) ;
258
+ jsEngine . Setup ( x => x . SupportsScriptPrecompilation ) . Returns ( true ) ;
259
+ jsEngine . Setup ( x => x . Evaluate < int > ( "1 + 1" ) ) . Returns ( 2 ) ;
260
+
261
+ var config = new Mock < IReactSiteConfiguration > ( ) ;
262
+ config . Setup ( x => x . ScriptsWithoutTransform ) . Returns ( new List < string > { "First.js" , "Second.js" } ) ;
263
+ config . Setup ( x => x . AllowJavaScriptPrecompilation ) . Returns ( false ) ;
264
+ config . Setup ( x => x . LoadReact ) . Returns ( true ) ;
265
+
266
+ var cache = new Mock < ICache > ( ) ;
267
+
268
+ var fileSystem = new Mock < IFileSystem > ( ) ;
269
+ fileSystem . Setup ( x => x . ReadAsString ( It . IsAny < string > ( ) ) ) . Returns < string > ( path => "CONTENTS_" + path ) ;
270
+
271
+ var factory = CreateFactory ( config , cache , fileSystem , ( ) => jsEngine . Object ) ;
272
+
273
273
factory . GetEngineForCurrentThread ( ) ;
274
274
275
275
jsEngine . Verify ( x => x . Execute ( "CONTENTS_First.js" , "First.js" ) ) ;
@@ -340,6 +340,56 @@ public void ShouldLoadFilesThatDoNotRequireTransformWithPrecompilationAndNotEmpt
340
340
jsEngine . Verify ( x => x . Execute ( secondPrecompiledScript ) ) ;
341
341
}
342
342
343
+ [ Fact ]
344
+ public void ShouldThrowIfEngineNotSupportPrecompilationOfFilesThatDoNotRequireTransform ( )
345
+ {
346
+ var jsEngine = new Mock < IJsEngine > ( ) ;
347
+ jsEngine . Setup ( x => x . Name ) . Returns ( "FooJsEngine" ) ;
348
+ jsEngine . Setup ( x => x . Version ) . Returns ( "1.2.3" ) ;
349
+ jsEngine . Setup ( x => x . SupportsScriptPrecompilation ) . Returns ( false ) ;
350
+ jsEngine . Setup ( x => x . Evaluate < int > ( "1 + 1" ) ) . Returns ( 2 ) ;
351
+
352
+ var config = new Mock < IReactSiteConfiguration > ( ) ;
353
+ config . Setup ( x => x . ScriptsWithoutTransform ) . Returns ( new List < string > { "First.js" , "Second.js" } ) ;
354
+ config . Setup ( x => x . AllowJavaScriptPrecompilation ) . Returns ( true ) ;
355
+ config . Setup ( x => x . LoadReact ) . Returns ( true ) ;
356
+
357
+ var cache = new Mock < ICache > ( ) ;
358
+
359
+ var fileSystem = new Mock < IFileSystem > ( ) ;
360
+ fileSystem . Setup ( x => x . ReadAsString ( It . IsAny < string > ( ) ) ) . Returns < string > ( path => "CONTENTS_" + path ) ;
361
+
362
+ var factory = CreateFactory ( config , cache , fileSystem , ( ) => jsEngine . Object ) ;
363
+
364
+ var ex = Assert . Throws < ReactScriptPrecompilationNotAvailableException > (
365
+ ( ) => factory . GetEngineForCurrentThread ( ) ) ;
366
+ Assert . Equal ( "The FooJsEngine version 1.2.3 does not support the script pre-compilation." , ex . Message ) ;
367
+ }
368
+
369
+ [ Fact ]
370
+ public void ShouldThrowIfPrecompilationOfFilesThatDoNotRequireTransformIsPerformedWithoutCache ( )
371
+ {
372
+ var jsEngine = new Mock < IJsEngine > ( ) ;
373
+ jsEngine . Setup ( x => x . SupportsScriptPrecompilation ) . Returns ( true ) ;
374
+ jsEngine . Setup ( x => x . Evaluate < int > ( "1 + 1" ) ) . Returns ( 2 ) ;
375
+
376
+ var config = new Mock < IReactSiteConfiguration > ( ) ;
377
+ config . Setup ( x => x . ScriptsWithoutTransform ) . Returns ( new List < string > { "First.js" , "Second.js" } ) ;
378
+ config . Setup ( x => x . AllowJavaScriptPrecompilation ) . Returns ( true ) ;
379
+ config . Setup ( x => x . LoadReact ) . Returns ( true ) ;
380
+
381
+ var cache = new NullCache ( ) ;
382
+
383
+ var fileSystem = new Mock < IFileSystem > ( ) ;
384
+ fileSystem . Setup ( x => x . ReadAsString ( It . IsAny < string > ( ) ) ) . Returns < string > ( path => "CONTENTS_" + path ) ;
385
+
386
+ var factory = CreateFactory ( config . Object , cache , fileSystem . Object , ( ) => jsEngine . Object ) ;
387
+
388
+ var ex = Assert . Throws < ReactScriptPrecompilationNotAvailableException > (
389
+ ( ) => factory . GetEngineForCurrentThread ( ) ) ;
390
+ Assert . Equal ( "Usage of the script pre-compilation without caching does not make sense." , ex . Message ) ;
391
+ }
392
+
343
393
[ Fact ]
344
394
public void ShouldHandleLoadingExternalReactVersion ( )
345
395
{
0 commit comments