1010 * - create-request-body-json.test.mts
1111 */
1212
13+ import path from 'node:path'
14+
1315import { describe , expect , it } from 'vitest'
1416
17+ import { normalizePath } from '@socketsecurity/lib/path'
18+
1519import {
1620 createRequestBodyForJson ,
1721 normalizeBaseUrl ,
@@ -63,7 +67,7 @@ describe('Path Resolution', () => {
6367 it ( 'should resolve relative path to absolute' , ( ) => {
6468 const result = resolveBasePath ( '.' )
6569 expect ( result ) . toContain ( 'socket-sdk-js' )
66- expect ( result . startsWith ( '/' ) ) . toBe ( true )
70+ expect ( path . isAbsolute ( result ) ) . toBe ( true )
6771 } )
6872
6973 it ( 'should resolve nested relative path' , ( ) => {
@@ -73,9 +77,10 @@ describe('Path Resolution', () => {
7377 } )
7478
7579 it ( 'should return absolute path unchanged' , ( ) => {
76- const absolutePath = '/tmp/test'
80+ // Use a truly absolute path for cross-platform testing
81+ const absolutePath = normalizePath ( path . resolve ( '/tmp/test' ) )
7782 const result = resolveBasePath ( absolutePath )
78- expect ( result ) . toBe ( '/tmp/test' )
83+ expect ( result ) . toBe ( absolutePath )
7984 } )
8085
8186 it ( 'should default to cwd when no argument provided' , ( ) => {
@@ -92,23 +97,27 @@ describe('Path Resolution', () => {
9297 expect ( result ) . toHaveLength ( 2 )
9398 expect ( result [ 0 ] ) . toContain ( 'socket-sdk-js/package.json' )
9499 expect ( result [ 1 ] ) . toContain ( 'socket-sdk-js/src/index.ts' )
95- result . forEach ( p => expect ( p . startsWith ( '/' ) ) . toBe ( true ) )
100+ result . forEach ( p => expect ( path . isAbsolute ( p ) ) . toBe ( true ) )
96101 } )
97102
98103 it ( 'should handle absolute paths in array' , ( ) => {
99- const paths = [ '/tmp/test.txt' , '/var/log/app.log' ]
104+ // Use truly absolute paths for cross-platform testing
105+ const path1 = normalizePath ( path . resolve ( '/tmp/test.txt' ) )
106+ const path2 = normalizePath ( path . resolve ( '/var/log/app.log' ) )
107+ const paths = [ path1 , path2 ]
100108 const result = resolveAbsPaths ( paths )
101109
102- expect ( result ) . toEqual ( [ '/tmp/test.txt' , '/var/log/app.log' ] )
110+ expect ( result ) . toEqual ( [ path1 , path2 ] )
103111 } )
104112
105113 it ( 'should resolve relative to specified base path' , ( ) => {
106114 const paths = [ 'file1.txt' , 'file2.txt' ]
107- const result = resolveAbsPaths ( paths , '/custom/base' )
115+ const basePath = normalizePath ( path . resolve ( '/custom/base' ) )
116+ const result = resolveAbsPaths ( paths , basePath )
108117
109118 expect ( result ) . toHaveLength ( 2 )
110- expect ( result [ 0 ] ) . toBe ( '/custom/base/ file1.txt')
111- expect ( result [ 1 ] ) . toBe ( '/custom/base/ file2.txt')
119+ expect ( result [ 0 ] ) . toBe ( normalizePath ( path . join ( basePath , ' file1.txt') ) )
120+ expect ( result [ 1 ] ) . toBe ( normalizePath ( path . join ( basePath , ' file2.txt') ) )
112121 } )
113122
114123 it ( 'should handle empty array' , ( ) => {
@@ -117,11 +126,13 @@ describe('Path Resolution', () => {
117126 } )
118127
119128 it ( 'should handle mixed absolute and relative paths' , ( ) => {
120- const paths = [ './relative.txt' , '/absolute.txt' ]
121- const result = resolveAbsPaths ( paths , '/base' )
129+ const basePath = normalizePath ( path . resolve ( '/base' ) )
130+ const absolutePath = normalizePath ( path . resolve ( '/absolute.txt' ) )
131+ const paths = [ './relative.txt' , absolutePath ]
132+ const result = resolveAbsPaths ( paths , basePath )
122133
123- expect ( result [ 0 ] ) . toBe ( '/base/ relative.txt')
124- expect ( result [ 1 ] ) . toBe ( '/absolute.txt' )
134+ expect ( result [ 0 ] ) . toBe ( normalizePath ( path . join ( basePath , ' relative.txt') ) )
135+ expect ( result [ 1 ] ) . toBe ( absolutePath )
125136 } )
126137 } )
127138} )
0 commit comments