@@ -256,80 +256,143 @@ try {
256256 # Move back to the original directory
257257 Set-Location $current_dir
258258
259+ if (-not (Test-Path $ConformanceTestsFolder )) {
260+ Write-Host " Error: Conformance tests folder '$ConformanceTestsFolder ' does not exist."
261+ exit $UNRECOVERABLE_ERROR_EXIT_CODE
262+ }
263+
259264 # Define the path to the conformance tests subfolder
260265 $script :NODE_CONFORMANCE_TESTS_SUBFOLDER = Join-Path ([System.IO.Path ]::GetTempPath()) " node_$ ( Split-Path $ConformanceTestsFolder - Leaf) "
261266
262- if ($env: VERBOSE -eq " 1" ) {
263- Write-Host " Preparing conformance tests Node subfolder: $script :NODE_CONFORMANCE_TESTS_SUBFOLDER "
264- }
265-
266- # Check if the conformance tests node subfolder exists
267- if (Test-Path $script :NODE_CONFORMANCE_TESTS_SUBFOLDER ) {
268- # Delete all files and folders except "node_modules", "plain_modules", and "package-lock.json"
269- Get-ChildItem - Path $script :NODE_CONFORMANCE_TESTS_SUBFOLDER - Force |
270- Where-Object {
271- $_.Name -ne " node_modules" -and
272- $_.Name -ne " plain_modules" -and
273- $_.Name -ne " package-lock.json"
274- } | Remove-Item - Recurse - Force
267+ # Stage a single conformance test suite into the scratch subfolder and run
268+ # it. Returns the cypress run exit code.
269+ function Invoke-CypressSuite {
270+ param ([string ]$SuiteFolder )
275271
276272 if ($env: VERBOSE -eq " 1" ) {
277- Write-Host " Cleanup completed, keeping 'node_modules' and 'package-lock.json'. "
273+ Write-Host " Preparing conformance tests Node subfolder: $ script :NODE_CONFORMANCE_TESTS_SUBFOLDER "
278274 }
279- } else {
280- if ($env: VERBOSE -eq " 1" ) {
281- Write-Host " Subfolder does not exist. Creating it..."
275+
276+ # Check if the conformance tests node subfolder exists
277+ if (Test-Path $script :NODE_CONFORMANCE_TESTS_SUBFOLDER ) {
278+ # Delete all files and folders except "node_modules", "plain_modules", and "package-lock.json"
279+ Get-ChildItem - Path $script :NODE_CONFORMANCE_TESTS_SUBFOLDER - Force |
280+ Where-Object {
281+ $_.Name -ne " node_modules" -and
282+ $_.Name -ne " plain_modules" -and
283+ $_.Name -ne " package-lock.json"
284+ } | Remove-Item - Recurse - Force
285+
286+ if ($env: VERBOSE -eq " 1" ) {
287+ Write-Host " Cleanup completed, keeping 'node_modules' and 'package-lock.json'."
288+ }
289+ } else {
290+ if ($env: VERBOSE -eq " 1" ) {
291+ Write-Host " Subfolder does not exist. Creating it..."
292+ }
293+
294+ New-Item - ItemType Directory - Path $script :NODE_CONFORMANCE_TESTS_SUBFOLDER - Force | Out-Null
282295 }
283296
284- New-Item - ItemType Directory - Path $script :NODE_CONFORMANCE_TESTS_SUBFOLDER - Force | Out-Null
285- }
297+ Copy-Item - Path " $SuiteFolder /*" - Destination $script :NODE_CONFORMANCE_TESTS_SUBFOLDER - Recurse - Force
286298
287- Copy-Item - Path " $ConformanceTestsFolder /*" - Destination $script :NODE_CONFORMANCE_TESTS_SUBFOLDER - Recurse - Force
299+ # Move to the subfolder with Cypress tests
300+ if (-not (Test-Path $script :NODE_CONFORMANCE_TESTS_SUBFOLDER )) {
301+ Write-Host " Error: conformance tests Node folder '$script :NODE_CONFORMANCE_TESTS_SUBFOLDER ' does not exist."
302+ exit $UNRECOVERABLE_ERROR_EXIT_CODE
303+ }
288304
289- # Move to the subfolder with Cypress tests
290- if (-not (Test-Path $script :NODE_CONFORMANCE_TESTS_SUBFOLDER )) {
291- Write-Host " Error: conformance tests Node folder '$script :NODE_CONFORMANCE_TESTS_SUBFOLDER ' does not exist."
292- exit $UNRECOVERABLE_ERROR_EXIT_CODE
293- }
305+ Push-Location $script :NODE_CONFORMANCE_TESTS_SUBFOLDER
294306
295- Push-Location $script :NODE_CONFORMANCE_TESTS_SUBFOLDER
307+ try {
308+ # Temporarily allow stderr output without throwing (npm may write warnings to stderr)
309+ # ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
310+ $script :ErrorActionPreference = ' Continue'
311+ $npmInstallOutput = npm install cypress -- save-dev -- prefer- offline -- no- audit -- no- fund -- loglevel error 2>&1 | ForEach-Object { if ($_ -is [System.Management.Automation.ErrorRecord ]) { $_.Exception.Message } else { $_ } } | Out-String
312+ $script :ErrorActionPreference = ' Stop'
313+ $npmInstallOutput -split " `n " | Where-Object { $_ -notmatch $NPM_INSTALL_OUTPUT_FILTER } | ForEach-Object {
314+ if ($_.Trim ()) { Write-Host $_ }
315+ }
296316
297- # Temporarily allow stderr output without throwing (npm may write warnings to stderr)
298- # ForEach-Object converts ErrorRecord objects (from stderr) to plain strings to avoid verbose error formatting
299- $ErrorActionPreference = ' Continue'
300- $npmInstallOutput = npm install cypress -- save-dev -- prefer- offline -- no- audit -- no- fund -- loglevel error 2>&1 | ForEach-Object { if ($_ -is [System.Management.Automation.ErrorRecord ]) { $_.Exception.Message } else { $_ } } | Out-String
301- $ErrorActionPreference = ' Stop'
302- $npmInstallOutput -split " `n " | Where-Object { $_ -notmatch $NPM_INSTALL_OUTPUT_FILTER } | ForEach-Object {
303- if ($_.Trim ()) { Write-Host $_ }
304- }
317+ if ($env: VERBOSE -eq " 1" ) {
318+ Write-Host " Running Cypress conformance tests..."
319+ }
305320
306- if ($env: VERBOSE -eq " 1" ) {
307- Write-Host " Running Cypress conformance tests..."
321+ $script :ErrorActionPreference = ' Continue'
322+ $cypress_info_output = npx cypress info 2>&1 | ForEach-Object { if ($_ -is [System.Management.Automation.ErrorRecord ]) { $_.Exception.Message } else { $_ } } | Out-String
323+ $script :ErrorActionPreference = ' Stop'
324+ $CYPRESS_BROWSER_FLAG = " "
325+ if ($cypress_info_output -match " (?i)chrome" ) {
326+ $CYPRESS_BROWSER_FLAG = " --browser=chrome"
327+ }
328+ Write-Host " CYPRESS_BROWSER_FLAG: $ ( if ($CYPRESS_BROWSER_FLAG ) { $CYPRESS_BROWSER_FLAG } else { ' none' }) "
329+
330+ $env: BROWSERSLIST_IGNORE_OLD_DATA = " 1"
331+ if ($CYPRESS_BROWSER_FLAG ) {
332+ npx cypress run $CYPRESS_BROWSER_FLAG -- config video= false 2> $null
333+ } else {
334+ npx cypress run -- config video= false 2> $null
335+ }
336+ return $LASTEXITCODE
337+ } finally {
338+ Pop-Location
339+ }
308340 }
309341
310- $ErrorActionPreference = ' Continue'
311- $cypress_info_output = npx cypress info 2>&1 | ForEach-Object { if ($_ -is [System.Management.Automation.ErrorRecord ]) { $_.Exception.Message } else { $_ } } | Out-String
312- $ErrorActionPreference = ' Stop'
313- $CYPRESS_BROWSER_FLAG = " "
314- if ($cypress_info_output -match " (?i)chrome" ) {
315- $CYPRESS_BROWSER_FLAG = " --browser=chrome"
342+ function Test-HasCypressConfig {
343+ param ([string ]$Folder )
344+ return [bool ](Get-ChildItem - Path $Folder - Filter " cypress.config.*" - File - ErrorAction SilentlyContinue)
316345 }
317- Write-Host " CYPRESS_BROWSER_FLAG: $ ( if ($CYPRESS_BROWSER_FLAG ) { $CYPRESS_BROWSER_FLAG } else { ' none' }) "
318346
319- $env: BROWSERSLIST_IGNORE_OLD_DATA = " 1"
320- if ($CYPRESS_BROWSER_FLAG ) {
321- npx cypress run $CYPRESS_BROWSER_FLAG -- config video= false 2> $null
322- } else {
323- npx cypress run -- config video= false 2> $null
347+ if (Test-HasCypressConfig $ConformanceTestsFolder ) {
348+ # Single conformance test suite ($ConformanceTestsFolder is the suite folder itself).
349+ $cypress_run_result = Invoke-CypressSuite $ConformanceTestsFolder
350+
351+ if ($cypress_run_result -ne 0 ) {
352+ if ($env: VERBOSE -eq " 1" ) {
353+ Write-Host " Error: Cypress conformance tests have failed."
354+ }
355+ exit 1
356+ }
357+
358+ exit 0
324359 }
325- $cypress_run_result = $LASTEXITCODE
326360
327- if ($cypress_run_result -ne 0 ) {
328- if ($env: VERBOSE -eq " 1" ) {
329- Write-Host " Error: Cypress conformance tests have failed."
361+ # $ConformanceTestsFolder is a folder of conformance test suites: run every
362+ # non-hidden subfolder that contains a cypress config file.
363+ $suites_run = 0
364+ $aggregated_exit_code = 0
365+
366+ $suite_folders = Get-ChildItem - Path $ConformanceTestsFolder - Directory |
367+ Where-Object { -not $_.Name.StartsWith (" ." ) } |
368+ Sort-Object Name
369+
370+ foreach ($suite in $suite_folders ) {
371+ if (-not (Test-HasCypressConfig $suite.FullName )) {
372+ continue
373+ }
374+
375+ Write-Host " === conformance suite: $ ( $suite.Name ) ==="
376+
377+ $cypress_run_result = Invoke-CypressSuite $suite.FullName
378+ $suites_run += 1
379+
380+ # Keep running the remaining suites so the full set of failures is
381+ # reported, but exit non-zero if any suite failed.
382+ if ($cypress_run_result -ne 0 ) {
383+ if ($env: VERBOSE -eq " 1" ) {
384+ Write-Host " Error: Cypress conformance tests have failed."
385+ }
386+ $aggregated_exit_code = 1
330387 }
388+ }
389+
390+ if ($suites_run -eq 0 ) {
391+ Write-Host " `n Error: No conformance test suites discovered."
331392 exit 1
332393 }
394+
395+ exit $aggregated_exit_code
333396} finally {
334397 Cleanup
335398}
0 commit comments