@@ -124,6 +124,50 @@ describe.skipIf(process.platform === "win32")("a signal with a child process run
124124 ) ;
125125} ) ;
126126
127+ /**
128+ * Leave the process by `path` while a spinner is drawing on a terminal, and
129+ * return what it wrote there.
130+ */
131+ async function leaveMidSpinner ( path : string ) : Promise < string > {
132+ const source = `
133+ const { registerSignalHandlers } = await import(${ JSON . stringify ( SIGNALS_MODULE ) } );
134+ const { createIndicator } = await import(${ JSON . stringify ( `${ import . meta. dirname } /frame.ts` ) } );
135+ process.stderr.isTTY = true;
136+ registerSignalHandlers();
137+ createIndicator((chunk) => process.stderr.write(chunk)).start("Working");
138+ setTimeout(() => { ${ path } ; }, 150);
139+ setTimeout(() => process.exit(99), 10_000); // guard against a hang
140+ ` ;
141+ const { CLERK_CLI_NO_SIGNAL_RERAISE : _suppressed , ...cleanEnv } = process . env ;
142+ const proc = Bun . spawn ( [ "bun" , "-e" , source ] , {
143+ stdout : "ignore" ,
144+ stderr : "pipe" ,
145+ env : { ...cleanEnv , CLERK_TELEMETRY_DISABLED : "1" } ,
146+ } ) ;
147+ const stderr = await new Response ( proc . stderr ) . text ( ) ;
148+ await proc . exited ;
149+ return stderr ;
150+ }
151+
152+ describe . skipIf ( process . platform === "win32" ) ( "the cursor a spinner hid" , ( ) => {
153+ test . each ( [
154+ 'process.kill(process.pid, "SIGINT")' ,
155+ 'process.kill(process.pid, "SIGTERM")' ,
156+ 'process.kill(process.pid, "SIGHUP")' ,
157+ "process.exit(1)" ,
158+ 'throw new Error("boom")' ,
159+ ] ) (
160+ "is shown again after %s" ,
161+ async ( path ) => {
162+ const stderr = await leaveMidSpinner ( path ) ;
163+
164+ expect ( stderr ) . toContain ( "\x1b[?25l" ) ;
165+ expect ( stderr . lastIndexOf ( "\x1b[?25h" ) ) . toBeGreaterThan ( stderr . lastIndexOf ( "\x1b[?25l" ) ) ;
166+ } ,
167+ 15_000 ,
168+ ) ;
169+ } ) ;
170+
127171describe ( "Ctrl-C as the shell sees it" , ( ) => {
128172 test ( "an interrupted operation dies from SIGINT rather than exiting 130" , async ( ) => {
129173 const { signalCode } = await runInterrupted ( "work" ) ;
0 commit comments