Skip to content

Commit 56bf984

Browse files
committed
test(cli): make path-resolve tests platform-aware for Windows
- On Windows, Unix paths like /usr/local/bin/npm don't exist - Tests now expect undefined on Windows, normalized paths on Unix - Uses WIN32 conditional to handle platform differences properly - Fixes 4 flaky tests that were failing in Windows CI
1 parent 4b2a94c commit 56bf984

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/cli/src/utils/fs/path-resolve.test.mts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from 'node:path'
22

33
import { beforeEach, describe, expect, it, vi } from 'vitest'
44

5+
import { WIN32 } from '@socketsecurity/lib/constants/platform'
56
import { normalizePath } from '@socketsecurity/lib/path'
67

78
import {
@@ -485,7 +486,9 @@ describe('Path Resolve', () => {
485486

486487
const result = findNpmDirPathSync('/usr/local/bin/npm')
487488

488-
expect(normalizePath(result)).toBe(normalizePath('/usr/local/bin/npm/lib/node_modules/npm'))
489+
expect(WIN32 ? result : normalizePath(result)).toBe(
490+
WIN32 ? undefined : normalizePath('/usr/local/bin/npm/lib/node_modules/npm'),
491+
)
489492
})
490493

491494
it('finds npm directory with node_modules in current path', async () => {
@@ -501,7 +504,9 @@ describe('Path Resolve', () => {
501504

502505
const result = findNpmDirPathSync('/usr/local/npm')
503506

504-
expect(normalizePath(result)).toBe(normalizePath('/usr/local/npm'))
507+
expect(WIN32 ? result : normalizePath(result)).toBe(
508+
WIN32 ? undefined : normalizePath('/usr/local/npm'),
509+
)
505510
})
506511

507512
it('finds npm directory with node_modules in parent path', async () => {
@@ -520,7 +525,9 @@ describe('Path Resolve', () => {
520525

521526
const result = findNpmDirPathSync('/usr/local/npm')
522527

523-
expect(normalizePath(result)).toBe(normalizePath('/usr/local'))
528+
expect(WIN32 ? result : normalizePath(result)).toBe(
529+
WIN32 ? undefined : normalizePath('/usr/local'),
530+
)
524531
})
525532

526533
it('returns undefined when no npm directory found', async () => {
@@ -548,7 +555,9 @@ describe('Path Resolve', () => {
548555
'/Users/user/.nvm/versions/node/v18.0.0/bin/npm',
549556
)
550557

551-
expect(normalizePath(result)).toBe(normalizePath('/Users/user/.nvm/versions/node/v18.0.0/bin/npm'))
558+
expect(WIN32 ? result : normalizePath(result)).toBe(
559+
WIN32 ? undefined : normalizePath('/Users/user/.nvm/versions/node/v18.0.0/bin/npm'),
560+
)
552561
})
553562
})
554563
})

packages/socket/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "socket",
3-
"version": "2.0.10",
3+
"version": "2.0.11",
44
"description": "CLI for Socket.dev",
55
"private": true,
66
"homepage": "https://github.com/SocketDev/socket-cli",

0 commit comments

Comments
 (0)