Skip to content

Commit 2bf5d34

Browse files
committed
fix(test): make getCommonAncestor tests cross-platform
Tests were using hardcoded POSIX paths which fail on Windows because path.resolve() converts them to Windows-style paths. Now using path.join() and endsWith() assertions for portability.
1 parent 294660b commit 2bf5d34

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/utils/path-helpers.test.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,29 @@ ava('getCommonAncestor - empty array', (t) => {
157157
})
158158

159159
ava('getCommonAncestor - single path', (t) => {
160-
const result = getCommonAncestor(['/home/user/file.txt'])
161-
t.is(result, '/home/user')
160+
// Use platform-appropriate paths
161+
const file = path.join('home', 'user', 'file.txt')
162+
const result = getCommonAncestor([file])
163+
// path.resolve will make these absolute, so check the result ends correctly
164+
t.true(result?.endsWith(path.join('home', 'user')) ?? false)
162165
})
163166

164167
ava('getCommonAncestor - sibling files', (t) => {
165-
const result = getCommonAncestor(['/home/user/a.txt', '/home/user/b.txt'])
166-
t.is(result, '/home/user')
168+
// Use platform-appropriate paths
169+
const file1 = path.join('home', 'user', 'a.txt')
170+
const file2 = path.join('home', 'user', 'b.txt')
171+
const result = getCommonAncestor([file1, file2])
172+
// path.resolve will make these absolute, so check the result ends correctly
173+
t.true(result?.endsWith(path.join('home', 'user')) ?? false)
167174
})
168175

169176
ava('getCommonAncestor - different directories', (t) => {
170-
const result = getCommonAncestor(['/home/user/docs/a.txt', '/home/user/images/b.png'])
171-
t.is(result, '/home/user')
177+
// Use platform-appropriate paths
178+
const file1 = path.join('home', 'user', 'docs', 'a.txt')
179+
const file2 = path.join('home', 'user', 'images', 'b.png')
180+
const result = getCommonAncestor([file1, file2])
181+
// path.resolve will make these absolute, so check the result ends correctly
182+
t.true(result?.endsWith(path.join('home', 'user')) ?? false)
172183
})
173184

174185
// ============================================================================

0 commit comments

Comments
 (0)