Skip to content

Commit ef13d72

Browse files
committed
Normalize expected paths in tests for Windows compatibility
Path functions now return normalized paths with forward slashes on all platforms. Updated test expectations to use normalizePath() for consistent assertions across Windows and POSIX systems.
1 parent 8d7c9b0 commit ef13d72

File tree

3 files changed

+53
-28
lines changed

3 files changed

+53
-28
lines changed

test/registry/edge-cases.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('edge case tests', () => {
3232
await fs.writeFile(testFile, '{}')
3333

3434
const result = await fsUtils.findUp('package.json', { cwd: tmpDir })
35-
expect(result).toBe(testFile)
35+
expect(result).toBe(normalizePath(testFile))
3636
})
3737

3838
it('should handle findUpSync edge cases', () => {
@@ -84,7 +84,7 @@ describe('edge case tests', () => {
8484
it('should handle uniqueSync with directories', () => {
8585
const dirPath = path.join(tmpDir, 'mydir')
8686
const unique1 = fsUtils.uniqueSync(dirPath)
87-
expect(unique1).toBe(dirPath)
87+
expect(unique1).toBe(normalizePath(dirPath))
8888

8989
// Create the directory
9090
require('node:fs').mkdirSync(dirPath)

test/registry/fs.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ describe('fs module', () => {
387387
it('should return same path if not exists', () => {
388388
const uniquePath = path.join(tmpDir, 'unique.txt')
389389
const result = uniqueSync(uniquePath)
390-
expect(result).toBe(uniquePath)
390+
expect(result).toBe(normalizePath(uniquePath))
391391
})
392392

393393
it('should add number suffix for existing files', () => {

test/registry/paths.test.mts

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path'
33

44
import { describe, expect, it } from 'vitest'
55

6+
import { normalizePath } from '../../registry/dist/lib/path.js'
67
import {
78
getSocketAppCacheDir,
89
getSocketAppCacheTtlDir,
@@ -19,7 +20,7 @@ describe('paths module', () => {
1920
describe('getSocketUserDir', () => {
2021
it('should return ~/.socket path', () => {
2122
const result = getSocketUserDir()
22-
expect(result).toBe(path.join(os.homedir(), '.socket'))
23+
expect(result).toBe(normalizePath(path.join(os.homedir(), '.socket')))
2324
})
2425

2526
it('should return consistent path on multiple calls', () => {
@@ -32,45 +33,57 @@ describe('paths module', () => {
3233
describe('getSocketAppDir', () => {
3334
it('should return app directory with underscore prefix', () => {
3435
const result = getSocketAppDir('test')
35-
expect(result).toBe(path.join(os.homedir(), '.socket', '_test'))
36+
expect(result).toBe(
37+
normalizePath(path.join(os.homedir(), '.socket', '_test')),
38+
)
3639
})
3740

3841
it('should handle different app names', () => {
3942
const socket = getSocketAppDir('socket')
4043
const registry = getSocketAppDir('registry')
41-
expect(socket).toBe(path.join(os.homedir(), '.socket', '_socket'))
42-
expect(registry).toBe(path.join(os.homedir(), '.socket', '_registry'))
44+
expect(socket).toBe(
45+
normalizePath(path.join(os.homedir(), '.socket', '_socket')),
46+
)
47+
expect(registry).toBe(
48+
normalizePath(path.join(os.homedir(), '.socket', '_registry')),
49+
)
4350
})
4451
})
4552

4653
describe('getSocketCacacheDir', () => {
4754
it('should return cacache directory', () => {
4855
const result = getSocketCacacheDir()
49-
expect(result).toBe(path.join(os.homedir(), '.socket', '_cacache'))
56+
expect(result).toBe(
57+
normalizePath(path.join(os.homedir(), '.socket', '_cacache')),
58+
)
5059
})
5160
})
5261

5362
describe('getSocketDlxDir', () => {
5463
it('should return dlx directory', () => {
5564
const result = getSocketDlxDir()
56-
expect(result).toBe(path.join(os.homedir(), '.socket', '_dlx'))
65+
expect(result).toBe(
66+
normalizePath(path.join(os.homedir(), '.socket', '_dlx')),
67+
)
5768
})
5869
})
5970

6071
describe('getSocketAppCacheDir', () => {
6172
it('should return app cache directory', () => {
6273
const result = getSocketAppCacheDir('test')
63-
expect(result).toBe(path.join(os.homedir(), '.socket', '_test', 'cache'))
74+
expect(result).toBe(
75+
normalizePath(path.join(os.homedir(), '.socket', '_test', 'cache')),
76+
)
6477
})
6578

6679
it('should handle different app names', () => {
6780
const socketCache = getSocketAppCacheDir('socket')
6881
const registryCache = getSocketAppCacheDir('registry')
6982
expect(socketCache).toBe(
70-
path.join(os.homedir(), '.socket', '_socket', 'cache'),
83+
normalizePath(path.join(os.homedir(), '.socket', '_socket', 'cache')),
7184
)
7285
expect(registryCache).toBe(
73-
path.join(os.homedir(), '.socket', '_registry', 'cache'),
86+
normalizePath(path.join(os.homedir(), '.socket', '_registry', 'cache')),
7487
)
7588
})
7689
})
@@ -79,47 +92,59 @@ describe('paths module', () => {
7992
it('should return app TTL cache directory', () => {
8093
const result = getSocketAppCacheTtlDir('test')
8194
expect(result).toBe(
82-
path.join(os.homedir(), '.socket', '_test', 'cache', 'ttl'),
95+
normalizePath(
96+
path.join(os.homedir(), '.socket', '_test', 'cache', 'ttl'),
97+
),
8398
)
8499
})
85100

86101
it('should handle different app names', () => {
87102
const socketTtl = getSocketAppCacheTtlDir('socket')
88103
const registryTtl = getSocketAppCacheTtlDir('registry')
89104
expect(socketTtl).toBe(
90-
path.join(os.homedir(), '.socket', '_socket', 'cache', 'ttl'),
105+
normalizePath(
106+
path.join(os.homedir(), '.socket', '_socket', 'cache', 'ttl'),
107+
),
91108
)
92109
expect(registryTtl).toBe(
93-
path.join(os.homedir(), '.socket', '_registry', 'cache', 'ttl'),
110+
normalizePath(
111+
path.join(os.homedir(), '.socket', '_registry', 'cache', 'ttl'),
112+
),
94113
)
95114
})
96115
})
97116

98117
describe('getSocketCliDir', () => {
99118
it('should return CLI directory', () => {
100119
const result = getSocketCliDir()
101-
expect(result).toBe(path.join(os.homedir(), '.socket', '_socket'))
120+
expect(result).toBe(
121+
normalizePath(path.join(os.homedir(), '.socket', '_socket')),
122+
)
102123
})
103124
})
104125

105126
describe('getSocketRegistryDir', () => {
106127
it('should return Registry directory', () => {
107128
const result = getSocketRegistryDir()
108-
expect(result).toBe(path.join(os.homedir(), '.socket', '_registry'))
129+
expect(result).toBe(
130+
normalizePath(path.join(os.homedir(), '.socket', '_registry')),
131+
)
109132
})
110133
})
111134

112135
describe('getSocketRegistryGithubCacheDir', () => {
113136
it('should return Registry GitHub cache directory', () => {
114137
const result = getSocketRegistryGithubCacheDir()
115138
expect(result).toBe(
116-
path.join(
117-
os.homedir(),
118-
'.socket',
119-
'_registry',
120-
'cache',
121-
'ttl',
122-
'github',
139+
normalizePath(
140+
path.join(
141+
os.homedir(),
142+
'.socket',
143+
'_registry',
144+
'cache',
145+
'ttl',
146+
'github',
147+
),
123148
),
124149
)
125150
})
@@ -158,14 +183,14 @@ describe('paths module', () => {
158183
})
159184

160185
describe('platform compatibility', () => {
161-
it('should use correct path separators', () => {
186+
it('should use normalized forward slashes', () => {
162187
const result = getSocketAppDir('test')
163-
expect(result.includes(path.sep)).toBe(true)
188+
expect(result.includes('/')).toBe(true)
164189
})
165190

166-
it('should not contain hardcoded slashes', () => {
191+
it('should normalize paths correctly', () => {
167192
const result = getSocketUserDir()
168-
const parts = result.split(path.sep)
193+
const parts = result.split('/')
169194
expect(parts[parts.length - 1]).toBe('.socket')
170195
})
171196
})

0 commit comments

Comments
 (0)