@@ -32,6 +32,22 @@ const pick = (log: Array<{ type: "created" | "exited" | "deleted"; id: PtyID }>,
3232 return log . filter ( ( evt ) => evt . id === id ) . map ( ( evt ) => evt . type )
3333}
3434
35+ function createPty ( input : Pty . CreateInput ) {
36+ return AppRuntime . runPromise ( Pty . Service . use ( ( svc ) => svc . create ( input ) ) )
37+ }
38+
39+ function removePty ( id : PtyID ) {
40+ return AppRuntime . runPromise ( Pty . Service . use ( ( svc ) => svc . remove ( id ) ) )
41+ }
42+
43+ function connectPty ( id : PtyID , ws : Parameters < Pty . Interface [ "connect" ] > [ 1 ] ) {
44+ return AppRuntime . runPromise ( Pty . Service . use ( ( svc ) => svc . connect ( id , ws ) ) )
45+ }
46+
47+ function writePty ( id : PtyID , data : string ) {
48+ return AppRuntime . runPromise ( Pty . Service . use ( ( svc ) => svc . write ( id , data ) ) )
49+ }
50+
3551describe ( "pty" , ( ) => {
3652 test ( "publishes created, exited, deleted in order for a short-lived process" , async ( ) => {
3753 if ( process . platform === "win32" ) return
@@ -127,10 +143,10 @@ describe("pty", () => {
127143 await Instance . provide ( {
128144 directory : dir . path ,
129145 fn : async ( ) => {
130- const info = await Pty . create ( { command : "cat" , title : "cat" } )
146+ const info = await createPty ( { command : "cat" , title : "cat" } )
131147 try {
132148 const out : string [ ] = [ ]
133- const ws : Parameters < typeof Pty . connect > [ 1 ] = {
149+ const ws : Parameters < Pty . Interface [ " connect" ] > [ 1 ] = {
134150 readyState : 1 ,
135151 data : { id : info . id } ,
136152 send : ( data : unknown ) => {
@@ -139,12 +155,12 @@ describe("pty", () => {
139155 close : ( ) => { } ,
140156 }
141157
142- await Pty . connect ( info . id , ws )
158+ await connectPty ( info . id , ws )
143159 out . length = 0
144- await Pty . write ( info . id , "AAA\n" )
160+ await writePty ( info . id , "AAA\n" )
145161 await wait ( ( ) => out . join ( "" ) . includes ( "AAA" ) )
146162 } finally {
147- await Pty . remove ( info . id )
163+ await removePty ( info . id )
148164 }
149165 } ,
150166 } )
@@ -172,7 +188,7 @@ describe("pty", () => {
172188 await Instance . provide ( {
173189 directory : dir . path ,
174190 fn : async ( ) => {
175- const info = await Pty . create ( { command : "/bin/bash" , title : "bash" } )
191+ const info = await createPty ( { command : "/bin/bash" , title : "bash" } )
176192 try {
177193 await sleep ( 150 )
178194 const hit = await fs
@@ -181,7 +197,7 @@ describe("pty", () => {
181197 . catch ( ( ) => false )
182198 expect ( hit ) . toBe ( false )
183199 } finally {
184- await Pty . remove ( info . id )
200+ await removePty ( info . id )
185201 }
186202 } ,
187203 } )
@@ -202,11 +218,11 @@ describe("pty", () => {
202218 await Instance . provide ( {
203219 directory : dir . path ,
204220 fn : async ( ) => {
205- await expect ( Pty . create ( { command : "python" , title : "py" } ) ) . rejects . toThrow ( "python" )
221+ await expect ( createPty ( { command : "python" , title : "py" } ) ) . rejects . toThrow ( "python" )
206222 await expect (
207- Pty . create ( { command : "env" , args : [ "FOO=1" , "python" , "-c" , "print(1)" ] , title : "env" } ) ,
223+ createPty ( { command : "env" , args : [ "FOO=1" , "python" , "-c" , "print(1)" ] , title : "env" } ) ,
208224 ) . rejects . toThrow ( "python" )
209- await expect ( Pty . create ( { command : "sh" , args : [ "-c" , "python -c 'print(1)'" ] , title : "sh" } ) ) . rejects . toThrow (
225+ await expect ( createPty ( { command : "sh" , args : [ "-c" , "python -c 'print(1)'" ] , title : "sh" } ) ) . rejects . toThrow (
210226 "python" ,
211227 )
212228 } ,
0 commit comments