@@ -4,7 +4,7 @@ import { networkInterfaces } from 'node:os'
44
55import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
66
7- import { copyURL , getNetworkAddresses , listen , openBrowser , resolveOpenCommand , validateHostname } from '../../src/dev/listen'
7+ import { copyURL , formatDisplayURL , getNetworkAddresses , listen , openBrowser , resolveOpenCommand , validateHostname } from '../../src/dev/listen'
88
99const writeText = vi . hoisted ( ( ) => vi . fn ( ) )
1010
@@ -62,6 +62,31 @@ describe('getNetworkAddresses', () => {
6262 } )
6363} )
6464
65+ describe ( 'formatDisplayURL' , ( ) => {
66+ it ( 'should include a non-default port' , ( ) => {
67+ expect ( formatDisplayURL ( 'http' , 'localhost' , 3000 , '/' ) ) . toBe ( 'http://localhost:3000/' )
68+ expect ( formatDisplayURL ( 'https' , 'localhost' , 8443 , '/' ) ) . toBe ( 'https://localhost:8443/' )
69+ } )
70+
71+ it ( 'should omit the default port for the protocol' , ( ) => {
72+ expect ( formatDisplayURL ( 'http' , 'localhost' , 80 , '/' ) ) . toBe ( 'http://localhost/' )
73+ expect ( formatDisplayURL ( 'https' , 'localhost' , 443 , '/' ) ) . toBe ( 'https://localhost/' )
74+ expect ( formatDisplayURL ( 'https' , 'localhost' , 80 , '/' ) ) . toBe ( 'https://localhost:80/' )
75+ } )
76+
77+ it ( 'should bracket ipv6 hosts' , ( ) => {
78+ expect ( formatDisplayURL ( 'http' , '::1' , 3000 , '/' ) ) . toBe ( 'http://[::1]:3000/' )
79+ } )
80+
81+ it ( 'should decode a percent-encoded base url' , ( ) => {
82+ expect ( formatDisplayURL ( 'http' , 'localhost' , 3000 , '/%C3%A9t%C3%A9/' ) ) . toBe ( 'http://localhost:3000/été/' )
83+ } )
84+
85+ it ( 'should leave a malformed encoding alone' , ( ) => {
86+ expect ( formatDisplayURL ( 'http' , 'localhost' , 3000 , '/%E0%A4%A/' ) ) . toBe ( 'http://localhost:3000/%E0%A4%A/' )
87+ } )
88+ } )
89+
6590describe ( 'validateHostname' , ( ) => {
6691 it ( 'should pass through valid hosts' , ( ) => {
6792 expect ( validateHostname ( 'localhost' ) ) . toBe ( 'localhost' )
0 commit comments