Kaynağa Gözat

test: preserve immediate disposal and observe automatic terminal cleanup

07akioni 1 ay önce
ebeveyn
işleme
9f27a45408

+ 2 - 10
packages/shell/bash-sandbox/tests/sandbox.spec.ts

@@ -661,16 +661,8 @@ describe('background sandbox facts', () => {
 
   it('disposal kills wrapped background jobs (inherited HMR safety)', async () => {
     const { ctx, bash } = await setup()
-    const task = bash.start(bash.resolve({ command: 'echo ready; sleep 30' }))
-    let output = ''
-    try {
-      await expect.poll(() => {
-        output += task.readOutput().delta
-        return output
-      }).toContain('ready')
-    } finally {
-      await ctx.fiber.dispose()
-    }
+    const task = bash.start(bash.resolve({ command: 'sleep 30' }))
+    await ctx.fiber.dispose()
     expect(task.status).toBe('killed')
   })
 })

+ 4 - 3
packages/subprocess/subprocess-local/tests/local.spec.ts

@@ -400,8 +400,7 @@ describe('LocalSubprocessRuntime', () => {
       expect((service as unknown as { terminals: Set<SubprocessTerminalHandle> }).terminals.size).toBe(1)
       exitListener?.({ exitCode: 0 })
       await handle.done
-      await new Promise(resolve => setImmediate(resolve))
-      expect((service as unknown as { terminals: Set<SubprocessTerminalHandle> }).terminals.size).toBe(0)
+      await expect.poll(() => (service as unknown as { terminals: Set<SubprocessTerminalHandle> }).terminals.size).toBe(0)
       await fiber.dispose()
     } finally {
       vi.doUnmock('node-pty')
@@ -617,9 +616,11 @@ describe('LocalSubprocessRuntime', () => {
       const handle = await ctx.subprocess.spawnTerminal({
         argv: ['shell'], cwd: process.cwd(), rows: 24, cols: 80, graceMs: 1,
       })
+      const terminate = vi.spyOn(handle, 'terminate')
       exitListener?.({ exitCode: 0 })
       await handle.done
-      await expect(handle.terminate()).rejects.toThrow('surviving pids: 124')
+      await expect.poll(() => terminate.mock.calls.length).toBe(1)
+      await expect(terminate.mock.results[0]?.value).rejects.toThrow('surviving pids: 124')
       expect((ctx.subprocess as unknown as { terminals: Set<SubprocessTerminalHandle> }).terminals.size).toBe(1)
       await fiber.dispose()
       expect(disposalErrors).toHaveLength(1)