Skip to content

Commit

Permalink
Fixed Microsoft.ReactNative.IntegrationTests and Mso.UnitTests to run…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
jonthysell authored Apr 6, 2024
1 parent 55418db commit 5c71eac
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .ado/jobs/universal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@
BuildConfiguration: Debug
BuildPlatform: x64
UseFabric: true
- Name: X86ReleaseFabric # Specifically built so binskim / tests get run on fabric
BuildConfiguration: Release
BuildPlatform: x86
UseFabric: true
- BuildEnvironment: SecurePullRequest
Matrix:
- Name: X64DebugFabric
BuildConfiguration: Debug
BuildPlatform: x64
UseFabric: true
- Name: X86ReleaseFabric # Specifically built so binskim / tests get run on fabric
BuildConfiguration: Release
BuildPlatform: x86
UseFabric: true
- BuildEnvironment: Continuous
Matrix:
- Name: X64Debug
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix Microsoft.ReactNative.IntegrationTests to run with Fabric",
"packageName": "react-native-windows",
"email": "jthysell@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(ReactNativeWindowsDir)PropertySheets\React.Cpp.props" />
<!-- Because the test exe is unpackaged, it needs the self contained WinAppSDK stuff below when testing against fabric -->
<PropertyGroup Label="FromWinUI3_VSIX" Condition="'$(UseWinUI3)'=='true'">
<AppContainerApplication>false</AppContainerApplication>
<ApplicationType>Windows Store</ApplicationType>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
<WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<WindowsPackageType>None</WindowsPackageType>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -54,6 +63,9 @@
<Import Project="PropertySheet.props" />
-->
</ImportGroup>
<ImportGroup Condition=" '$(UseFabric)' == 'true' AND '$(UseWinUI3)' == 'true' ">
<Import Project="..\PropertySheets\WinUI.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
Expand Down Expand Up @@ -167,6 +179,9 @@
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="$(CppWinRTVersion)" PrivateAssets="all" />
<PackageReference Include="$(V8PackageName)" Version="$(V8Version)" Condition="'$(UseV8)' == 'true'" />
</ItemGroup>
<ItemGroup Condition=" '$(UseFabric)' == 'true' AND '$(UseWinUI3)' == 'true' ">
<PackageReference Include="$(WinUIPackageName)" Version="$(WinUIPackageVersion)" Condition="'$(OverrideWinUIPackage)'!='true'" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="TestBundle.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@
#include "pch.h"

#include <winrt/Microsoft.ReactNative.h>

#ifdef USE_WINUI3
#include <winrt/Microsoft.UI.Dispatching.h>
#else
#include <winrt/Windows.System.h>
#endif

using namespace winrt;
using namespace Microsoft::ReactNative;

#ifdef USE_WINUI3
using namespace Microsoft::UI::Dispatching;
#else
using namespace Windows::System;
#endif

namespace ReactNativeIntegrationTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace ReactNativeIntegrationTests {

using namespace winrt;
using namespace Windows::System;

// Work around crash in DeviceInfo when running outside of XAML environment
REACT_MODULE(DeviceInfo)
Expand Down Expand Up @@ -51,7 +50,11 @@ TestReactNativeHostHolder::TestReactNativeHostHolder(
Mso::Functor<void(winrt::Microsoft::ReactNative::ReactNativeHost const &)> &&hostInitializer,
Options &&options) noexcept {
m_host = winrt::Microsoft::ReactNative::ReactNativeHost{};
m_queueController = DispatcherQueueController::CreateOnDedicatedThread();
#ifdef USE_WINUI3
m_queueController = winrt::Microsoft::UI::Dispatching::DispatcherQueueController::CreateOnDedicatedThread();
#else
m_queueController = winrt::Windows::System::DispatcherQueueController::CreateOnDedicatedThread();
#endif
m_queueController.DispatcherQueue().TryEnqueue([this,
jsBundle = std::wstring{jsBundle},
hostInitializer = std::move(hostInitializer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@

#include <functional/functor.h>
#include <winrt/Microsoft.ReactNative.h>
#include <winrt/Windows.System.h>
#include <string_view>

#ifdef USE_WINUI3
#include <winrt/Microsoft.UI.Dispatching.h>
#else
#include <winrt/Windows.System.h>
#endif

namespace ReactNativeIntegrationTests {

struct TestReactNativeHostHolder {
Expand All @@ -25,7 +30,11 @@ struct TestReactNativeHostHolder {

private:
winrt::Microsoft::ReactNative::ReactNativeHost m_host{nullptr};
#ifdef USE_WINUI3
winrt::Microsoft::UI::Dispatching::DispatcherQueueController m_queueController{nullptr};
#else
winrt::Windows::System::DispatcherQueueController m_queueController{nullptr};
#endif
};

} // namespace ReactNativeIntegrationTests
16 changes: 16 additions & 0 deletions vnext/Mso.UnitTests/Mso.UnitTests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(ReactNativeWindowsDir)PropertySheets\React.Cpp.props" />
<!-- Because the test exe is unpackaged, it needs the self contained WinAppSDK stuff below when testing against fabric -->
<PropertyGroup Label="FromWinUI3_VSIX" Condition="'$(UseWinUI3)'=='true'">
<AppContainerApplication>false</AppContainerApplication>
<ApplicationType>Windows Store</ApplicationType>
<ApplicationTypeRevision>10.0</ApplicationTypeRevision>
<WindowsTargetPlatformVersion>10.0.22000.0</WindowsTargetPlatformVersion>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<WindowsPackageType>None</WindowsPackageType>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand Down Expand Up @@ -53,6 +62,9 @@
<ImportGroup Label="PropertySheets">
<Import Project="PropertySheet.props" />
</ImportGroup>
<ImportGroup Condition=" '$(UseFabric)' == 'true' AND '$(UseWinUI3)' == 'true' ">
<Import Project="..\PropertySheets\WinUI.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<ClCompile>
Expand All @@ -62,6 +74,7 @@
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<PreprocessorDefinitions>_CONSOLE;MS_TARGET_WINDOWS;MSO_MOTIFCPP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level4</WarningLevel>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await %(AdditionalOptions) /bigobj</AdditionalOptions>
<ConformanceMode>true</ConformanceMode>
<CallingConvention>Cdecl</CallingConvention>
Expand Down Expand Up @@ -147,5 +160,8 @@
<PackageReference Include="Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn" Version="1.8.1" />
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="$(CppWinRTVersion)" PrivateAssets="all" />
</ItemGroup>
<ItemGroup Condition=" '$(UseFabric)' == 'true' AND '$(UseWinUI3)' == 'true' ">
<PackageReference Include="$(WinUIPackageName)" Version="$(WinUIPackageVersion)" Condition="'$(OverrideWinUIPackage)'!='true'" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

0 comments on commit 5c71eac

Please # to comment.