aspnetcore/src/Shared/E2ETesting/E2ETesting.targets

122 lines
5.3 KiB
XML

<Project>
<!-- Version of this SDK is set in global.json -->
<Sdk Name="Yarn.MSBuild" />
<!-- Ensuring that everything is ready before build -->
<Target Name="EnsureNodeJSRestored" Condition="'$(SeleniumE2ETestsSupported)' == 'true'" BeforeTargets="Build">
<Message Text="Running yarn install on $(MSBuildProjectFile)" Importance="High" />
<Message Condition="'$(EnforcePrerequisites)' == ''"
Importance="High"
Text="Prerequisites were not enforced at build time. Running Yarn or the E2E tests might fail as a result. Check /src/Shared/E2ETesting/Readme.md for instructions." />
<Yarn Command="install" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="_YarnExitCode"/>
</Yarn>
<Yarn Command="install" Condition="'$(_YarnExitCode)' != '0'">
<Output TaskParameter="ExitCode" PropertyName="_YarnExitCode"/>
</Yarn>
</Target>
<Target
Name="WarnSeleniumNotSupported"
BeforeTargets="Build"
Condition="'$(SeleniumE2ETestsSupported)' == ''">
<Message Importance="High" Text="Selenium tests are not supported for OS '$(OS)' and architecture '$(TargetArchitecture)'." />
</Target>
<!-- Running prerequisites -->
<Target Name="EnsurePrerequisites" Condition="'$(EnforcePrerequisites)' == 'true'" BeforeTargets="EnsureNodeJSRestored">
<PropertyGroup>
<_PackageJson>$(MSBuildProjectDirectory)\package.json</_PackageJson>
</PropertyGroup>
<!-- JAVA -->
<Message Importance="High" Text="Ensuring JAVA is available" />
<Exec Command="java -version" />
<Message Importance="High" Text="JAVA is available on the PATH" />
<!-- package.json -->
<Error Condition="!Exists('$(_PackageJson)')" Text="Can't find $(_PackageJson)" />
<ReadLinesFromFile File="$(_PackageJson)">
<Output TaskParameter="Lines" ItemName="_PackageJsonLines" />
</ReadLinesFromFile>
<PropertyGroup>
<_PackageJsonLinesContent>@(_PackageJsonLines)</_PackageJsonLinesContent>
<_PackageJsonSeleniumPackage>&quot;selenium-standalone&quot;: &quot;^6.15.4&quot;</_PackageJsonSeleniumPackage>
</PropertyGroup>
<Error
Condition="!$(_PackageJsonLinesContent.Contains ('$(_PackageJsonSeleniumPackage)'))"
Text="Can't find dependency $(_PackageJsonSeleniumPackage) in '$(_PackageJson)'" />
</Target>
<!-- Resolve content roots at build time -->
<Target Name="_ResolveTestProjectReferences" DependsOnTargets="ResolveReferences">
<PropertyGroup>
<_DefaultProjectRoot>$([System.IO.Path]::GetFullPath($(_DefaultProjectFilter)))</_DefaultProjectRoot>
</PropertyGroup>
<ItemGroup>
<_ContentRootProjectReferencesUnfiltered
Include="@(ReferencePath)"
Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference'" />
<_ContentRootProjectReferencesFilter
Include="@(_ContentRootProjectReferencesUnfiltered->StartsWith('$(_DefaultProjectRoot)'))" />
<_ContentRootProjectReferences
Include="@(_ContentRootProjectReferencesFilter)"
Condition="'%(Identity)' == 'True'" />
</ItemGroup>
</Target>
<Target Name="_AddTestProjectMetadataAttributes" BeforeTargets="BeforeCompile" DependsOnTargets="_ResolveTestProjectReferences">
<ItemGroup>
<_ContentRootMetadata
Condition="'%(_ContentRootProjectReferences.Identity)' != ''"
Include="%(_ContentRootProjectReferences.Identity)"
AssemblyName="%(_ContentRootProjectReferences.FusionName)"
ContentRootPath="$([System.IO.Path]::GetDirectoryName(%(_ContentRootProjectReferences.MSBuildSourceProjectFile)))"
ContentRootTest="$([System.IO.Path]::GetFileName(%(_ContentRootProjectReferences.MSBuildSourceProjectFile)))"
Priority="0" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute
Condition=" '%(_ContentRootMetadata.Identity)' != '' "
Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>TestAssemblyApplication[%(_ContentRootMetadata.AssemblyName)]</_Parameter1>
<_Parameter2>%(_ContentRootMetadata.ContentRootPath)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Target>
<Target Name="_AddSeleniumSupportedMetadataAttribute" BeforeTargets="BeforeCompile">
<PropertyGroup>
<_SeleniumE2ETestsSupportedAttributeValue>false</_SeleniumE2ETestsSupportedAttributeValue>
<_SeleniumE2ETestsSupportedAttributeValue Condition="'$(SeleniumE2ETestsSupported)' == 'true'">true</_SeleniumE2ETestsSupportedAttributeValue>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute
Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>Microsoft.AspNetCore.Testing.Selenium.Supported</_Parameter1>
<_Parameter2>$(_SeleniumE2ETestsSupportedAttributeValue)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Target>
<Target Name="_AddProcessTrackingMetadataAttribute" BeforeTargets="BeforeCompile">
<MakeDir Directories="$(SeleniumProcessTrackingFolder)" />
<ItemGroup>
<AssemblyAttribute
Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>Microsoft.AspNetCore.Testing.Selenium.ProcessTracking</_Parameter1>
<_Parameter2>$(SeleniumProcessTrackingFolder)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Target>
</Project>