Skip to content

Commit

Permalink
Merge pull request #581 from juhasuni/rn-win-0.47-fixes
Browse files Browse the repository at this point in the history
Windows fixes for RN 0.47.*
  • Loading branch information
itinance authored Dec 19, 2018
2 parents 7b95002 + 05758c5 commit 8c121e8
Show file tree
Hide file tree
Showing 7 changed files with 2,087 additions and 1,871 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
"devDependencies": {
"flow-bin": "0.28.0",
"react": "^16.2.0",
"react-native": "^0.51.0",
"react-native": "^0.57.0",
"prop-types": "15.6.0",
"create-react-class": "^15.6.2"
"create-react-class": "^15.6.2",
"react-native-windows": "^0.57.0"
},
"peerDependencies": {
"react": "^16.2.0",
Expand Down
10 changes: 8 additions & 2 deletions windows/RNFS.Tests/RNFS.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10586.0</TargetPlatformMinVersion>
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down Expand Up @@ -138,6 +138,12 @@
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.0.6</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>1.3.2</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>1.3.2</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
Expand All @@ -150,4 +156,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
50 changes: 29 additions & 21 deletions windows/RNFS.Tests/RNFSManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task RNFSManager_writeFile()
var hello = "Hello World";
var base64Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(hello));
var promise = new MockPromise();
manager.writeFile(path, base64Content, promise);
manager.writeFile(path, base64Content, new JObject(), promise);
await promise.Task;

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

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

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

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

await AssertRejectAsync(
promise,
ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
ex => Assert.AreEqual(ex.Message, $"Access to the path '{path}' is denied.", $"Message was {ex.Message}"));
}

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

// Cleanup
Directory.Delete(path);
Expand Down Expand Up @@ -287,10 +288,11 @@ public async Task RNFSManager_write_Fail()

// Run test
var promise = new MockPromise();
manager.write("badPath", "", 0, promise);
var path = $"{Windows.ApplicationModel.Package.Current.InstalledLocation.Path}\\badPath";
manager.write(path, "", 0, promise);
await AssertRejectAsync(
promise,
ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
ex => Assert.AreEqual(ex.Message, $"Access to the path '{path}' is denied.", $"Message was {ex.Message}"));
}

[TestMethod]
Expand Down Expand Up @@ -648,7 +650,7 @@ public async Task RNFSManager_moveFile()
// Run test
var newPath = Path.Combine(tempFolder, Guid.NewGuid().ToString());
var promise = new MockPromise();
manager.moveFile(path, newPath, promise);
manager.moveFile(path, newPath, new JObject(), promise);
await promise.Task;

// Assert
Expand All @@ -672,7 +674,7 @@ public async Task RNFSManager_moveFile_NotExists()
var path = Path.Combine(tempFolder, Guid.NewGuid().ToString());
var newPath = Path.Combine(tempFolder, Guid.NewGuid().ToString());
var promise = new MockPromise();
manager.moveFile(path, newPath, promise);
manager.moveFile(path, newPath, new JObject(), promise);
await AssertRejectAsync(promise, ex => Assert.AreEqual("ENOENT", ex.Code));
}

Expand All @@ -692,7 +694,7 @@ public async Task RNFSManager_copyFile()
// Run test
var newPath = Path.Combine(tempFolder, Guid.NewGuid().ToString());
var promise = new MockPromise();
manager.copyFile(path, newPath, promise);
manager.copyFile(path, newPath, new JObject(), promise);
await promise.Task;

// Assert
Expand All @@ -717,7 +719,7 @@ public async Task RNFSManager_copyFile_NotExists()
var path = Path.Combine(tempFolder, Guid.NewGuid().ToString());
var newPath = Path.Combine(tempFolder, Guid.NewGuid().ToString());
var promise = new MockPromise();
manager.copyFile(path, newPath, promise);
manager.copyFile(path, newPath, new JObject(), promise);
await AssertRejectAsync(promise, ex => Assert.AreEqual("ENOENT", ex.Code));
}

