-
Notifications
You must be signed in to change notification settings - Fork 261
Add RunPageScriptingTests parameter and implementation to Run-AlPipeline #4052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dd58688
7101a16
992418d
fc5068d
fc2de4b
958b65d
e57d33e
203af47
4430d6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,6 +279,8 @@ | |
| Override function parameter for Get-BcContainerEventLog | ||
| .Parameter InstallMissingDependencies | ||
| Override function parameter for Installing missing dependencies | ||
| .Parameter RunPageScriptingTests | ||
| Override function parameter for Running Page Scripting Tests | ||
| .Example | ||
| Please visit https://www.freddysblog.com for descriptions | ||
| .Example | ||
|
|
@@ -416,6 +418,7 @@ Param( | |
| [scriptblock] $GetBestGenericImageName, | ||
| [scriptblock] $GetBcContainerEventLog, | ||
| [scriptblock] $InstallMissingDependencies, | ||
| [scriptblock] $RunPageScriptingTests, | ||
| [scriptblock] $PipelineFinalize | ||
| ) | ||
|
|
||
|
|
@@ -528,6 +531,110 @@ function GetInstalledApps { | |
| Write-GroupEnd | ||
| } | ||
|
|
||
| function RunPageScriptingTests { | ||
| param( | ||
| [string] $containerName, | ||
| [PSCredential] $credential, | ||
| [array] $pageScriptingTests, | ||
| [array] $restoreDatabases, | ||
| [string] $pageScriptingTestResultsFile, | ||
| [string] $pageScriptingTestResultsFolder, | ||
| [string] $startAddress, | ||
| [scriptblock] $RestoreDatabasesInBcContainer, | ||
| [switch] $returnTrueIfAllPassed | ||
| ) | ||
|
|
||
| # Install npm package for page scripting tests | ||
| pwsh -command { npm i @microsoft/[email protected] --save --silent } | ||
|
|
||
| ${env:containerUsername} = $credential.UserName | ||
| ${env:containerPassword} = $credential.Password | Get-PlainText | ||
|
|
||
| $allPassed = $true | ||
| $usedNames = @() | ||
|
|
||
| $pageScriptingTests | ForEach-Object { | ||
| $thisFailed = $false | ||
| if ($restoreDatabases -contains 'BeforeEachPageScriptingTest') { | ||
| Write-GroupStart -Message "Restoring databases before each page scripting test" | ||
| Invoke-Command -ScriptBlock $RestoreDatabasesInBcContainer -ArgumentList @{"containerName" = $containerName } | ||
| Write-GroupEnd | ||
| } | ||
| $testSpec = $_ | ||
| $name = $testSpec -replace '[\\/]', '-' -replace ':', '' -replace '\*', 'all' -replace '\?', 'x' -replace '\.yml$', '' | ||
| if ($usedNames -contains $name) { | ||
| throw "PageScriptingTests contains two similar test specs (resulting in identical results folders), please rename your test specs ($testSpec)." | ||
| } | ||
| $usedNames += $name | ||
| $path = $testSpec | ||
| if (-not [System.IO.Path]::IsPathRooted($path)) { $path = Join-Path $baseFolder $path } | ||
| if (-not (Test-Path $path)) { throw "No page scripting tests found matching $testSpec" } | ||
| Write-Host "Running Page Scripting Tests for $testSpec (test name: $name)" | ||
| $resultsFolder = Join-Path $pageScriptingTestResultsFolder $name | ||
| New-Item -Path $resultsFolder -ItemType Directory | Out-Null | ||
| try { | ||
| pwsh -command { | ||
| param( | ||
| [string]$TestPath, | ||
| [string]$ResultsFolder, | ||
| [string]$StartAddress | ||
| ) | ||
| Write-Host "Running: npx replay $TestPath -ResultDir $ResultsFolder -StartAddress $StartAddress -Authentication 'UserPassword' -usernameKey 'containerUsername' -passwordkey 'containerPassword'" | ||
| npx replay $TestPath -ResultDir $ResultsFolder -StartAddress $StartAddress -Authentication 'UserPassword' -usernameKey 'containerUsername' -passwordkey 'containerPassword' | ||
| } -args $path, $resultsFolder, $startAddress | ||
| if ($? -ne "True") { | ||
| Write-Host "Page Scripting Tests failed for $testSpec" | ||
| $thisFailed = $true | ||
| } | ||
| } | ||
| catch { | ||
| $thisFailed = $true | ||
| Write-Host -ForegroundColor Red "Page Scripting Tests failed for $testSpec : $($_.Exception.Message)" | ||
| } | ||
|
|
||
| if ($thisFailed) { | ||
| Write-Host "Page Scripting Tests failed for $testSpec" | ||
| $allPassed = $false | ||
aholstrup1 marked this conversation as resolved.
Show resolved
Hide resolved
aholstrup1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| $testResultsFile = Join-Path $resultsFolder "results.xml" | ||
| $playwrightReportFolder = Join-Path $resultsFolder 'playwright-report' | ||
| if ((Test-Path $testResultsFile -PathType Leaf) -and (Test-Path $playwrightReportFolder -PathType Container)) { | ||
| $thisXml = [xml](Get-Content $testResultsFile -Encoding UTF8) | ||
| $thisXml.testsuites.testsuite.Name = $name | ||
| $resultsXml = $thisXml | ||
| if (Test-Path $pageScriptingTestResultsFile) { | ||
| # Merge results and aggregate counts | ||
| $resultsXml = [xml](Get-Content $pageScriptingTestResultsFile -Encoding UTF8) | ||
| $resultsXml.testsuites.AppendChild($resultsXml.ImportNode($thisXml.testsuites.testsuite, $true)) | ||
| } | ||
| foreach ($property in 'tests', 'failures', 'skipped', 'errors', 'time') { | ||
| $resultsXml.testsuites."$property" = "$(([double[]]$resultsXml.testsuites.testsuite."$property" | Measure-Object -Sum).Sum)" | ||
| } | ||
| $resultsXml.Save($pageScriptingTestResultsFile) | ||
| Remove-Item $testResultsFile -Force | ||
| if ($thisFailed) { | ||
| Write-Host "Moving Playwright report folder" | ||
| Move-Item -Path "$playwrightReportFolder/*" -Destination $resultsFolder -Force | ||
| Write-Host "Removing Playwright report folder" | ||
| Remove-Item -Path $playwrightReportFolder -Force | ||
| } | ||
| else { | ||
| if (Test-Path $resultsFolder) { | ||
| Write-Host "Removing results folder" | ||
| Remove-Item -Path $resultsFolder -Recurse -Force -ErrorAction SilentlyContinue | ||
| } | ||
| else { | ||
| Write-Host "Results folder $resultsFolder not found" | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ($returnTrueIfAllPassed) { | ||
| return $allPassed | ||
| } | ||
| } | ||
|
|
||
| $script:existingContainerName = '' | ||
| $script:existingCompilerFolder = '' | ||
|
|
||
|
|
@@ -838,7 +945,10 @@ if ($bcptTestFolders) { | |
|
|
||
| $artifactUrl = "" | ||
| $filesOnly = $false | ||
| if ($bcAuthContext) { | ||
| $IsBcSaaSInfrastructure = $bcAuthContext -and $bcAuthContext -is [Hashtable] -and $bcAuthContext.ContainsKey('scopes') -and $bcAuthContext.scopes -like "https://projectmadeira.com/*" | ||
|
|
||
| if ($IsBcSaaSInfrastructure) { | ||
| Write-Host "Using BC SaaS Infrastructure. Test for feature compatibility." | ||
| if ("$environment" -eq "") { | ||
| throw "When specifying bcAuthContext, you also have to specify the name of the pre-setup online environment to use." | ||
| } | ||
|
|
@@ -1263,6 +1373,11 @@ else { | |
| if ($InstallMissingDependencies) { | ||
| Write-Host -ForegroundColor Yellow "InstallMissingDependencies override"; Write-Host $InstallMissingDependencies.ToString() | ||
| } | ||
| if ($RunPageScriptingTests) { | ||
| Write-Host -ForegroundColor Yellow "RunPageScriptingTests override"; Write-Host $RunPageScriptingTests.ToString() | ||
| } else { | ||
| $RunPageScriptingTests = { Param([Hashtable]$parameters) RunPageScriptingTests @parameters } | ||
| } | ||
| Write-GroupEnd | ||
|
|
||
| $signApps = ($codeSignCertPfxFile -ne "") | ||
|
|
@@ -2878,7 +2993,7 @@ if ($buildArtifactFolder -and (Test-Path $bcptResultsFile)) { | |
| Write-GroupEnd | ||
| } | ||
|
|
||
| if ($createContainer -and !$doNotRunPageScriptingTests -and $pageScriptingTests -and $pageScriptingTestResultsFolder -and $pageScriptingTestResultsFile) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would you not check that a container is created when restoring the database in a container?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just because you use CompilerFolder doesn't necessarily mean you don't have a container. |
||
| if (!$doNotRunPageScriptingTests -and $pageScriptingTests -and $pageScriptingTestResultsFolder -and $pageScriptingTestResultsFile) { | ||
| if ($restoreDatabases -contains 'BeforePageScriptingTests' -and $restoreDatabases -notcontains 'BeforeEachPageScriptingTest') { | ||
| Write-GroupStart -Message "Restoring databases before page scripting tests" | ||
| Invoke-Command -ScriptBlock $RestoreDatabasesInBcContainer -ArgumentList @{"containerName" = (GetBuildContainer)} | ||
|
|
@@ -2899,92 +3014,24 @@ Measure-Command { | |
| if ($testCountry) { | ||
| Write-Host -ForegroundColor Yellow "Running Page Scripting Tests for additional country $testCountry" | ||
| } | ||
|
|
||
| $containerName = (GetBuildContainer) | ||
|
|
||
| # Install npm package for page scripting tests | ||
| pwsh -command { npm i @microsoft/[email protected] --save --silent } | ||
|
|
||
| ${env:containerUsername} = $credential.UserName | ||
| ${env:containerPassword} = $credential.Password | Get-PlainText | ||
| $startAddress = "http://$containerName/BC?tenant=$tenant" | ||
|
|
||
| $usedNames = @() | ||
|
|
||
| $pageScriptingTests | ForEach-Object { | ||
| $thisFailed = $false | ||
| if ($restoreDatabases -contains 'BeforeEachPageScriptingTest') { | ||
| Write-GroupStart -Message "Restoring databases before each page scripting test" | ||
| Invoke-Command -ScriptBlock $RestoreDatabasesInBcContainer -ArgumentList @{"containerName" = $containerName} | ||
| Write-GroupEnd | ||
| } | ||
| $testSpec = $_ | ||
| $name = $testSpec -replace '[\\/]', '-' -replace ':', '' -replace '\*', 'all' -replace '\?', 'x' -replace '\.yml$', '' | ||
| if ($usedNames -contains $name) { | ||
| throw "PageScriptingTests contains two similar test specs (resulting in identical results folders), please rename your test specs ($testSpec)." | ||
| } | ||
| $usedNames += $name | ||
| $path = $testSpec | ||
| if (-not [System.IO.Path]::IsPathRooted($path)) { $path = Join-Path $baseFolder $path } | ||
| if (-not (Test-Path $path)) { throw "No page scripting tests found matching $testSpec" } | ||
| Write-Host "Running Page Scripting Tests for $testSpec (test name: $name)" | ||
| $resultsFolder = Join-Path $pageScriptingTestResultsFolder $name | ||
| New-Item -Path $resultsFolder -ItemType Directory | Out-Null | ||
| try { | ||
| pwsh -command { | ||
| param( | ||
| [string]$TestPath, | ||
| [string]$ResultsFolder, | ||
| [string]$StartAddress | ||
| ) | ||
| Write-Host "Running: npx replay $TestPath -ResultDir $ResultsFolder -StartAddress $StartAddress -Authentication 'UserPassword' -usernameKey 'containerUsername' -passwordkey 'containerPassword'" | ||
| npx replay $TestPath -ResultDir $ResultsFolder -StartAddress $StartAddress -Authentication 'UserPassword' -usernameKey 'containerUsername' -passwordkey 'containerPassword' | ||
| } -args $path, $resultsFolder, $startAddress | ||
| if ($? -ne "True") { | ||
| Write-Host "Page Scripting Tests failed for $testSpec" | ||
| $thisFailed = $true | ||
| } | ||
| } catch { | ||
| $thisFailed = $true | ||
| Write-Host -ForegroundColor Red "Page Scripting Tests failed for $testSpec : $($_.Exception.Message)" | ||
| } | ||
|
|
||
| if ($thisFailed) { | ||
| Write-Host "Page Scripting Tests failed for $testSpec" | ||
| $allPassed = $false | ||
| } | ||
| $testResultsFile = Join-Path $resultsFolder "results.xml" | ||
| $playwrightReportFolder = Join-Path $resultsFolder 'playwright-report' | ||
| if ((Test-Path $testResultsFile -PathType Leaf) -and (Test-Path $playwrightReportFolder -PathType Container)) { | ||
| $thisXml = [xml](Get-Content $testResultsFile -encoding UTF8) | ||
| $thisXml.testsuites.testsuite.Name = $name | ||
| $resultsXml = $thisXml | ||
| if (Test-Path $pageScriptingTestResultsFile) { | ||
| # Merge results and aggregate counts | ||
| $resultsXml = [xml](Get-Content $pageScriptingTestResultsFile -encoding UTF8) | ||
| $resultsXml.testsuites.AppendChild($resultsXml.ImportNode($thisXml.testsuites.testsuite, $true)) | ||
| } | ||
| foreach($property in 'tests','failures','skipped','errors','time') { | ||
| $resultsXml.testsuites."$property" = "$(([double[]]$resultsXml.testsuites.testsuite."$property" | Measure-Object -Sum).Sum)" | ||
| } | ||
| $resultsXml.Save($pageScriptingTestResultsFile) | ||
| Remove-Item $testResultsFile -Force | ||
| if ($thisFailed) { | ||
| Write-Host "Moving Playwright report folder" | ||
| Move-Item -Path "$playwrightReportFolder/*" -Destination $resultsFolder -Force | ||
| Write-Host "Removing Playwright report folder" | ||
| Remove-Item -Path $playwrightReportFolder -Force | ||
| } | ||
| else { | ||
| if (Test-Path $resultsFolder) { | ||
| Write-Host "Removing results folder" | ||
| Remove-Item -Path $resultsFolder -Recurse -Force -ErrorAction SilentlyContinue | ||
| } else { | ||
| Write-Host "Results folder $resultsFolder not found" | ||
| } | ||
| } | ||
| } | ||
| $Parameters = @{ | ||
| "containerName" = (GetBuildContainer) | ||
| "credential" = $credential | ||
| "pageScriptingTests" = $pageScriptingTests | ||
| "restoreDatabases" = $restoreDatabases | ||
| "pageScriptingTestResultsFile" = $pageScriptingTestResultsFile | ||
| "pageScriptingTestResultsFolder" = $pageScriptingTestResultsFolder | ||
| "startAddress" = "http://$containerName/BC?tenant=$tenant" | ||
| "RestoreDatabasesInBcContainer" = $RestoreDatabasesInBcContainer | ||
| "returnTrueIfAllPassed" = $true | ||
| } | ||
| $result = Invoke-Command -ScriptBlock $RunPageScriptingTests -ArgumentList $Parameters | ||
| if ($result -is [array]) { | ||
aholstrup1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $allPassed = $allPassed -and $result[$result.Count-1] | ||
| } | ||
| else { | ||
| $allPassed = $allPassed -and $result | ||
| } | ||
| } | ForEach-Object { Write-Host -ForegroundColor Yellow "`nRunning Page Scripting Tests took $([int]$_.TotalSeconds) seconds" } | ||
| Write-GroupEnd | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.