feat: harden isolated Tornado test workflow
This commit is contained in:
68
scripts/Test-WebPlayout.ps1
Normal file
68
scripts/Test-WebPlayout.ps1
Normal file
@@ -0,0 +1,68 @@
|
||||
#Requires -Version 5.1
|
||||
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string] $NodePath
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Resolve-NodePath {
|
||||
param([AllowEmptyString()][string] $ExplicitPath)
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace($ExplicitPath)) {
|
||||
if (-not [IO.Path]::IsPathRooted($ExplicitPath) -or
|
||||
-not (Test-Path -LiteralPath $ExplicitPath -PathType Leaf)) {
|
||||
throw 'NodePath must identify an existing absolute node executable path.'
|
||||
}
|
||||
|
||||
return [IO.Path]::GetFullPath($ExplicitPath)
|
||||
}
|
||||
|
||||
$command = Get-Command node -CommandType Application -ErrorAction SilentlyContinue |
|
||||
Select-Object -First 1
|
||||
if ($null -ne $command) {
|
||||
return $command.Source
|
||||
}
|
||||
|
||||
$programFiles = [Environment]::GetFolderPath(
|
||||
[Environment+SpecialFolder]::ProgramFiles)
|
||||
$candidates = @(
|
||||
(Join-Path $programFiles 'Microsoft Visual Studio\18\Community\MSBuild\Microsoft\VisualStudio\NodeJs\node.exe'),
|
||||
(Join-Path $programFiles 'Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VisualStudio\NodeJs\node.exe')
|
||||
)
|
||||
foreach ($candidate in $candidates) {
|
||||
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
|
||||
return [IO.Path]::GetFullPath($candidate)
|
||||
}
|
||||
}
|
||||
|
||||
throw 'A Node.js executable was not found. Pass its absolute path with -NodePath.'
|
||||
}
|
||||
|
||||
$node = Resolve-NodePath -ExplicitPath $NodePath
|
||||
$repositoryRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
|
||||
$scripts = @(
|
||||
(Join-Path $repositoryRoot 'Web\playout-safety.js'),
|
||||
(Join-Path $repositoryRoot 'Web\app.js')
|
||||
)
|
||||
$test = Join-Path $repositoryRoot 'tests\Web\playout-safety.test.cjs'
|
||||
|
||||
foreach ($script in $scripts) {
|
||||
& $node --check $script
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "JavaScript syntax validation failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
}
|
||||
|
||||
& $node --test $test
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Web playout tests failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
|
||||
[pscustomobject][ordered]@{
|
||||
Status = 'Passed'
|
||||
SyntaxFiles = $scripts.Count
|
||||
TestFile = [IO.Path]::GetFileName($test)
|
||||
}
|
||||
Reference in New Issue
Block a user