Developer-Dashboard
view release on metacpan or search on metacpan
integration/windows/run-strawberry-smoke.ps1 view on Meta::CPAN
# Output: returns nothing and throws if the fragment is absent.
function Invoke-AssertContains {
param(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$Text,
[Parameter(Mandatory = $true)]
[string]$Fragment,
[Parameter(Mandatory = $true)]
[string]$Label
)
if (-not $Text.Contains($Fragment)) {
throw "$Label missing fragment [$Fragment]"
}
}
# Purpose: assert that a text blob omits a forbidden fragment.
# Input: text to inspect, the forbidden fragment, and a label for error reporting.
# Output: returns nothing and throws if the fragment is present.
function Invoke-AssertNotContains {
param(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[string]$Text,
[Parameter(Mandatory = $true)]
[string]$Fragment,
[Parameter(Mandatory = $true)]
[string]$Label
)
if ($Text.Contains($Fragment)) {
throw "$Label unexpectedly contained [$Fragment]"
}
}
# Purpose: locate an Edge or Chrome browser binary for DOM smoke checks.
# Input: none.
# Output: returns a browser path or $null when no supported browser exists.
function Get-BrowserBinary {
$candidates = @(
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
"C:\Program Files\Microsoft\Edge\Application\msedge.exe",
"C:\Program Files\Google\Chrome\Application\chrome.exe",
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
)
foreach ($candidate in $candidates) {
if (Test-Path $candidate) {
return $candidate
}
}
return $null
}
# Purpose: wait until the dashboard HTTP endpoint responds.
# Input: target URL string.
# Output: returns when the URL responds with a non-5xx code or throws on timeout.
function Wait-HttpOk {
param([Parameter(Mandatory = $true)][string]$Url)
$deadline = (Get-Date).AddSeconds(20)
while ((Get-Date) -lt $deadline) {
try {
$response = Invoke-WebRequest -UseBasicParsing -Uri $Url -TimeoutSec 2
if ($response.StatusCode -ge 200 -and $response.StatusCode -lt 500) {
return
}
}
catch {
Start-Sleep -Milliseconds 250
}
}
throw "Timed out waiting for HTTP response from $Url"
}
# Purpose: quote one native Windows process argument for a ProcessStartInfo
# Arguments string on older Windows PowerShell runtimes that lack ArgumentList.
# Input: one native argument string.
# Output: returns one safely quoted command-line argument string.
function Quote-WindowsProcessArgument {
param([Parameter(Mandatory = $true)][string]$Argument)
if ($Argument -notmatch '[\s"]') {
return $Argument
}
$quoted = $Argument -replace '(\\*)"', '$1$1\"'
$quoted = $quoted -replace '(\\+)$', '$1$1'
return '"' + $quoted + '"'
}
# Purpose: dump the rendered DOM of a page through a real Windows browser.
# Input: browser path, target URL, and browser user-data directory path.
# Output: returns the dumped DOM as text or throws on browser failure.
function Get-DumpDom {
param(
[Parameter(Mandatory = $true)][string]$Browser,
[Parameter(Mandatory = $true)][string]$Url,
[Parameter(Mandatory = $true)][string]$UserDataDir
)
$processStartInfo = [System.Diagnostics.ProcessStartInfo]::new()
$processStartInfo.FileName = $Browser
$processStartInfo.UseShellExecute = $false
$processStartInfo.RedirectStandardOutput = $true
$processStartInfo.RedirectStandardError = $true
$processStartInfo.CreateNoWindow = $true
$browserArguments = @(
'--headless',
'--disable-gpu',
'--no-first-run',
'--disable-background-networking',
'--allow-insecure-localhost',
( run in 0.507 second using v1.01-cache-2.11-cpan-524268b4103 )