From d920d43ef029a11c8c9202a1e5dc19b6b5ad1b58 Mon Sep 17 00:00:00 2001 From: gowridurgad <159780674+gowridurgad@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:43:49 +0530 Subject: [PATCH] Update Node.Tests.ps1 --- tests/Node.Tests.ps1 | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/Node.Tests.ps1 b/tests/Node.Tests.ps1 index c8141ef..315d4b6 100644 --- a/tests/Node.Tests.ps1 +++ b/tests/Node.Tests.ps1 @@ -2,22 +2,17 @@ Import-Module (Join-Path $PSScriptRoot "../helpers/pester-extensions.psm1") BeforeAll { function Get-UseNodeLogs { - # Determine if the current environment is Windows or Linux - $isWindows = $PSVersionTable.PSVersion.Platform -eq "Win32NT" - $isArm64 = $env:PROCESSOR_ARCHITECTURE -eq "ARM64" + # GitHub Windows images don't have `HOME` variable + $homeDir = $env:HOME ?? $env:HOMEDRIVE + $logsFolderPath = Join-Path -Path $homeDir -ChildPath "runners/*/_diag/pages" -Resolve - # For Windows, use HOMEDRIVE if HOME is not available - # For Linux, use HOME directly - $homeDir = if ($isWindows) { $env:HOME ?? $env:HOMEDRIVE } else { $env:HOME } - - # Check if the OS is Windows ARM64 or Linux ARM64 and set the logs folder path accordingly - if ($isWindows -and $isArm64) { - $logsFolderPath = Join-Path -Path $homeDir -ChildPath "runners/_diag/pages" -Resolve - } elseif (-not $isWindows -and $isArm64) { - $logsFolderPath = Join-Path -Path $homeDir -ChildPath "runners/_diag/pages" -Resolve - } else { - throw "Unsupported OS or architecture." - } + $useNodeLogFile = Get-ChildItem -Path $logsFolderPath | Where-Object { + $logContent = Get-Content $_.Fullname -Raw + return $logContent -match "setup-node@v" + } | Select-Object -First 1 + return $useNodeLogFile.Fullname + } +} $useNodeLogFile = Get-ChildItem -Path $logsFolderPath | Where-Object { $logContent = Get-Content $_.Fullname -Raw @@ -51,9 +46,12 @@ Describe "Node.js" { It "cached version is used without downloading" { # Analyze output of previous steps to check if Node.js was consumed from cache or downloaded $useNodeLogFile = Get-UseNodeLogs + if ($useNodeLogFile -eq $null) { + Set-ItResult -Skipped -Because "Log file does not exist" + } else { $useNodeLogFile | Should -Exist $useNodeLogContent = Get-Content $useNodeLogFile -Raw - $useNodeLogContent | Should -Match "Found in cache" + } } It "Run simple code" {