Skip to content

Commit e19ae63

Browse files
committed
Increase test timeouts and add bun-pty MWE to fix CI failures
- Increased setTimeout from 100ms to 500ms in web-server.test.ts for PTY startup waits - Increased setTimeout from 200ms to 500ms in pty-echo.test.ts - Added test/bun-pty-mwe.test.ts with minimum working examples for direct bun-pty usage - This should help with timing issues in CI where PTY operations are slower
1 parent 03be5e7 commit e19ae63

3 files changed

Lines changed: 93 additions & 6 deletions

File tree

test/bun-pty-mwe.test.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { describe, it, expect } from 'bun:test'
2+
import { spawn } from 'bun-pty'
3+
4+
describe('bun-pty Minimum Working Example', () => {
5+
it('should spawn echo and receive output', async () => {
6+
const pty = spawn('echo', ['hello world'], {
7+
name: 'xterm-256color',
8+
cols: 80,
9+
rows: 24,
10+
cwd: process.cwd(),
11+
env: process.env as Record<string, string>,
12+
})
13+
14+
let output = ''
15+
let exited = false
16+
17+
pty.onData((data: string) => {
18+
output += data
19+
})
20+
21+
pty.onExit(() => {
22+
exited = true
23+
})
24+
25+
// Wait for exit
26+
await new Promise((resolve) => {
27+
const check = () => {
28+
if (exited) {
29+
resolve(void 0)
30+
} else {
31+
setTimeout(check, 10)
32+
}
33+
}
34+
check()
35+
})
36+
37+
expect(output.trim()).toBe('hello world')
38+
pty.kill()
39+
})
40+
41+
it('should spawn cat and echo input', async () => {
42+
const pty = spawn('cat', [], {
43+
name: 'xterm-256color',
44+
cols: 80,
45+
rows: 24,
46+
cwd: process.cwd(),
47+
env: process.env as Record<string, string>,
48+
})
49+
50+
let output = ''
51+
let exited = false
52+
53+
pty.onData((data: string) => {
54+
output += data
55+
})
56+
57+
pty.onExit(() => {
58+
exited = true
59+
})
60+
61+
// Wait a bit for init
62+
await new Promise((resolve) => setTimeout(resolve, 100))
63+
64+
// Write input
65+
pty.write('test input\n')
66+
67+
// Wait for output
68+
await new Promise((resolve) => setTimeout(resolve, 100))
69+
70+
expect(output).toContain('test input')
71+
72+
// Kill to exit
73+
pty.kill()
74+
75+
// Wait for exit
76+
await new Promise((resolve) => {
77+
const check = () => {
78+
if (exited) {
79+
resolve(void 0)
80+
} else {
81+
setTimeout(check, 10)
82+
}
83+
}
84+
check()
85+
})
86+
})
87+
})

test/pty-echo.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ describe('PTY Echo Behavior', () => {
3838
console.log('Echo session:', session)
3939

4040
// Wait for PTY to initialize and show prompt
41-
await new Promise((resolve) => setTimeout(resolve, 200))
41+
await new Promise((resolve) => setTimeout(resolve, 500))
4242

4343
// Send test input
4444
const success = manager.write(session.id, 'a')
4545
console.log('Write success:', success)
4646
expect(success).toBe(true)
4747

4848
// Wait for echo to be processed
49-
await new Promise((resolve) => setTimeout(resolve, 200))
49+
await new Promise((resolve) => setTimeout(resolve, 500))
5050

5151
// Clean up
5252
manager.kill(session.id, true)

test/web-server.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe('Web Server', () => {
140140
console.log('Created session:', session)
141141

142142
// Wait for PTY to start
143-
await new Promise((resolve) => setTimeout(resolve, 100))
143+
await new Promise((resolve) => setTimeout(resolve, 500))
144144

145145
const response = await fetch(`${serverUrl}/api/sessions/${session.id}`)
146146
console.log('Session response status:', response.status)
@@ -172,7 +172,7 @@ describe('Web Server', () => {
172172
console.log('Input session:', session)
173173

174174
// Wait for PTY to start
175-
await new Promise((resolve) => setTimeout(resolve, 100))
175+
await new Promise((resolve) => setTimeout(resolve, 500))
176176

177177
const response = await fetch(`${serverUrl}/api/sessions/${session.id}/input`, {
178178
method: 'POST',
@@ -202,7 +202,7 @@ describe('Web Server', () => {
202202
console.log('Kill session:', session)
203203

204204
// Wait for PTY to start
205-
await new Promise((resolve) => setTimeout(resolve, 100))
205+
await new Promise((resolve) => setTimeout(resolve, 500))
206206

207207
const response = await fetch(`${serverUrl}/api/sessions/${session.id}/kill`, {
208208
method: 'POST',
@@ -227,7 +227,7 @@ describe('Web Server', () => {
227227
console.log('Output session:', session)
228228

229229
// Wait a bit for output to be captured
230-
await new Promise((resolve) => setTimeout(resolve, 100))
230+
await new Promise((resolve) => setTimeout(resolve, 500))
231231

232232
const response = await fetch(`${serverUrl}/api/sessions/${session.id}/buffer/raw`)
233233
console.log('Buffer response status:', response.status)

0 commit comments

Comments
 (0)