1
1
Import-Module (Join-Path $PSScriptRoot " ../helpers/pester-extensions.psm1" )
2
2
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
+
16
4
17
5
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
+
18
21
It " is available" {
19
22
" node --version" | Should - ReturnZeroExitCode
20
23
}
@@ -34,15 +37,25 @@ Describe "Node.js" {
34
37
$nodePath.startsWith ($expectedPath ) | Should - BeTrue - Because " '$nodePath ' is not started with '$expectedPath '"
35
38
}
36
39
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" {
44
41
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
+
45
58
It " Run simple code" {
46
59
" node ./simple-test.js" | Should - ReturnZeroExitCode
47
60
}
48
- }
61
+ }
0 commit comments