forked from microsoft/devhome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.ps1
150 lines (123 loc) · 4.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
Param(
[string]$Platform = "x64",
[string]$Configuration = "debug",
[switch]$IsAzurePipelineBuild = $false,
[switch]$Help = $false
)
$StartTime = Get-Date
if ($Help) {
Write-Host @"
Copyright (c) Microsoft Corporation and Contributors.
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-ChildItem HKLM:\SOFTWARE\$_\Microsoft\Windows\CurrentVersion\Uninstall\ | ? {($_.GetValue("DisplayName")) -like "*Windows Application Driver*"}
if (-not($IsAzurePipelineBuild)) {
if ($isInstalled){
Write-Host "WinAppDriver is already installed on this computer."
}
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 = "$env:Build_SourcesDirectory\temp"
if (-not(Test-Path -Path $outpath)) {
New-Item -ItemType Directory -Path $outpath | Out-Null
}
Invoke-WebRequest -Uri $url -OutFile "$env:Build_SourcesDirectory\temp\WinAppDriverx64.exe"
Start-Process -Wait -Filepath $env:Build_SourcesDirectory\temp\WinAppDriverx64.exe -ArgumentList "/S" -PassThru
}
Start-Process -FilePath "C:\Program Files\Windows Application Driver\WinAppDriver.exe"
}
Function ShutDownTests {
if (-not($IsAzurePipelineBuild)) {
Stop-Process -Name "WinAppDriver"
}
$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 pipeline until signing is solved
if (-not($IsAzurePipelineBuild)) {
$DevHomePackage = Get-AppPackage "Microsoft.DevHome"
if ($DevHomePackage) {
Write-Host "Uninstalling old Dev Home"
Remove-AppPackage -Package $DevHomePackage.PackageFullName
}
Write-Host "Installing Dev Home"
Add-AppPackage "AppxPackages\$configuration\DevHome-$platform.msix"
}
$vstestArgs = @(
("/Platform:$platform"),
("/Logger:trx;LogFileName=DevHome.Test-$platform-$configuration.trx"),
("test\bin\$platform\$configuration\net6.0-windows10.0.22000.0\DevHome.Test.dll")
)
$winAppTestArgs = @(
("/Platform:$platform"),
("/Logger:trx;LogFileName=DevHome.UITest-$platform-$configuration.trx"),
("uitest\bin\$platform\$configuration\net6.0-windows10.0.22000.0\DevHome.UITest.dll")
)
& $vstestPath $vstestArgs
# TODO: UI tests are currently disabled in pipeline until signing is solved
if (-not($IsAzurePipelineBuild)) {
& $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\net6.0-windows10.0.22000.0\*.UnitTest.dll")
)
$winAppTestArgs = @(
("/Platform:$platform"),
("/Logger:trx;LogFileName=$tool.UITest-$platform-$configuration.trx"),
("tools\$tool\*UITest\bin\$platform\$configuration\net6.0-windows10.0.22000.0\*.UITest.dll")
)
& $vstestPath $vstestArgs
# TODO: UI tests are currently disabled in pipeline until signing is solved
if (-not($IsAzurePipelineBuild)) {
& $vstestPath $winAppTestArgs
}
}
}
}
} Catch {
$formatString = "`n{0}`n`n{1}`n`n"
$fields = $_, $_.ScriptStackTrace
Write-Host ($formatString -f $fields) -ForegroundColor RED
ShutDownTests
Exit 1
}
ShutDownTests