Skip to content

Commit 8c121e8

Browse files
authored
Merge pull request #581 from juhasuni/rn-win-0.47-fixes
Windows fixes for RN 0.47.*
2 parents 7b95002 + 05758c5 commit 8c121e8

File tree

7 files changed

+2087
-1871
lines changed

7 files changed

+2087
-1871
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
"devDependencies": {
3333
"flow-bin": "0.28.0",
3434
"react": "^16.2.0",
35-
"react-native": "^0.51.0",
35+
"react-native": "^0.57.0",
3636
"prop-types": "15.6.0",
37-
"create-react-class": "^15.6.2"
37+
"create-react-class": "^15.6.2",
38+
"react-native-windows": "^0.57.0"
3839
},
3940
"peerDependencies": {
4041
"react": "^16.2.0",

windows/RNFS.Tests/RNFS.Tests.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<DefaultLanguage>en-US</DefaultLanguage>
1313
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
1414
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
15-
<TargetPlatformMinVersion>10.0.10586.0</TargetPlatformMinVersion>
15+
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
1616
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
1717
<FileAlignment>512</FileAlignment>
1818
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@@ -138,6 +138,12 @@
138138
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
139139
<Version>6.0.6</Version>
140140
</PackageReference>
141+
<PackageReference Include="MSTest.TestAdapter">
142+
<Version>1.3.2</Version>
143+
</PackageReference>
144+
<PackageReference Include="MSTest.TestFramework">
145+
<Version>1.3.2</Version>
146+
</PackageReference>
141147
</ItemGroup>
142148
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
143149
<VisualStudioVersion>14.0</VisualStudioVersion>
@@ -150,4 +156,4 @@
150156
<Target Name="AfterBuild">
151157
</Target>
152158
-->
153-
</Project>
159+
</Project>

windows/RNFS.Tests/RNFSManagerTests.cs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task RNFSManager_writeFile()
4646
var hello = "Hello World";
4747
var base64Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(hello));
4848
var promise = new MockPromise();
49-
manager.writeFile(path, base64Content, promise);
49+
manager.writeFile(path, base64Content, new JObject(), promise);
5050
await promise.Task;
5151

5252
// Assert
@@ -73,7 +73,7 @@ public async Task RNFSManager_writeFile_ExistingFile()
7373
var hello = "Hello World";
7474
var base64Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(hello));
7575
var promise = new MockPromise();
76-
manager.writeFile(path, base64Content, promise);
76+
manager.writeFile(path, base64Content, new JObject(), promise);
7777
await promise.Task;
7878

7979
// Assert
@@ -100,8 +100,8 @@ public async Task RNFSManager_writeFile_ExistingDirectory()
100100
var hello = "Hello World";
101101
var base64Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(hello));
102102
var promise = new MockPromise();
103-
manager.writeFile(path, base64Content, promise);
104-
await AssertRejectAsync(promise, ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
103+
manager.writeFile(path, base64Content, new JObject(), promise);
104+
await AssertRejectAsync(promise, ex => Assert.AreEqual(ex.Message, $"Access to the path '{path}' is denied.", $"Message was {ex.Message}"));
105105

106106
// Cleanup
107107
Directory.Delete(path);
@@ -116,11 +116,12 @@ public async Task RNFSManager_writeFile_Fail()
116116

117117
// Run test
118118
var promise = new MockPromise();
119-
manager.writeFile("badPath", "", promise);
119+
var path = $"{Windows.ApplicationModel.Package.Current.InstalledLocation.Path}\\badPath";
120+
manager.writeFile(path, "", new JObject(), promise);
120121

121122
await AssertRejectAsync(
122123
promise,
123-
ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
124+
ex => Assert.AreEqual(ex.Message, $"Access to the path '{path}' is denied.", $"Message was {ex.Message}"));
124125
}
125126

126127
[TestMethod]
@@ -218,7 +219,7 @@ public async Task RNFSManager_write_ExistingDirectory()
218219
var base64Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(hello));
219220
var promise = new MockPromise();
220221
manager.write(path, base64Content, 0, promise);
221-
await AssertRejectAsync(promise, ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
222+
await AssertRejectAsync(promise, ex => Assert.AreEqual(ex.Message, $"Access to the path '{path}' is denied.", $"Message was {ex.Message}"));
222223

223224
// Cleanup
224225
Directory.Delete(path);
@@ -287,10 +288,11 @@ public async Task RNFSManager_write_Fail()
287288

288289
// Run test
289290
var promise = new MockPromise();
290-
manager.write("badPath", "", 0, promise);
291+
var path = $"{Windows.ApplicationModel.Package.Current.InstalledLocation.Path}\\badPath";
292+
manager.write(path, "", 0, promise);
291293
await AssertRejectAsync(
292294
promise,
293-
ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
295+
ex => Assert.AreEqual(ex.Message, $"Access to the path '{path}' is denied.", $"Message was {ex.Message}"));
294296
}
295297

