11import { describe , expect , it } from "bun:test"
22
33import {
4- // Legacy aliases
5- addHttp ,
6- addProtocol ,
7- getBaseUrl ,
8- getDomain ,
9- getQueryParams ,
10- getUrlHostname ,
11- isExternalUrl ,
12- isLocalhostUrl ,
13- isValidUrl ,
14- joinUrlPaths ,
15- normalizeUrl ,
16- removeHttp ,
17- removeProtocol ,
18- removeQueryParams ,
19- removeTrailingSlash ,
20- setQueryParams ,
21- stripTrailingSlash ,
22- stripURLSubpath
4+ addHttp ,
5+ addProtocol ,
6+ getBaseUrl ,
7+ getDomain ,
8+ getQueryParams ,
9+ getUrlHostname ,
10+ isExternalUrl ,
11+ isLocalhostUrl ,
12+ isValidUrl ,
13+ joinUrlPaths ,
14+ normalizeUrl ,
15+ removeHttp ,
16+ removeProtocol ,
17+ removeQueryParams ,
18+ removeTrailingSlash ,
19+ setQueryParams ,
20+ stripTrailingSlash ,
21+ stripURLSubpath ,
2322} from "./http"
2423
2524describe ( "isValidUrl" , ( ) => {
@@ -29,6 +28,14 @@ describe("isValidUrl", () => {
2928 expect ( isValidUrl ( "https://www.example.com/path?query=value#hash" ) ) . toBe ( true )
3029 } )
3130
31+ it ( "validates URLs with longer TLDs" , ( ) => {
32+ expect ( isValidUrl ( "https://example.storage" ) ) . toBe ( true )
33+ expect ( isValidUrl ( "https://mysite.directory" ) ) . toBe ( true )
34+ expect ( isValidUrl ( "http://www.example.storage" ) ) . toBe ( true )
35+ expect ( isValidUrl ( "https://api.myapp.directory/path" ) ) . toBe ( true )
36+ expect ( isValidUrl ( "https://subdomain.example.storage?param=value" ) ) . toBe ( true )
37+ } )
38+
3239 it ( "rejects invalid URLs" , ( ) => {
3340 expect ( isValidUrl ( "not a url" ) ) . toBe ( false )
3441 expect ( isValidUrl ( "example.com" ) ) . toBe ( false )
@@ -111,41 +118,39 @@ describe("normalizeUrl", () => {
111118 expect ( normalizeUrl ( ) ) . toBe ( "" )
112119 expect ( normalizeUrl ( "" ) ) . toBe ( "" )
113120 } )
114- } )
115121
116- describe ( "stripTrailingSlash" , ( ) => {
117122 it ( "removes trailing slash from URL" , ( ) => {
118123 const url = "https://example.com/"
119124 const expected = "https://example.com"
120- expect ( stripTrailingSlash ( url ) ) . toBe ( expected )
125+ expect ( normalizeUrl ( url ) ) . toBe ( expected )
121126 } )
122127
123128 it ( "removes trailing slash from URL with path" , ( ) => {
124129 const url = "https://example.com/path/"
125130 const expected = "https://example.com/path"
126- expect ( stripTrailingSlash ( url ) ) . toBe ( expected )
131+ expect ( normalizeUrl ( url ) ) . toBe ( expected )
127132 } )
128133
129134 it ( "does not remove slash from root URL" , ( ) => {
130135 const url = "/"
131136 const expected = "/"
132- expect ( stripTrailingSlash ( url ) ) . toBe ( expected )
137+ expect ( normalizeUrl ( url ) ) . toBe ( expected )
133138 } )
134139
135140 it ( "returns URL unchanged when no trailing slash" , ( ) => {
136141 const url = "https://example.com/path"
137142 const expected = "https://example.com/path"
138- expect ( stripTrailingSlash ( url ) ) . toBe ( expected )
143+ expect ( normalizeUrl ( url ) ) . toBe ( expected )
139144 } )
140145
141146 it ( "returns empty string for undefined input" , ( ) => {
142- expect ( stripTrailingSlash ( ) ) . toBe ( "" )
147+ expect ( normalizeUrl ( ) ) . toBe ( "" )
143148 } )
144149
145150 it ( "handles URLs with query parameters and trailing slash" , ( ) => {
146151 const url = "https://example.com/path/?param=value"
147152 const expected = "https://example.com/path?param=value"
148- expect ( stripTrailingSlash ( url ) ) . toBe ( expected )
153+ expect ( normalizeUrl ( url ) ) . toBe ( expected )
149154 } )
150155} )
151156
0 commit comments