-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from unoplatform/dev/dr/hrTests
feat: Add ability to test hot-reload scenario
- Loading branch information
Showing
85 changed files
with
5,238 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project ToolsVersion="15.0"> | ||
<Import Project="..\Directory.Build.props" /> | ||
|
||
<PropertyGroup> | ||
<DefineConstants>$(DefineConstants);IS_UNO_RUNTIMETEST_PROJECT</DefineConstants> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<AssemblyAttribute Include="Uno.UI.RuntimeTests.Engine.RuntimeTestsSourceProjectAttribute"> | ||
<_Parameter1>$(MSBuildProjectFullPath)</_Parameter1> | ||
</AssemblyAttribute> | ||
|
||
<AssemblyAttribute Include="Uno.UI.RuntimeTests.Engine.RuntimeTestDevServerAttribute" Condition="'$(PkgUno_UI_DevServer)' != ''"> | ||
<_Parameter1>$([System.IO.Path]::GetFileName(`$(PkgUno_UI_DevServer)`)) </_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="Uno.UI.RuntimeTests.Engine.RuntimeTestDevServerAttribute" Condition="'$(PkgUno_WinUI_DevServer)' != ''"> | ||
<_Parameter1>$([System.IO.Path]::GetFileName(`$(PkgUno_WinUI_DevServer)`)) </_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project ToolsVersion="15.0"> | ||
<Import Project="..\Directory.Build.targets" /> | ||
|
||
<PropertyGroup> | ||
<DefineConstants Condition="'$(PkgUno_UI_DevServer)' != '' OR '$(PkgUno_WinUI_DevServer)' != ''">$(DefineConstants);HAS_UNO_DEVSERVER</DefineConstants> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Uno.UI.RuntimeTests.Engine; | ||
|
||
[TestClass] | ||
public class FilterTests | ||
{ | ||
[TestMethod] | ||
[DataRow("abc & ghi", "abc", false)] | ||
[DataRow("abc & ghi", "ghi", false)] | ||
[DataRow("abc & ghi", "abc.ghi", true)] | ||
[DataRow("abc & (ghi)", "abc", false)] | ||
[DataRow("abc & (ghi)", "ghi", false)] | ||
[DataRow("abc & (ghi)", "abc.ghi", true)] | ||
[DataRow("a.b.c & ghi", "a.b", false)] | ||
[DataRow("a.b.c & ghi", "a.b.c.def.ghi", true)] | ||
[DataRow("a.b.c & (ghi)", "a.b", false)] | ||
[DataRow("a.b.c & (ghi)", "a.b.c.def.ghi", true)] | ||
[DataRow("abc & g.h.i", "g.h", false)] | ||
[DataRow("abc & g.h.i", "abc.def.g.h.i", true)] | ||
|
||
[DataRow("abc | ghi", "abc", true)] | ||
[DataRow("abc | ghi", "ghi", true)] | ||
[DataRow("abc | ghi", "abc.ghi", true)] | ||
[DataRow("abc | (ghi)", "abc", true)] | ||
[DataRow("abc | (ghi)", "ghi", true)] | ||
[DataRow("abc | (ghi)", "abc.ghi", true)] | ||
[DataRow("a.b.c | ghi", "a.b", false)] | ||
[DataRow("a.b.c | ghi", "a.b.c", true)] | ||
[DataRow("a.b.c | ghi", "a.b.c.def.ghi", true)] | ||
[DataRow("a.b.c | (ghi)", "a.b", false)] | ||
[DataRow("a.b.c | (ghi)", "a.b.c", true)] | ||
[DataRow("a.b.c | (ghi)", "a.b.c.def.ghi", true)] | ||
[DataRow("abc | g.h.i", "g.h", false)] | ||
[DataRow("abc | g.h.i", "g.h.i", true)] | ||
[DataRow("abc | g.h.i", "abc.def.g.h.i", true)] | ||
|
||
[DataRow("abc ; ghi", "abc", true)] | ||
[DataRow("abc ; ghi", "ghi", true)] | ||
[DataRow("abc ; ghi", "abc.ghi", true)] | ||
[DataRow("abc ; (ghi)", "abc", true)] | ||
[DataRow("abc ; (ghi)", "ghi", true)] | ||
[DataRow("abc ; (ghi)", "abc.ghi", true)] | ||
[DataRow("a.b.c ; ghi", "a.b", false)] | ||
[DataRow("a.b.c ; ghi", "a.b.c", true)] | ||
[DataRow("a.b.c ; ghi", "a.b.c.def.ghi", true)] | ||
[DataRow("a.b.c ; (ghi)", "a.b", false)] | ||
[DataRow("a.b.c ; (ghi)", "a.b.c", true)] | ||
[DataRow("a.b.c ; (ghi)", "a.b.c.def.ghi", true)] | ||
[DataRow("abc ; g.h.i", "g.h", false)] | ||
[DataRow("abc ; g.h.i", "g.h.i", true)] | ||
[DataRow("abc ; g.h.i", "abc.def.g.h.i", true)] | ||
public void When_ParseAndMatch(string filter, string method, bool expectedResult) | ||
{ | ||
UnitTestFilter sut = filter; | ||
var result = sut.IsMatch(method); | ||
|
||
Assert.AreEqual(expectedResult, result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma warning disable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Uno.UI.RuntimeTests.Engine; | ||
|
||
public class HotReloadTest_SimpleSubject | ||
{ | ||
public string Value => "42"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Uno.Extensions; | ||
|
||
#if HAS_UNO_WINUI || WINDOWS_WINUI | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
#else | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
#endif | ||
|
||
namespace Uno.UI.RuntimeTests.Engine; | ||
|
||
[TestClass] | ||
public class HotReloadSanity | ||
{ | ||
[TestMethod] | ||
public void Is_HotReload_Supported() | ||
{ | ||
#if __SKIA__ // DevServer should be referenced also in release | ||
Assert.IsTrue(HotReloadHelper.IsSupported); | ||
#else | ||
Assert.IsFalse(HotReloadHelper.IsSupported); | ||
#endif | ||
} | ||
} | ||
|
||
[TestClass] | ||
[RunsInSecondaryApp] | ||
public class HotReloadTests | ||
{ | ||
[TestMethod] | ||
#if !__SKIA__ | ||
[Ignore("This tests assume directs access to the file system which not possible on this platform.")] | ||
#endif | ||
public async Task Is_SourcesEditable(CancellationToken ct) | ||
{ | ||
var sutPath = "../../shared/HotReloadTests_Subject.xaml"; | ||
var dir = Path.GetDirectoryName(typeof(HotReloadHelper).Assembly.GetCustomAttribute<RuntimeTestsSourceProjectAttribute>()!.ProjectFullPath)!; | ||
var file = Path.Combine(dir, sutPath); | ||
|
||
Assert.IsTrue(File.Exists(file)); | ||
Assert.IsTrue(File.ReadAllText(file).Contains("Original text")); | ||
|
||
await using var _ = await HotReloadHelper.UpdateSourceFile(sutPath, "Original text", "Updated text from Can_Edit_File", waitForMetadataUpdate: false, ct); | ||
|
||
await TestHelper.WaitFor(() => File.ReadAllText(file).Contains("Updated text from Can_Edit_File"), ct); | ||
|
||
Assert.IsTrue(File.ReadAllText(file).Contains("Updated text from Can_Edit_File")); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Is_CodeHotReload_Enabled(CancellationToken ct) | ||
{ | ||
if (!HotReloadHelper.IsSupported) | ||
{ | ||
Assert.Inconclusive("Hot reload testing is not supported on this platform."); | ||
} | ||
|
||
var sut = new HotReloadTest_SimpleSubject(); | ||
|
||
Debug.Assert(sut.Value == "42"); | ||
|
||
await using var _ = await HotReloadHelper.UpdateSourceFile("../../shared/HotReloadTest_SimpleSubject.cs", "42", "43", ct); | ||
|
||
Debug.Assert(sut.Value == "43"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Is_UIHotReload_Enabled(CancellationToken ct) | ||
{ | ||
if (!HotReloadHelper.IsSupported) | ||
{ | ||
Assert.Inconclusive("Hot reload testing is not supported on this platform."); | ||
} | ||
|
||
await UIHelper.Load(new HotReloadTests_Subject(), ct); | ||
|
||
Assert.AreEqual("Original text", UIHelper.GetChild<TextBlock>().Text); | ||
|
||
await using var _ = await HotReloadHelper.UpdateSourceFile<HotReloadTests_Subject>("Original text", "Updated text", ct); | ||
|
||
await AsyncAssert.AreEqual("Updated text", () => UIHelper.GetChild<TextBlock>().Text, ct); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Page | ||
x:Class="Uno.UI.RuntimeTests.Engine.HotReloadTests_Subject" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:Uno.UI.RuntimeTests.Engine" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid> | ||
<TextBlock Text="Original text" /> | ||
</Grid> | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
| ||
#if HAS_UNO_WINUI || WINDOWS_WINUI | ||
using Microsoft.UI.Xaml.Controls; | ||
#else | ||
using Windows.UI.Xaml.Controls; | ||
#endif | ||
|
||
namespace Uno.UI.RuntimeTests.Engine | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class HotReloadTests_Subject : Page | ||
{ | ||
public HotReloadTests_Subject() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#pragma warning disable | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Uno.UI.RuntimeTests.Internal.Helpers; | ||
|
||
namespace Uno.UI.RuntimeTests.Engine; | ||
|
||
[TestClass] | ||
public class SecondaryAppSanity | ||
{ | ||
[TestMethod] | ||
public void Is_SecondaryApp_Supported() | ||
{ | ||
#if __SKIA__ | ||
Assert.IsTrue(SecondaryApp.IsSupported); | ||
#else | ||
Assert.IsFalse(SecondaryApp.IsSupported); | ||
#endif | ||
} | ||
} | ||
|
||
[TestClass] | ||
[RunsInSecondaryApp(ignoreIfNotSupported: true)] | ||
public class SecondaryAppTests | ||
{ | ||
[TestMethod] | ||
public void Is_From_A_Secondary_App() | ||
{ | ||
Assert.IsTrue(Environment.GetEnvironmentVariable("UNO_RUNTIME_TESTS_IS_SECONDARY_APP") is "true"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Is_DevServer_Connected() | ||
{ | ||
#if HAS_UNO_DEVSERVER | ||
Assert.IsNotNull(Uno.UI.RemoteControl.RemoteControlClient.Instance); | ||
|
||
var connected = Uno.UI.RemoteControl.RemoteControlClient.Instance.WaitForConnection(CancellationToken.None); | ||
var timeout = Task.Delay(500); | ||
|
||
Assert.AreEqual(connected, await Task.WhenAny(connected, timeout)); | ||
#else | ||
Assert.Inconclusive("Dev server in not supported on this platform."); | ||
#endif | ||
} | ||
|
||
#if DEBUG | ||
[TestMethod] | ||
public async Task No_Longer_Sane() // expected to fail | ||
{ | ||
await Task.Delay(2000); | ||
|
||
throw new Exception("Great works require a touch of insanity."); | ||
} | ||
|
||
[TestMethod, Ignore] | ||
public void Is_An_Illusion() // expected to be ignored | ||
{ | ||
} | ||
#endif | ||
} | ||
|
||
[TestClass] | ||
public class NotSecondaryAppTests | ||
{ | ||
[TestMethod] | ||
public void Is_From_A_Secondary_App() | ||
{ | ||
Assert.IsFalse(Environment.GetEnvironmentVariable("UNO_RUNTIME_TESTS_IS_SECONDARY_APP") is "true"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.