296298
[TestMethod]
@@ -648,7 +650,7 @@ public async Task RNFSManager_moveFile()
648650
// Run test
649651
var newPath = Path.Combine(tempFolder, Guid.NewGuid().ToString());
650652
var promise = new MockPromise();
651-
manager.moveFile(path, newPath, promise);
653+
manager.moveFile(path, newPath, new JObject(), promise);
652654
await promise.Task;
653655

654656
// Assert
@@ -672,7 +674,7 @@ public async Task RNFSManager_moveFile_NotExists()
672674
var path = Path.Combine(tempFolder, Guid.NewGuid().ToString());
673675
var newPath = Path.Combine(tempFolder, Guid.NewGuid().ToString());
674676
var promise = new MockPromise();
675-
manager.moveFile(path, newPath, promise);
677+
manager.moveFile(path, newPath, new JObject(), promise);
676678
await AssertRejectAsync(promise, ex => Assert.AreEqual("ENOENT", ex.Code));
677679
}
678680

@@ -692,7 +694,7 @@ public async Task RNFSManager_copyFile()
692694
// Run test
693695
var newPath = Path.Combine(tempFolder, Guid.NewGuid().ToString());
694696
var promise = new MockPromise();
695-
manager.copyFile(path, newPath, promise);
697+
manager.copyFile(path, newPath, new JObject(), promise);
696698
await promise.Task;
697699

698700
// Assert
@@ -717,7 +719,7 @@ public async Task RNFSManager_copyFile_NotExists()
717719
var path = Path.Combine(tempFolder, Guid.NewGuid().ToString());
718720
var newPath = Path.Combine(tempFolder, Guid.NewGuid().ToString());
719721
var promise = new MockPromise();
720-
manager.copyFile(path, newPath, promise);
722+
manager.copyFile(path, newPath, new JObject(), promise);
721723
await AssertRejectAsync(promise, ex => Assert.AreEqual("ENOENT", ex.Code));
722724
}
723725

@@ -1066,7 +1068,7 @@ public async Task RNFSManager_mkdir_ExistingFile()
10661068
// Run test
10671069
var promise = new MockPromise();
10681070
manager.mkdir(path, null, promise);
1069-
await AssertRejectAsync(promise, ex => Assert.IsTrue(ex.InnerException is IOException));
1071+
await AssertRejectAsync(promise, ex => Assert.AreEqual(ex.Message, $"Cannot create '{path}' because a file or directory with the same name already exists.", $"Message was {ex.Message}"));
10701072

10711073
// Cleanup
10721074
File.Delete(path);
@@ -1105,11 +1107,12 @@ public async Task RNFSManager_mkdir_Fail()
11051107

11061108
// Run test
11071109
var promise = new MockPromise();
1108-
manager.mkdir("badPath", null, promise);
1110+
var path = $"{Windows.ApplicationModel.Package.Current.InstalledLocation.Path}\\badPath";
1111+
manager.mkdir(path, null, promise);
11091112

11101113
await AssertRejectAsync(
11111114
promise,
1112-
ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
1115+
ex => Assert.AreEqual($"Access to the path '{path}' is denied.", ex.Message, $"Message was {ex.Message}"));
11131116
}
11141117

11151118
[TestMethod]
@@ -1213,7 +1216,7 @@ public async Task RNFSManager_touch_ExistingDirectory()
12131216
ConvertToUnixTimestamp(mtime),
12141217
ConvertToUnixTimestamp(ctime),
12151218
promise);
1216-
await AssertRejectAsync(promise, ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
1219+
await AssertRejectAsync(promise, ex => Assert.AreEqual(ex.Message, $"Access to the path '{path}' is denied.", $"Message was {ex.Message}"));
12171220

12181221
// Cleanup
12191222
Directory.Delete(path);
@@ -1402,7 +1405,7 @@ public async Task RNFSManager_downloadFile_ExistingDirectory()
14021405

14031406
var promise = new MockPromise();
14041407
manager.downloadFile(options, promise);
1405-
await AssertRejectAsync(promise, ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
1408+
await AssertRejectAsync(promise, ex => Assert.AreEqual(ex.Message, $"Access to the path '{path}' is denied.", $"Message was {ex.Message}"));
14061409

14071410
// Cleanup
14081411
Directory.Delete(path);
@@ -1470,7 +1473,7 @@ public async Task RNFSManager_stopDownload()
14701473
var promise = new MockPromise();
14711474
manager.downloadFile(options, promise);
14721475
manager.stopDownload(1);
1473-
await AssertRejectAsync(promise, ex => Assert.IsTrue(ex.InnerException is TaskCanceledException));
1476+
await AssertRejectAsync(promise, ex => Assert.AreEqual("A task was canceled.", ex.Message, ex.Message));
14741477
Assert.IsFalse(new FileInfo(path).Exists);
14751478
}
14761479

@@ -1592,11 +1595,16 @@ public void Reject(Exception exception)
15921595
_tcs.SetException(new RejectException(null, null, exception));
15931596
}
15941597

