-
Notifications
You must be signed in to change notification settings - Fork 337
/
Test.ps1
177 lines (146 loc) · 6.98 KB
/
Test.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
param (
[string]$Platform = "x64",
[string]$Configuration = "debug",
[switch]$IsAzurePipelineBuild = $false,
[switch]$RunUITests = $false,
[switch]$Help = $false
)
$StartTime = Get-Date
if ($Help) {
Write-Host @"
Copyright (c) Microsoft Corporation.
Licensed under the MIT License.
Syntax:
Test.cmd [options]
Description:
Runs Dev Home tests.
Options:
-Platform <platform>
Only build the selected platform(s)
Example: -Platform x64
Example: -Platform "x86,x64,arm64"
-Configuration <configuration>
Only build the selected configuration(s)
Example: -Configuration release
Example: -Configuration "debug,release"
-Help
Display this usage message.
"@
Exit
}
$env:Build_SourcesDirectory = (Split-Path $MyInvocation.MyCommand.Path)
$env:Build_Platform = $Platform.ToLower()
$env:Build_Configuration = $Configuration.ToLower()
$vstestPath = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -find '**\TestPlatform\vstest.console.exe'
$ErrorActionPreference = "Stop"
$isInstalled = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.DisplayName -like "*Windows Application Driver*" }
if (-not $IsAzurePipelineBuild) {
if ($isInstalled) {
Write-Host "WinAppDriver is already installed on this computer."
Start-Process -FilePath "C:\Program Files\Windows Application Driver\WinAppDriver.exe"
} else {
Write-Host "WinAppDriver will be installed in the background."
$url = "https://github.com/microsoft/WinAppDriver/releases/download/v1.2.99/WindowsApplicationDriver-1.2.99-win-x64.exe"
$outpath = Join-Path $env:Build_SourcesDirectory "temp"
if (-not (Test-Path -Path $outpath)) {
New-Item -ItemType Directory -Path $outpath | Out-Null
}
Invoke-WebRequest -Uri $url -OutFile (Join-Path $outpath "WinAppDriverx64.exe")
Start-Process -Wait -FilePath (Join-Path $env:Build_SourcesDirectory "temp\WinAppDriverx64.exe") -ArgumentList "/S" -PassThru
}
}
function ShutDownTests {
if (-not $IsAzurePipelineBuild) {
Stop-Process -Name "WinAppDriver" -ErrorAction SilentlyContinue
}
$TotalTime = (Get-Date) - $StartTime
$TotalMinutes = [math]::Floor($TotalTime.TotalMinutes)
$TotalSeconds = [math]::Ceiling($TotalTime.TotalSeconds)
Write-Host @"
Total Running Time:
$TotalMinutes minutes and $TotalSeconds seconds
"@ -ForegroundColor Cyan
}
if (-not (Test-Path -Path "AppxPackages")) {
Write-Host "Nothing to test. Ensure you have built via the command line before running tests. Exiting." -ForegroundColor Yellow
Exit 1
}
try {
foreach ($platform in $env:Build_Platform.Split(",")) {
foreach ($configuration in $env:Build_Configuration.Split(",")) {
# TODO: UI tests are currently disabled in the pipeline until we can run tests as user
if ($RunUITests) {
$DevHomePackage = Get-AppPackage "Microsoft.DevHome" -ErrorAction SilentlyContinue
if ($DevHomePackage) {
Write-Host "Uninstalling old Dev Home"
Remove-AppPackage -Package $DevHomePackage.PackageFullName
}
Write-Host "Installing Dev Home"
Add-AppPackage (Join-Path "AppxPackages" "$configuration\DevHome-$platform.msix")
if ($true) {
# Start/stop the app once so that WinAppDriver doesn't time out during first time setup
# and wait 60 seconds to give plenty of time
Start-Process "Shell:AppsFolder\Microsoft.Windows.DevHome.Dev_8wekyb3d8bbwe!App"
Start-Sleep 60
Stop-Process -Name "DevHome"
}
}
$vstestArgs = @(
"/Platform:$platform",
"/Logger:trx;LogFileName=DevHome.Test-$platform-$configuration.trx",
"test\bin\$platform\$configuration\net8.0-windows10.0.22621.0\DevHome.Test.dll"
)
$winAppTestArgs = @(
"/Platform:$platform",
"/Logger:trx;LogFileName=DevHome.UITest-$platform-$configuration.trx",
"/Settings:uitest\Test.runsettings",
"uitest\bin\$platform\$configuration\net8.0-windows10.0.22621.0\DevHome.UITest.dll"
)
& $vstestPath $vstestArgs
# TODO: UI tests are currently disabled in the pipeline until we can run tests as user
if ($RunUITests) {
& $vstestPath $winAppTestArgs
}
foreach ($toolPath in (Get-ChildItem "tools")) {
$tool = $toolPath.Name
$vstestArgs = @(
"/Platform:$platform",
"/Logger:trx;LogFileName=$tool.Test-$platform-$configuration.trx",
"tools\$tool\*UnitTest\bin\$platform\$configuration\net8.0-windows10.0.22621.0\*.UnitTest.dll"
)
$winAppTestArgs = @(
"/Platform:$platform",
"/Logger:trx;LogFileName=$tool.UITest-$platform-$configuration.trx",
"/Settings:uitest\Test.runsettings",
"tools\$tool\*UITest\bin\$platform\$configuration\net8.0-windows10.0.22621.0\*.UITest.dll"
)
if (Get-ChildItem "tools\$tool\*UnitTest\bin\$platform\$configuration\net8.0-windows10.0.22621.0\*.UnitTest.dll") {
& $vstestPath $vstestArgs
}
# TODO: UI tests are currently disabled in the pipeline until signing is solved
if ($RunUITests) {
& $vstestPath $winAppTestArgs
}
}
$vstestArgs = @(
"/Platform:$platform",
"/Logger:trx;LogFileName=FileExplorerGitIntegration.UnitTest-$platform-$configuration.trx",
"extensions\GitExtension\FileExplorerGitIntegration.UnitTest\bin\$platform\$configuration\net8.0-windows10.0.22621.0\FileExplorerGitIntegration.UnitTest.dll"
)
& $vstestPath $vstestArgs
$vstestArgs = @(
"/Platform:$platform",
"/Logger:trx;LogFileName=DevHome.FileExplorerSourceControlIntegrationUnitTest.UnitTest-$platform-$configuration.trx",
"tools\Customization\DevHome.FileExplorerSourceControlIntegrationUnitTest\bin\$platform\$configuration\net8.0-windows10.0.22621.0\DevHome.FileExplorerSourceControlIntegrationUnitTest.dll"
)
& $vstestPath $vstestArgs
}
}
} catch {
$formatString = "`n{0}`n`n{1}`n`n"
$fields = $_, $_.ScriptStackTrace
Write-Host ($formatString -f $fields) -ForegroundColor Red
ShutDownTests
Exit 1
}
ShutDownTests