@@ -10,6 +10,11 @@ import { copyURL, formatDisplayURL, getNetworkAddresses, isReusePortSupported, l
1010const writeText = vi . hoisted ( ( ) => vi . fn ( ) )
1111const isolatedEnvironment = vi . hoisted ( ( ) => ( { current : undefined as string | undefined } ) )
1212
13+ vi . mock ( 'std-env' , async importOriginal => ( {
14+ ...await importOriginal < typeof import ( 'std-env' ) > ( ) ,
15+ isCI : false ,
16+ } ) )
17+
1318vi . mock ( 'tinyclip' , ( ) => ( { writeText } ) )
1419vi . mock ( '../../src/dev/environment' , ( ) => ( {
1520detectIsolatedEnvironment : ( ) => isolatedEnvironment . current ,
@@ -234,6 +239,26 @@ describe('listen', () => {
234239return listener
235240}
236241
242+ it ( 'should not draw a QR code into output nothing can scan it from' , async ( ) => {
243+ const log = vi . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } )
244+ const originalIsTTY = process . stdout . isTTY
245+ Object . defineProperty ( process . stdout , 'isTTY' , { value : false , configurable : true } )
246+
247+ try {
248+ const listener = await listen ( ( _req , res ) => res . end ( 'ok' ) , { port : 0 , hostname : '127.0.0.1' , qr : true } )
249+ listeners . push ( listener )
250+ const printed = log . mock . calls . map ( ( [ line ] ) => String ( line ) ) . join ( '\n' )
251+
252+ expect ( printed ) . toContain ( 'Local:' )
253+ expect ( printed ) . not . toContain ( '[QR code]' )
254+ expect ( printed ) . not . toMatch ( / [ \u2580 - \u259F ] / )
255+ }
256+ finally {
257+ Object . defineProperty ( process . stdout , 'isTTY' , { value : originalIsTTY , configurable : true } )
258+ log . mockRestore ( )
259+ }
260+ } )
261+
237262it ( 'should accept connections on both loopback addresses in an isolated environment' , async ( ) => {
238263isolatedEnvironment . current = 'the container'
239264const listener = await start ( { port : 0 } )
@@ -356,12 +381,19 @@ describe('listener.close', () => {
356381throw new Error ( 'qr unavailable' )
357382} ,
358383} ) )
384+ const originalIsTTY = process . stdout . isTTY
385+ Object . defineProperty ( process . stdout , 'isTTY' , { value : true , configurable : true } )
359386
360- await expect ( listen ( ( _req , res ) => res . end ( 'ok' ) , { port : 0 , hostname : '127.0.0.1' , tunnel : true , qr : true } ) ) . rejects . toThrow ( 'qr unavailable' )
387+ try {
388+ await expect ( listen ( ( _req , res ) => res . end ( 'ok' ) , { port : 0 , hostname : '127.0.0.1' , tunnel : true , qr : true } ) ) . rejects . toThrow ( 'qr unavailable' )
361389
362- expect ( closeTunnel ) . toHaveBeenCalledTimes ( 1 )
363- vi . doUnmock ( '../../src/dev/tunnel' )
364- vi . doUnmock ( 'uqr' )
390+ expect ( closeTunnel ) . toHaveBeenCalledTimes ( 1 )
391+ }
392+ finally {
393+ Object . defineProperty ( process . stdout , 'isTTY' , { value : originalIsTTY , configurable : true } )
394+ vi . doUnmock ( '../../src/dev/tunnel' )
395+ vi . doUnmock ( 'uqr' )
396+ }
365397} )
366398
367399it ( 'should release the port when setup fails after binding' , async ( ) => {
0 commit comments