Skip to content

Commit f184424

Browse files
jdaltonclaude
andcommitted
Add tests for relativeResolve function
Add comprehensive test coverage for the previously untested relativeResolve function. This improves path.ts function coverage from 90.9% to 100%. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent cd31464 commit f184424

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

test/registry/path.test.mts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
isRelative,
77
normalizePath,
88
pathLikeToString,
9+
relativeResolve,
910
splitPath,
1011
trimLeadingDotSlash,
1112
} from '../../registry/dist/lib/path.js'
@@ -227,4 +228,52 @@ describe('path module', () => {
227228
expect(pathLikeToString('')).toBe('')
228229
})
229230
})
231+
232+
describe('relativeResolve', () => {
233+
it('should resolve relative path between two paths', () => {
234+
const from = '/path/to/from'
235+
const to = '/path/to/target'
236+
expect(relativeResolve(from, to)).toBe('../target')
237+
})
238+
239+
it('should resolve when paths are in same directory', () => {
240+
const from = '/path/to/dir'
241+
const to = '/path/to/file'
242+
expect(relativeResolve(from, to)).toBe('../file')
243+
})
244+
245+
it('should resolve when target is ancestor', () => {
246+
const from = '/path/to/deep/nested'
247+
const to = '/path/to'
248+
expect(relativeResolve(from, to)).toBe('../..')
249+
})
250+
251+
it('should resolve when target is descendant', () => {
252+
const from = '/path/to'
253+
const to = '/path/to/deep/nested'
254+
expect(relativeResolve(from, to)).toBe('deep/nested')
255+
})
256+
257+
it('should handle relative paths as input', () => {
258+
const from = 'src/lib'
259+
const to = 'src/test'
260+
expect(relativeResolve(from, to)).toBe('../test')
261+
})
262+
263+
it('should handle same path', () => {
264+
const path = '/path/to/file'
265+
expect(relativeResolve(path, path)).toBe('')
266+
})
267+
268+
it('should handle root paths', () => {
269+
expect(relativeResolve('/', '/path')).toBe('path')
270+
})
271+
272+
it('should handle current directory', () => {
273+
const from = './src'
274+
const to = './lib'
275+
const result = relativeResolve(from, to)
276+
expect(result).toBeDefined()
277+
})
278+
})
230279
})

0 commit comments

Comments
 (0)