11import { describe , expect , it } from "vitest" ;
2- import { applyBasePath , joinPath , removeBasePath } from "./path" ;
2+ import { joinPath , removeBasePath } from "./path" ;
33
44describe ( "joinPath" , ( ) => {
55 it ( "should join base and path with single slash" , ( ) => {
@@ -24,25 +24,58 @@ describe("joinPath", () => {
2424 expect ( joinPath ( "" , "/foo" ) ) . toBe ( "/foo" ) ;
2525 expect ( joinPath ( "" , "foo" ) ) . toBe ( "/foo" ) ;
2626 } ) ;
27- } ) ;
2827
29- describe ( "applyBasePath" , ( ) => {
30- it ( "should apply basePath to absolute path" , ( ) => {
31- expect ( applyBasePath ( "/base" , "/foo" ) ) . toBe ( "/base/foo" ) ;
32- expect ( applyBasePath ( "/foo" , "/bar/baz" ) ) . toBe ( "/foo/bar/baz" ) ;
28+ it ( "should join multiple parts" , ( ) => {
29+ expect ( joinPath ( "/base" , "foo" , "bar" ) ) . toBe ( "/base/foo/bar" ) ;
30+ expect ( joinPath ( "/" , "foo" , "bar" ) ) . toBe ( "/foo/bar" ) ;
31+ expect ( joinPath ( "" , "foo" , "bar" ) ) . toBe ( "/foo/bar" ) ;
32+ expect ( joinPath ( "/base/" , "/foo/" , "/bar/" ) ) . toBe ( "/base/foo/bar/" ) ;
3333 } ) ;
3434
35- it ( "should not apply basePath to relative path" , ( ) => {
36- expect ( applyBasePath ( "/base" , "./index.html" ) ) . toBe ( "./index.html" ) ;
37- expect ( applyBasePath ( "/foo/bar" , "baz/qux" ) ) . toBe ( "baz/qux" ) ;
35+ it ( "should handle parts with trailing and leading slashes" , ( ) => {
36+ expect ( joinPath ( "/base/" , "/foo/" , "/bar/" ) ) . toBe ( "/base/foo/bar/" ) ;
37+ expect ( joinPath ( "/base/" , "foo/" , "/bar" ) ) . toBe ( "/base/foo/bar" ) ;
38+ expect ( joinPath ( "/base" , "foo/" , "bar/" ) ) . toBe ( "/base/foo/bar/" ) ;
3839 } ) ;
3940
40- it ( "should handle root basePath" , ( ) => {
41- expect ( applyBasePath ( "/" , "/foo" ) ) . toBe ( "/foo" ) ;
41+ it ( "should handle parts with only slashes" , ( ) => {
42+ expect ( joinPath ( "/" , "/" , "/" ) ) . toBe ( "/" ) ;
43+ expect ( joinPath ( "/" , "" , "/foo" ) ) . toBe ( "/foo" ) ;
4244 } ) ;
4345
44- it ( "should handle empty basePath" , ( ) => {
45- expect ( applyBasePath ( "" , "/foo" ) ) . toBe ( "/foo" ) ;
46+ it ( "should preserve trailing slash if last part has it" , ( ) => {
47+ expect ( joinPath ( "/base" , "foo/" , "bar/" ) ) . toBe ( "/base/foo/bar/" ) ;
48+ expect ( joinPath ( "/base" , "foo" , "bar/" ) ) . toBe ( "/base/foo/bar/" ) ;
49+ } ) ;
50+
51+ it ( "should handle special paths with leading slash" , ( ) => {
52+ expect ( joinPath ( "/base" , "/@" ) ) . toBe ( "/base/@" ) ;
53+ expect ( joinPath ( "/base" , "/node_modules" ) ) . toBe ( "/base/node_modules" ) ;
54+ } ) ;
55+
56+ it ( "should remove duplicate slashes safely" , ( ) => {
57+ expect ( joinPath ( "/base//" , "/foo//bar/" ) ) . toBe ( "/base/foo/bar/" ) ;
58+ expect ( joinPath ( "//" , "/foo//" , "/bar//baz//" ) ) . toBe ( "/foo/bar/baz/" ) ;
59+ expect ( joinPath ( "/" , "/" , "/foo//bar//baz/" ) ) . toBe ( "/foo/bar/baz/" ) ;
60+ expect ( joinPath ( "/base//" , "//foo//" , "//bar//" ) ) . toBe ( "/base/foo/bar/" ) ;
61+ expect ( joinPath ( "base//" , "/foo//bar/" ) ) . toBe ( "base/foo/bar/" ) ;
62+ expect ( joinPath ( "base//" , "foo//bar/" ) ) . toBe ( "base/foo/bar/" ) ;
63+ expect ( joinPath ( "/base//" , "foo//bar" ) ) . toBe ( "/base/foo/bar" ) ;
64+ expect ( joinPath ( "base//" , "foo//bar" ) ) . toBe ( "base/foo/bar" ) ;
65+ } ) ;
66+
67+ it ( "should handle only slash and empty" , ( ) => {
68+ expect ( joinPath ( "/" ) ) . toBe ( "/" ) ;
69+ expect ( joinPath ( "" , "/" ) ) . toBe ( "/" ) ;
70+ expect ( joinPath ( "" , "" ) ) . toBe ( "" ) ;
71+ } ) ;
72+
73+ it ( "should handle mix of empty, slash, and normal parts" , ( ) => {
74+ expect ( joinPath ( "" , "/" , "foo" ) ) . toBe ( "/foo" ) ;
75+ expect ( joinPath ( "" , "foo" , "" ) ) . toBe ( "/foo/" ) ;
76+ expect ( joinPath ( "" , "foo" , "/" ) ) . toBe ( "/foo/" ) ;
77+ expect ( joinPath ( "/" , "" , "foo" ) ) . toBe ( "/foo" ) ;
78+ expect ( joinPath ( "/" , "foo" , "" ) ) . toBe ( "/foo/" ) ;
4679 } ) ;
4780} ) ;
4881
0 commit comments