Skip to content

Commit c8cf9cb

Browse files
Implementing Runner-Specific Node.js Tests (#178)
* Update Node.Tests.ps1 * Update Node.Tests.ps1 * Update Node.Tests.ps1 --------- Co-authored-by: aparnajyothi-y <[email protected]>
1 parent 3a7a383 commit c8cf9cb

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

tests/Node.Tests.ps1

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
Import-Module (Join-Path $PSScriptRoot "../helpers/pester-extensions.psm1")
22

3-
BeforeAll {
4-
function Get-UseNodeLogs {
5-
# GitHub Windows images don't have `HOME` variable
6-
$homeDir = $env:HOME ?? $env:HOMEDRIVE
7-
$logsFolderPath = Join-Path -Path $homeDir -ChildPath "runners/*/_diag/pages" -Resolve
8-
9-
$useNodeLogFile = Get-ChildItem -Path $logsFolderPath | Where-Object {
10-
$logContent = Get-Content $_.Fullname -Raw
11-
return $logContent -match "setup-node@v"
12-
} | Select-Object -First 1
13-
return $useNodeLogFile.Fullname
14-
}
15-
}
3+
164

175
Describe "Node.js" {
6+
7+
BeforeAll {
8+
function Get-UseNodeLogs {
9+
# GitHub Windows images don't have `HOME` variable
10+
$homeDir = $env:HOME ?? $env:HOMEDRIVE
11+
$logsFolderPath = Join-Path -Path $homeDir -ChildPath "runners/*/_diag/pages" -Resolve
12+
13+
$useNodeLogFile = Get-ChildItem -Path $logsFolderPath | Where-Object {
14+
$logContent = Get-Content $_.Fullname -Raw
15+
return $logContent -match "setup-node@v"
16+
} | Select-Object -First 1
17+
return $useNodeLogFile.Fullname
18+
}
19+
}
20+
1821
It "is available" {
1922
"node --version" | Should -ReturnZeroExitCode
2023
}
@@ -34,15 +37,25 @@ Describe "Node.js" {
3437
$nodePath.startsWith($expectedPath) | Should -BeTrue -Because "'$nodePath' is not started with '$expectedPath'"
3538
}
3639

37-
It "cached version is used without downloading" {
38-
# Analyze output of previous steps to check if Node.js was consumed from cache or downloaded
39-
$useNodeLogFile = Get-UseNodeLogs
40-
$useNodeLogFile | Should -Exist
41-
$useNodeLogContent = Get-Content $useNodeLogFile -Raw
42-
$useNodeLogContent | Should -Match "Found in cache"
43-
}
40+
It "cached version is used without downloading" {
4441

42+
if ($env:RUNNER_TYPE -eq "self-hosted") {
43+
# Get the installed version of Node.js
44+
$nodeVersion = Invoke-Expression "node --version"
45+
# Check if Node.js is installed
46+
$nodeVersion | Should -Not -BeNullOrEmpty
47+
# Check if the installed version of Node.js is the expected version
48+
$nodeVersion | Should -Match $env:VERSION
49+
}else {
50+
# Analyze output of previous steps to check if Node.js was consumed from cache or downloaded
51+
$useNodeLogFile = Get-UseNodeLogs
52+
$useNodeLogFile | Should -Exist
53+
$useNodeLogContent = Get-Content $useNodeLogFile -Raw
54+
$useNodeLogContent | Should -Match "Found in cache"
55+
}
56+
}
57+
4558
It "Run simple code" {
4659
"node ./simple-test.js" | Should -ReturnZeroExitCode
4760
}
48-
}
61+
}

0 commit comments

Comments
 (0)