Skip to content

Commit f711c7a

Browse files
cursoragentbolens
andcommitted
fix(test): guard npm module path lookup when HOME is unset
Windows CI runners often lack HOME, which made Join-Path throw inside Get-TestNodeModuleSearchPaths and fail binary conversion integration tests before they could skip missing npm packages. Fall back to USERPROFILE and skip null base paths instead. Co-authored-by: Michael Bolens <bolens@users.noreply.github.com>
1 parent f2c8ad3 commit f711c7a

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

tests/TestSupport/TestNpmHelpers.ps1

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,20 @@ function Get-TestNodeModuleSearchPaths {
3939
}
4040
}
4141

42-
foreach ($candidate in @(
43-
"$env:LOCALAPPDATA\pnpm\global\5\node_modules"
44-
(Join-Path $env:HOME '.local/share/pnpm/global/5/node_modules')
45-
)) {
42+
$fallbackCandidates = @()
43+
if ($env:LOCALAPPDATA) {
44+
$fallbackCandidates += Join-Path $env:LOCALAPPDATA 'pnpm\global\5\node_modules'
45+
}
46+
47+
$homeDirectory = $env:HOME
48+
if ([string]::IsNullOrWhiteSpace($homeDirectory)) {
49+
$homeDirectory = $env:USERPROFILE
50+
}
51+
if (-not [string]::IsNullOrWhiteSpace($homeDirectory)) {
52+
$fallbackCandidates += Join-Path $homeDirectory '.local/share/pnpm/global/5/node_modules'
53+
}
54+
55+
foreach ($candidate in $fallbackCandidates) {
4656
if ($candidate -and (Test-Path -LiteralPath $candidate)) {
4757
$paths.Add($candidate)
4858
}
@@ -73,6 +83,10 @@ function Get-TestNodeModuleSearchPaths {
7383
}
7484

7585
foreach ($repoRoot in @($repoRoots | Select-Object -Unique)) {
86+
if ([string]::IsNullOrWhiteSpace($repoRoot)) {
87+
continue
88+
}
89+
7690
$localModules = Join-Path $repoRoot 'node_modules'
7791
if (Test-Path -LiteralPath $localModules) {
7892
$paths.Add($localModules)

tests/unit/test-support/test-support.tests.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,24 @@ Describe 'TestSupport Modules' {
418418
}
419419

420420
Describe 'TestNpmHelpers Module' {
421+
Context 'Get-TestNodeModuleSearchPaths' {
422+
It 'Does not throw when HOME is unset on Windows-style environments' {
423+
$originalHome = $env:HOME
424+
try {
425+
Remove-Item Env:HOME -ErrorAction SilentlyContinue
426+
{ $null = Get-TestNodeModuleSearchPaths } | Should -Not -Throw
427+
}
428+
finally {
429+
if ($null -ne $originalHome) {
430+
$env:HOME = $originalHome
431+
}
432+
else {
433+
Remove-Item Env:HOME -ErrorAction SilentlyContinue
434+
}
435+
}
436+
}
437+
}
438+
421439
Context 'Test-NpmPackageAvailable' {
422440
It 'Returns false when package is not available' {
423441
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {

0 commit comments

Comments
 (0)