File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Concurrent ;
33using System . Diagnostics ;
4+ using System . IO ;
45using System . Linq ;
56using System . Reflection ;
67using System . Threading ;
@@ -171,6 +172,10 @@ private void LoadUserScripts(IJsEngine engine)
171172 ex . ColumnNumber
172173 ) ) ;
173174 }
175+ catch ( IOException ex )
176+ {
177+ _scriptLoadException = new ReactScriptLoadException ( ex . Message ) ;
178+ }
174179 }
175180 }
176181
Original file line number Diff line number Diff line change 99
1010using System ;
1111using System . Collections . Generic ;
12+ using System . IO ;
1213using System . Threading ;
1314using JavaScriptEngineSwitcher . Core ;
1415using Moq ;
15- using Xunit ;
1616using React . Exceptions ;
17+ using Xunit ;
1718
1819namespace React . Tests . Core
1920{
@@ -155,6 +156,24 @@ public void ShouldThrowIfReactVersionNotLoaded()
155156 } ) ;
156157 }
157158
159+ [ Fact ]
160+ public void FileLockExceptionShouldBeWrapped ( )
161+ {
162+ var config = new Mock < IReactSiteConfiguration > ( ) ;
163+ config . Setup ( x => x . ScriptsWithoutTransform ) . Returns ( new List < string > { "foo.js" } ) ;
164+ config . Setup ( x => x . LoadReact ) . Returns ( false ) ;
165+ var fileSystem = new Mock < IFileSystem > ( ) ;
166+ fileSystem . Setup ( x => x . ReadAsString ( "foo.js" ) ) . Throws ( new IOException ( "File was locked" ) ) ;
167+
168+ var jsEngine = new Mock < IJsEngine > ( ) ;
169+ jsEngine . Setup ( x => x . Evaluate < int > ( "1 + 1" ) ) . Returns ( 2 ) ;
170+ jsEngine . Setup ( x => x . Execute ( "Test" ) ) ;
171+ var factory = CreateFactory ( config , fileSystem , ( ) => jsEngine . Object ) ;
172+
173+ var ex = Assert . Throws < ReactScriptLoadException > ( ( ) => factory . GetEngineForCurrentThread ( ) ) ;
174+ Assert . Equal ( "File was locked" , ex . Message ) ;
175+ }
176+
158177 [ Fact ]
159178 public void ShouldThrowScriptErrorIfReactFails ( )
160179 {
You can’t perform that action at this time.
0 commit comments