@@ -6,6 +6,10 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
66
77import { getNetworkAddresses , listen , resolveOpenCommand } from '../../src/dev/listen'
88
9+ const spawn = vi . hoisted ( ( ) => vi . fn ( ( _command : string , _args : string [ ] ) => ( { on : ( ) => ( { unref : ( ) => { } } ) } ) ) )
10+
11+ vi . mock ( 'node:child_process' , ( ) => ( { spawn } ) )
12+
913vi . mock ( 'node:os' , ( ) => ( {
1014 networkInterfaces : vi . fn ( ( ) => ( { } ) ) ,
1115 release : ( ) => 'test' ,
@@ -91,6 +95,20 @@ describe('listen', () => {
9195 await expect ( start ( { port : first . address . port , strictPort : true } ) ) . rejects . toThrow ( / a l r e a d y i n u s e / )
9296 } )
9397
98+ it ( 'should open the dev server URL' , async ( ) => {
99+ const listener = await start ( { port : 0 , open : true } )
100+
101+ expect ( spawn . mock . lastCall ?. [ 1 ] ) . toContain ( listener . url )
102+ } )
103+
104+ it ( 'should open a path or URL relative to the dev server' , async ( ) => {
105+ const listener = await start ( { port : 0 , open : true , openURL : '/dashboard' } )
106+ expect ( spawn . mock . lastCall ?. [ 1 ] ) . toContain ( `${ listener . url } dashboard` )
107+
108+ await start ( { port : 0 , open : true , openURL : 'https://example.com/foo' } )
109+ expect ( spawn . mock . lastCall ?. [ 1 ] ) . toContain ( 'https://example.com/foo' )
110+ } )
111+
94112 it ( 'should use the requested port with `strictPort`' , async ( ) => {
95113 const { address } = await start ( { port : 0 } )
96114 const port = address . port
0 commit comments