diff --git a/package-lock.json b/package-lock.json index 1facd4d..79e6e49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4745,9 +4745,9 @@ "dev": true }, "node_modules/nanoid": { - "version": "3.3.17", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.17.tgz", - "integrity": "sha512-xQLf0A3HOMlgHq0n247/LRuAOYmB7dXJ/DvAxGvsSBij45XtBSmQycu+F8ODbHwns/XyFZagyL1+J0Offw1E0g==", + "version": "3.3.18", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.18.tgz", + "integrity": "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w==", "dev": true, "funding": [ { diff --git a/src/main/pty-host.test.ts b/src/main/pty-host.test.ts index 582db5f..639648b 100644 --- a/src/main/pty-host.test.ts +++ b/src/main/pty-host.test.ts @@ -41,14 +41,22 @@ const hasLsof = ((): boolean => { const sleep = (ms: number): Promise => new Promise((r) => setTimeout(r, ms)) -/** Poll rather than wait a fixed time: spawning a job is slower on a loaded machine. */ -async function waitFor(read: () => Promise): Promise { +/** + * Poll rather than wait a fixed time: spawning a job is slower on a loaded machine. + * The caller says what counts as arrived. Between fork and exec ps briefly reports the + * child as `[sleep]` with no args, and "anything non-null" would return that. + */ +async function waitFor( + read: () => Promise, + accept: (value: string) => boolean, +): Promise { + let last: string | null = null for (let i = 0; i < 100; i++) { - const value = await read() - if (value !== null) return value + last = await read() + if (last !== null && accept(last)) return last await sleep(100) } - return null + return last } describe.skipIf(!hasPs || !hasBash)('the foreground command through ps', () => { @@ -65,7 +73,10 @@ describe.skipIf(!hasPs || !hasBash)('the foreground command through ps', () => { expect(await foregroundCommandViaPs(term.pid)).toBe(null) term.write('sleep 300\r') - const running = await waitFor(() => foregroundCommandViaPs(term.pid)) + const running = await waitFor( + () => foregroundCommandViaPs(term.pid), + (v) => /sleep 300$/.test(v), + ) expect(running).toMatch(/sleep 300$/) } finally { term.kill()