Expand Down Expand Up @@ -1066,7 +1068,7 @@ public async Task RNFSManager_mkdir_ExistingFile()
// Run test
var promise = new MockPromise();
manager.mkdir(path, null, promise);
await AssertRejectAsync(promise, ex => Assert.IsTrue(ex.InnerException is IOException));
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}"));

// Cleanup
File.Delete(path);
Expand Down Expand Up @@ -1105,11 +1107,12 @@ public async Task RNFSManager_mkdir_Fail()

// Run test
var promise = new MockPromise();
manager.mkdir("badPath", null, promise);
var path = $"{Windows.ApplicationModel.Package.Current.InstalledLocation.Path}\\badPath";
manager.mkdir(path, null, promise);

await AssertRejectAsync(
promise,
ex => Assert.IsTrue(ex.InnerException is UnauthorizedAccessException));
ex => Assert.AreEqual($"Access to the path '{path}' is denied.", ex.Message, $"Message was {ex.Message}"));
}

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

// Cleanup
Directory.Delete(path);
Expand Down Expand Up @@ -1402,7 +1405,7 @@ public async Task RNFSManager_downloadFile_ExistingDirectory()

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

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

Expand Down Expand Up @@ -1592,11 +1595,16 @@ public void Reject(Exception exception)
_tcs.SetException(new RejectException(null, null, exception));
}

public void Reject(string code, string message, string stack, JToken userInfo)
{
_tcs.SetException(new RejectException(code, message));
}

public void Resolve(object value)
{
_tcs.SetResult(value);
_tcs.SetResult(value);
}
}
}

class RejectException : Exception
{
Expand Down
1 change: 1 addition & 0 deletions windows/RNFS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.projitems*{c7673ad5-e3aa-468c-a5fd-fa38154e205c}*SharedItemsImports = 4
..\node_modules\react-native-windows\Yoga\csharp\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{c7673ad5-e3aa-468c-a5fd-fa38154e205c}*SharedItemsImports = 4
..\node_modules\react-native-windows\ReactWindows\ReactNative.Shared\ReactNative.Shared.projitems*{eea8b852-4d07-48e1-8294-a21ab5909fe5}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
6 changes: 3 additions & 3 deletions windows/RNFS/RNFS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<AssemblyName>RNFS</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down Expand Up @@ -131,7 +131,7 @@
<EmbeddedResource Include="Properties\RNFS.rd.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\react-native-windows\ReactWindows\ReactNative\ReactNative.csproj">
<ProjectReference Include="..\..\node_modules\react-native-windows\ReactWindows\ReactNative\ReactNative.csproj">
<Project>{c7673ad5-e3aa-468c-a5fd-fa38154e205c}</Project>
<Name>ReactNative</Name>
</ProjectReference>
Expand Down
10 changes: 5 additions & 5 deletions windows/RNFS/RNFSManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public override IReadOnlyDictionary<string, object> Constants
}

[ReactMethod]
public async void writeFile(string filepath, string base64Content, JObject _, IPromise promise)
public async void writeFile(string filepath, string base64Content, JObject options, IPromise promise)
{
try
{
Expand Down Expand Up @@ -285,7 +285,7 @@ await Task.Run(() =>
}

[ReactMethod]
public void moveFile(string filepath, string destPath, IPromise promise)
public void moveFile(string filepath, string destPath, JObject options, IPromise promise)
{
try
{
Expand All @@ -300,7 +300,7 @@ public void moveFile(string filepath, string destPath, IPromise promise)
}

[ReactMethod]
public async void copyFile(string filepath, string destPath, IPromise promise)
public async void copyFile(string filepath, string destPath, JObject options, IPromise promise)
{
try
{
Expand Down Expand Up @@ -550,7 +550,7 @@ private async Task ProcessRequestAsync(IPromise promise, HttpRequestMessage requ
});

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

promise.Reject(null, ex.Message, ex);
promise.Reject(ex);
}

private void RejectFileNotFound(IPromise promise, String filepath)
Expand Down
Loading

0 comments on commit 8c121e8

Please sign in to comment.