-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathbuild-and-test.ps1
More file actions
69 lines (53 loc) · 2.31 KB
/
build-and-test.ps1
File metadata and controls
69 lines (53 loc) · 2.31 KB
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
$websiteUrl = "http://localhost:5020" # Adjust the URL as needed
$env:ASPIRE_ALLOW_UNSECURED_TRANSPORT="true"
# Delete the stop-aspire file if it exists
$stopAspireFilePath = Join-Path -Path "$PSScriptRoot/src/SharpSite.AppHost" -ChildPath "stop-aspire"
if (Test-Path -Path $stopAspireFilePath) {
Remove-Item -Path $stopAspireFilePath -Force
}
# Run the .NET Aspire application in the background
$dotnetRunProcess = Start-Process -FilePath "dotnet" -ArgumentList "run -lp http --project src/SharpSite.AppHost/SharpSite.AppHost.csproj --testonly=true" -NoNewWindow -PassThru -RedirectStandardOutput "output.log"
# Function to check if the website is running
function Test-Website {
param (
[string]$url
)
try {
$response = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 5
return $true
} catch {
return $false
}
}
# Wait for the website to be running
Write-Host "Waiting for the website to start..." -ForegroundColor Yellow
$maxRetries = 90
$retryCount = 0
while (-not (Test-Website -url $websiteUrl) -and $retryCount -lt $maxRetries) {
Start-Sleep -Seconds 2
$retryCount++
}
if ($retryCount -eq $maxRetries) {
Write-Host "Website did not start within the expected time." -ForegroundColor Red
# Stop the dotnet run process
Stop-Process -Id $dotnetRunProcess.Id -Force
exit 1
}
Write-Host "Website is running!" -ForegroundColor Green
# Change directory to the Playwright tests folder
# Set-Location -Path "$PSScriptRoot/e2e/SharpSite.E2E"
# Run Playwright tests using dotnet test
dotnet test ./e2e/SharpSite.E2E/SharpSite.E2E.csproj --logger trx --results-directory "playwright-test-results"
if ($LASTEXITCODE -ne 0) {
Write-Host "Playwright tests failed!" -ForegroundColor Red
# Create a file called stop-aspire
$stopAspireFilePath = Join-Path -Path "$PSScriptRoot/src/SharpSite.AppHost" -ChildPath "stop-aspire"
New-Item -Path $stopAspireFilePath -ItemType File -Force | Out-Null
Set-Location -Path "$PSScriptRoot"
exit $LASTEXITCODE
}
Write-Host "Build and tests completed successfully!" -ForegroundColor Green
# Stop the dotnet run process
$stopAspireFilePath = Join-Path -Path "$PSScriptRoot/src/SharpSite.AppHost" -ChildPath "stop-aspire"
New-Item -Path $stopAspireFilePath -ItemType File -Force | Out-Null
Set-Location -Path "$PSScriptRoot"