From 1aca531fdd45b503c067f7511ebd17054bc01860 Mon Sep 17 00:00:00 2001 From: Mathieu Hofman <86499+mhofman@users.noreply.github.com> Date: Fri, 20 Sep 2024 12:25:49 -0700 Subject: [PATCH] test(xsnap): fix child process types --- packages/xsnap/test/xsnap-eof.test.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/xsnap/test/xsnap-eof.test.js b/packages/xsnap/test/xsnap-eof.test.js index 0c796a94578..89f89883447 100644 --- a/packages/xsnap/test/xsnap-eof.test.js +++ b/packages/xsnap/test/xsnap-eof.test.js @@ -11,6 +11,21 @@ import { makePromiseKit } from '@endo/promise-kit'; import { options } from './message-tools.js'; import { xsnap, QUERY_RESPONSE_BUF } from '../src/xsnap.js'; +/** + * @import { Readable, Writable, Duplex } from 'stream' + */ + +/** + * @typedef {Omit & +* { +* stdin: null; +* stdout: null; +* stderr: Readable; +* readonly stdio: [null, null, Readable, Duplex, Duplex, undefined, undefined, Duplex, Duplex]; +* } +* } XsnapChildProcess +*/ + test('xsnap-worker complains while waiting for answer when parent is killed', async t => { const exitedPKit = makePromiseKit(); @@ -48,13 +63,15 @@ test('xsnap-worker complains while waiting for answer when parent is killed', as async function spawnReflectiveWorker(handleCommand) { const exitedPKit = makePromiseKit(); + /** @type {XsnapChildProcess | undefined} */ let xsnapProcess; /** @type {typeof import('child_process').spawn} */ const spawnSpy = (...args) => { // @ts-expect-error overloaded signature - xsnapProcess = proc.spawn(...args); - return xsnapProcess; + const cp = proc.spawn(...args) + xsnapProcess = cp; + return cp; }; const io = { spawn: spawnSpy, os: os.type(), fs, tmpName }; @@ -63,6 +80,8 @@ async function spawnReflectiveWorker(handleCommand) { 'function handleCommand(message) { issueCommand(new Uint8Array().buffer); };', ); + assert(xsnapProcess); + const toXsnap = xsnapProcess.stdio[3]; const fromXsnap = xsnapProcess.stdio[4]; const stderrP = text(xsnapProcess.stderr);