-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathvalidate-sample.ps1
More file actions
64 lines (53 loc) · 2.48 KB
/
Copy pathvalidate-sample.ps1
File metadata and controls
64 lines (53 loc) · 2.48 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
param(
[switch]$SkipInstall,
[switch]$SkipTests,
[switch]$SkipBrowser,
[switch]$KeepProcesses,
[switch]$Headed,
[int]$TimeoutSec = 90
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
. (Join-Path $PSScriptRoot '../../Tools/powershell/SampleValidation.ps1')
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '../..')).Path
$toolRoot = Join-Path $repoRoot 'Tools/sample-validation'
$appRoot = $PSScriptRoot
$nodeEnvironment = Get-ValidationNodeEnvironment
$runtimeHandle = $null
try {
Write-Step 'Preflight checks'
Assert-CommandExists 'node'
Assert-CommandExists 'npm'
Assert-CommandExists 'npx'
if (-not $SkipInstall) {
Write-Step 'Installing dependencies'
Invoke-ExternalCommand -FilePath 'npm' -Arguments @('install') -WorkingDirectory $appRoot -Environment $nodeEnvironment
}
Write-Step 'Building app'
Invoke-ExternalCommand -FilePath 'npm' -Arguments @('run', 'build') -WorkingDirectory $appRoot -Environment $nodeEnvironment
Write-Step 'Linting app'
Invoke-ExternalCommand -FilePath 'npm' -Arguments @('run', 'lint') -WorkingDirectory $appRoot -Environment $nodeEnvironment
Write-Host 'No automated test script is defined for this sample.' -ForegroundColor Yellow
Write-Step 'Starting preview server'
$logPath = New-ValidationLogPath -WorkingDirectory $appRoot -Name 'project-management'
$runtimeHandle = Start-LoggedProcess -FilePath 'npx' -Arguments @('vite', 'preview', '--host', '127.0.0.1', '--port', '4173') -WorkingDirectory $appRoot -LogPath $logPath -Environment $nodeEnvironment
[void](Wait-ForHttpEndpoint -Url 'http://127.0.0.1:4173' -TimeoutSec $TimeoutSec -AllowedStatusCodes @(200) -ProcessHandle $runtimeHandle)
if ($SkipBrowser) {
Write-Host 'Skipping browser smoke because -SkipBrowser was specified.' -ForegroundColor Yellow
}
else {
Write-Step 'Running browser smoke'
Invoke-BrowserSmoke -ToolRoot $toolRoot -Url 'http://127.0.0.1:4173' -SkipInstall:$SkipInstall -Headed:$Headed -TimeoutSec $TimeoutSec -ExpectSelector '#root'
}
Write-Host 'Project management sample validation completed.' -ForegroundColor Green
Write-ValidationSummary -Status 'PASS' -Message 'Build, preview startup, and browser smoke checks passed.'
}
catch {
Write-ValidationSummary -Status 'FAIL' -Message $_.Exception.Message
throw
}
finally {
if ($null -ne $runtimeHandle -and -not $KeepProcesses) {
Stop-LoggedProcess -Handle $runtimeHandle
}
}