Skip to content

Commit 5c71eac

Browse files
authored
Fixed Microsoft.ReactNative.IntegrationTests and Mso.UnitTests to run with Fabric (#12924)
## Description This PR makes Microsoft.ReactNative.IntegrationTests aware of Fabric requirements to use the WinAppSDK `DispatchQueueController`. This PR also fixes both that project and Mso.UnitTests to be able to consume self-contained WinAppSDK so they can run (the tests had code but were technically never exercising it). Finally this PR also enables a fabric config in PR to make sure we catch test failures like this in the future. ### Type of Change - Bug fix (non-breaking change which fixes an issue) ### Why See above. Resolves #12923 ### What See above. ## Screenshots N/A ## Testing Ran Microsoft.ReactNative.Integration tests locally. ## Changelog Should this change be included in the release notes: _yes_ Fixed Microsoft.ReactNative.IntegrationTests and Mso.UnitTests to run with Fabric
1 parent 55418db commit 5c71eac

File tree

7 files changed

+71
-3
lines changed

7 files changed

+71
-3
lines changed

.ado/jobs/universal.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@
3030
BuildConfiguration: Debug
3131
BuildPlatform: x64
3232
UseFabric: true
33+
- Name: X86ReleaseFabric # Specifically built so binskim / tests get run on fabric
34+
BuildConfiguration: Release
35+
BuildPlatform: x86
36+
UseFabric: true
3337
- BuildEnvironment: SecurePullRequest
3438
Matrix:
3539
- Name: X64DebugFabric
3640
BuildConfiguration: Debug
3741
BuildPlatform: x64
3842
UseFabric: true
43+
- Name: X86ReleaseFabric # Specifically built so binskim / tests get run on fabric
44+
BuildConfiguration: Release
45+
BuildPlatform: x86
46+
UseFabric: true
3947
- BuildEnvironment: Continuous
4048
Matrix:
4149
- Name: X64Debug
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Fix Microsoft.ReactNative.IntegrationTests to run with Fabric",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative.IntegrationTests/Microsoft.ReactNative.IntegrationTests.vcxproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
</PropertyGroup>
1111
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
1212
<Import Project="$(ReactNativeWindowsDir)PropertySheets\React.Cpp.props" />
13+
<!-- Because the test exe is unpackaged, it needs the self contained WinAppSDK stuff below when testing against fabric -->
14+
<PropertyGroup Label="FromWinUI3_VSIX" Condition="'$(UseWinUI3)'=='true'">
15+
<AppContainerApplication>false</AppContainerApplication>
16+
<ApplicationType>Windows Store</ApplicationType>
17+
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
18+
<WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion>
19+
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
20+
<WindowsPackageType>None</WindowsPackageType>
21+
</PropertyGroup>
1322
<ItemGroup Label="ProjectConfigurations">
1423
<ProjectConfiguration Include="Debug|Win32">
1524
<Configuration>Debug</Configuration>
@@ -54,6 +63,9 @@
5463
<Import Project="PropertySheet.props" />
5564
-->
5665
</ImportGroup>
66+
<ImportGroup Condition=" '$(UseFabric)' == 'true' AND '$(UseWinUI3)' == 'true' ">
67+
<Import Project="..\PropertySheets\WinUI.props" />
68+
</ImportGroup>
5769
<PropertyGroup Label="UserMacros" />
5870
<ItemDefinitionGroup>
5971
<ClCompile>
@@ -167,6 +179,9 @@
167179
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="$(CppWinRTVersion)" PrivateAssets="all" />
168180
<PackageReference Include="$(V8PackageName)" Version="$(V8Version)" Condition="'$(UseV8)' == 'true'" />
169181
</ItemGroup>
182+
<ItemGroup Condition=" '$(UseFabric)' == 'true' AND '$(UseWinUI3)' == 'true' ">
183+
<PackageReference Include="$(WinUIPackageName)" Version="$(WinUIPackageVersion)" Condition="'$(OverrideWinUIPackage)'!='true'" />
184+
</ItemGroup>
170185
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
171186
<Import Project="TestBundle.targets" />
172187
</Project>

vnext/Microsoft.ReactNative.IntegrationTests/ReactInstanceSettingsTests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
#include "pch.h"
55

66
#include <winrt/Microsoft.ReactNative.h>
7+
8+
#ifdef USE_WINUI3
9+
#include <winrt/Microsoft.UI.Dispatching.h>
10+
#else
711
#include <winrt/Windows.System.h>
12+
#endif
813

914
using namespace winrt;
1015
using namespace Microsoft::ReactNative;
16+
17+
#ifdef USE_WINUI3
18+
using namespace Microsoft::UI::Dispatching;
19+
#else
1120
using namespace Windows::System;
21+
#endif
1222

1323
namespace ReactNativeIntegrationTests {
1424

vnext/Microsoft.ReactNative.IntegrationTests/TestReactNativeHostHolder.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace ReactNativeIntegrationTests {
1010

1111
using namespace winrt;
12-
using namespace Windows::System;
1312

1413
// Work around crash in DeviceInfo when running outside of XAML environment
1514
REACT_MODULE(DeviceInfo)
@@ -51,7 +50,11 @@ TestReactNativeHostHolder::TestReactNativeHostHolder(
5150
Mso::Functor<void(winrt::Microsoft::ReactNative::ReactNativeHost const &)> &&hostInitializer,
5251
Options &&options) noexcept {
5352
m_host = winrt::Microsoft::ReactNative::ReactNativeHost{};
54-
m_queueController = DispatcherQueueController::CreateOnDedicatedThread();
53+
#ifdef USE_WINUI3
54+
m_queueController = winrt::Microsoft::UI::Dispatching::DispatcherQueueController::CreateOnDedicatedThread();
55+
#else
56+
m_queueController = winrt::Windows::System::DispatcherQueueController::CreateOnDedicatedThread();
57+
#endif
5558
m_queueController.DispatcherQueue().TryEnqueue([this,
5659
jsBundle = std::wstring{jsBundle},
5760
hostInitializer = std::move(hostInitializer),

vnext/Microsoft.ReactNative.IntegrationTests/TestReactNativeHostHolder.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55

66
#include <functional/functor.h>
77
#include <winrt/Microsoft.ReactNative.h>
8-
#include <winrt/Windows.System.h>
98
#include <string_view>
109

10+
#ifdef USE_WINUI3
11+
#include <winrt/Microsoft.UI.Dispatching.h>
12+
#else
13+
#include <winrt/Windows.System.h>
14+
#endif
15+
1116
namespace ReactNativeIntegrationTests {
1217

1318
struct TestReactNativeHostHolder {
@@ -25,7 +30,11 @@ struct TestReactNativeHostHolder {
2530

2631
private:
2732
winrt::Microsoft::ReactNative::ReactNativeHost m_host{nullptr};
33+
#ifdef USE_WINUI3
34+
winrt::Microsoft::UI::Dispatching::DispatcherQueueController m_queueController{nullptr};
35+
#else
2836
winrt::Windows::System::DispatcherQueueController m_queueController{nullptr};
37+
#endif
2938
};
3039

3140
} // namespace ReactNativeIntegrationTests

vnext/Mso.UnitTests/Mso.UnitTests.vcxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
</PropertyGroup>
1313
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
1414
<Import Project="$(ReactNativeWindowsDir)PropertySheets\React.Cpp.props" />
15+
<!-- Because the test exe is unpackaged, it needs the self contained WinAppSDK stuff below when testing against fabric -->
16+
<PropertyGroup Label="FromWinUI3_VSIX" Condition="'$(UseWinUI3)'=='true'">
17+
<AppContainerApplication>false</AppContainerApplication>
18+
<ApplicationType>Windows Store</ApplicationType>
19+
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
20+
<WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion>
21+
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
22+
<WindowsPackageType>None</WindowsPackageType>
23+
</PropertyGroup>
1524
<ItemGroup Label="ProjectConfigurations">
1625
<ProjectConfiguration Include="Debug|Win32">
1726
<Configuration>Debug</Configuration>
@@ -53,6 +62,9 @@
5362
<ImportGroup Label="PropertySheets">
5463
<Import Project="PropertySheet.props" />
5564
</ImportGroup>
65+
<ImportGroup Condition=" '$(UseFabric)' == 'true' AND '$(UseWinUI3)' == 'true' ">
66+
<Import Project="..\PropertySheets\WinUI.props" />
67+
</ImportGroup>
5668
<PropertyGroup Label="UserMacros" />
5769
<ItemDefinitionGroup>
5870
<ClCompile>
@@ -62,6 +74,7 @@
6274
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
6375
<PreprocessorDefinitions>_CONSOLE;MS_TARGET_WINDOWS;MSO_MOTIFCPP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
6476
<WarningLevel>Level4</WarningLevel>
77+
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
6578
<AdditionalOptions>/await %(AdditionalOptions) /bigobj</AdditionalOptions>
6679
<ConformanceMode>true</ConformanceMode>
6780
<CallingConvention>Cdecl</CallingConvention>
@@ -147,5 +160,8 @@
147160
<PackageReference Include="Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn" Version="1.8.1" />
148161
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="$(CppWinRTVersion)" PrivateAssets="all" />
149162
</ItemGroup>
163+
<ItemGroup Condition=" '$(UseFabric)' == 'true' AND '$(UseWinUI3)' == 'true' ">
164+
<PackageReference Include="$(WinUIPackageName)" Version="$(WinUIPackageVersion)" Condition="'$(OverrideWinUIPackage)'!='true'" />
165+
</ItemGroup>
150166
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
151167
</Project>

0 commit comments

Comments
 (0)