|
6 | 6 | isRelative, |
7 | 7 | normalizePath, |
8 | 8 | pathLikeToString, |
| 9 | + relativeResolve, |
9 | 10 | splitPath, |
10 | 11 | trimLeadingDotSlash, |
11 | 12 | } from '../../registry/dist/lib/path.js' |
@@ -227,4 +228,52 @@ describe('path module', () => { |
227 | 228 | expect(pathLikeToString('')).toBe('') |
228 | 229 | }) |
229 | 230 | }) |
| 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 | + }) |
230 | 279 | }) |
0 commit comments