1598+
public void Reject(string code, string message, string stack, JToken userInfo)
1599+
{
1600+
_tcs.SetException(new RejectException(code, message));
1601+
}
1602+
15951603
public void Resolve(object value)
15961604
{
1597-
_tcs.SetResult(value);
1605+
_tcs.SetResult(value);
15981606
}
1599-
}
1607+
}
16001608

16011609
class RejectException : Exception
16021610
{

windows/RNFS.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ EndProject
1515
Global
1616
GlobalSection(SharedMSBuildProjectFiles) = preSolution
1717
..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.projitems*{c7673ad5-e3aa-468c-a5fd-fa38154e205c}*SharedItemsImports = 4
18+
..\node_modules\react-native-windows\Yoga\csharp\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{c7673ad5-e3aa-468c-a5fd-fa38154e205c}*SharedItemsImports = 4
1819
..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.projitems*{eea8b852-4d07-48e1-8294-a21ab5909fe5}*SharedItemsImports = 13
1920
EndGlobalSection
2021
GlobalSection(SolutionConfigurationPlatforms) = preSolution

windows/RNFS/RNFS.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<AssemblyName>RNFS</AssemblyName>
1212
<DefaultLanguage>en-US</DefaultLanguage>
1313
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
14-
<TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion>
15-
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
14+
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
15+
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
1616
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
1717
<FileAlignment>512</FileAlignment>
1818
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@@ -131,7 +131,7 @@
131131
<EmbeddedResource Include="Properties\RNFS.rd.xml" />
132132
</ItemGroup>
133133
<ItemGroup>
134-
<ProjectReference Include="..\..\..\react-native-windows\ReactWindows\ReactNative\ReactNative.csproj">
134+
<ProjectReference Include="..\..\node_modules\react-native-windows\ReactWindows\ReactNative\ReactNative.csproj">
135135
<Project>{c7673ad5-e3aa-468c-a5fd-fa38154e205c}</Project>
136136
<Name>ReactNative</Name>
137137
</ProjectReference>

windows/RNFS/RNFSManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public override IReadOnlyDictionary<string, object> Constants
104104
}
105105

106106
[ReactMethod]
107-
public async void writeFile(string filepath, string base64Content, JObject _, IPromise promise)
107+
public async void writeFile(string filepath, string base64Content, JObject options, IPromise promise)
108108
{
109109
try
110110
{
@@ -285,7 +285,7 @@ await Task.Run(() =>
285285
}
286286

287287
[ReactMethod]
288-
public void moveFile(string filepath, string destPath, IPromise promise)
288+
public void moveFile(string filepath, string destPath, JObject options, IPromise promise)
289289
{
290290
try
291291
{
@@ -300,7 +300,7 @@ public void moveFile(string filepath, string destPath, IPromise promise)
300300
}
301301

302302
[ReactMethod]
303-
public async void copyFile(string filepath, string destPath, IPromise promise)
303+
public async void copyFile(string filepath, string destPath, JObject options, IPromise promise)
304304
{
305305
try
306306
{
@@ -550,7 +550,7 @@ private async Task ProcessRequestAsync(IPromise promise, HttpRequestMessage requ
550550
});
551551

552552
// TODO: open file on background thread?
553-
var totalRead = 0;
553+
long totalRead = 0;
554554
using (var fileStream = File.OpenWrite(filepath))
555555
using (var stream = await response.Content.ReadAsStreamAsync())
556556
{
@@ -603,7 +603,7 @@ private void Reject(IPromise promise, String filepath, Exception ex)
603603
return;
604604
}
605605

606-
promise.Reject(null, ex.Message, ex);
606+
promise.Reject(ex);
607607
}
608608

609609
private void RejectFileNotFound(IPromise promise, String filepath)

0 commit comments

Comments
 (0)