Skip to content

Commit 2559eb7

Browse files
committed
fix(test): normalize expected paths in cross-platform tests
The utils functions use normalizePath() which converts all backslashes to forward slashes. Tests were comparing against path.resolve() and path.join() which preserve native separators, causing failures on Windows CI. Solution: Wrap expected path values with normalizePath() to match the actual output format (forward slashes on all platforms).
1 parent a1bd04e commit 2559eb7

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

test/unit/utils.test.mts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import path from 'node:path'
1414

1515
import { describe, expect, it } from 'vitest'
1616

17+
import { normalizePath } from '@socketsecurity/lib/path'
18+
1719
import {
1820
createRequestBodyForJson,
1921
normalizeBaseUrl,
@@ -76,7 +78,7 @@ describe('Path Resolution', () => {
7678

7779
it('should return absolute path unchanged', () => {
7880
// Use a truly absolute path for cross-platform testing
79-
const absolutePath = path.resolve('/tmp/test')
81+
const absolutePath = normalizePath(path.resolve('/tmp/test'))
8082
const result = resolveBasePath(absolutePath)
8183
expect(result).toBe(absolutePath)
8284
})
@@ -100,8 +102,8 @@ describe('Path Resolution', () => {
100102

101103
it('should handle absolute paths in array', () => {
102104
// Use truly absolute paths for cross-platform testing
103-
const path1 = path.resolve('/tmp/test.txt')
104-
const path2 = path.resolve('/var/log/app.log')
105+
const path1 = normalizePath(path.resolve('/tmp/test.txt'))
106+
const path2 = normalizePath(path.resolve('/var/log/app.log'))
105107
const paths = [path1, path2]
106108
const result = resolveAbsPaths(paths)
107109

@@ -110,12 +112,12 @@ describe('Path Resolution', () => {
110112

111113
it('should resolve relative to specified base path', () => {
112114
const paths = ['file1.txt', 'file2.txt']
113-
const basePath = path.resolve('/custom/base')
115+
const basePath = normalizePath(path.resolve('/custom/base'))
114116
const result = resolveAbsPaths(paths, basePath)
115117

116118
expect(result).toHaveLength(2)
117-
expect(result[0]).toBe(path.join(basePath, 'file1.txt'))
118-
expect(result[1]).toBe(path.join(basePath, 'file2.txt'))
119+
expect(result[0]).toBe(normalizePath(path.join(basePath, 'file1.txt')))
120+
expect(result[1]).toBe(normalizePath(path.join(basePath, 'file2.txt')))
119121
})
120122

121123
it('should handle empty array', () => {
@@ -124,12 +126,12 @@ describe('Path Resolution', () => {
124126
})
125127

126128
it('should handle mixed absolute and relative paths', () => {
127-
const basePath = path.resolve('/base')
128-
const absolutePath = path.resolve('/absolute.txt')
129+
const basePath = normalizePath(path.resolve('/base'))
130+
const absolutePath = normalizePath(path.resolve('/absolute.txt'))
129131
const paths = ['./relative.txt', absolutePath]
130132
const result = resolveAbsPaths(paths, basePath)
131133

132-
expect(result[0]).toBe(path.join(basePath, 'relative.txt'))
134+
expect(result[0]).toBe(normalizePath(path.join(basePath, 'relative.txt')))
133135
expect(result[1]).toBe(absolutePath)
134136
})
135137
})

0 commit comments

Comments
 (0)