From 5190c2d76fb4f8ee48abe8df9eb198829002eb77 Mon Sep 17 00:00:00 2001 From: Gustav Hansen Date: Wed, 20 May 2026 11:15:20 +0200 Subject: [PATCH] test(cli): stub getWindowSize in vitest worker setup `@oclif/core/lib/screen.js` reads `process.stdout.getWindowSize()` once, at module init, but only if `process.stdout.isTTY` is truthy. Vitest's stdout proxy doesn't implement `getWindowSize`, so when a test sets `isTTY = true` before oclif is loaded in that worker (the situation in `checkForUpdates.test.ts`), screen.js crashes the whole worker with `TypeError: stream.getWindowSize is not a function`. It's order-dependent: only the shard where checkForUpdates is the first oclif-touching file flakes, which is why we see different individual tests fail across shards in CI. Install a `getWindowSize` shim once per worker so screen.js can load safely no matter when isTTY gets flipped. --- packages/@sanity/cli/test/setup.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/@sanity/cli/test/setup.ts b/packages/@sanity/cli/test/setup.ts index d29aa8d48..056f143e9 100644 --- a/packages/@sanity/cli/test/setup.ts +++ b/packages/@sanity/cli/test/setup.ts @@ -5,3 +5,18 @@ import {vi} from 'vitest' */ // Mock open, to prevent it from opening a browser vi.mock('open') + +// `@oclif/core/lib/screen.js` reads `process.stdout.getWindowSize()` at module +// init when `process.stdout.isTTY` is truthy. Vitest's stdout proxy doesn't +// implement `getWindowSize`, so any test that flips `isTTY = true` before oclif +// is loaded (e.g. `checkForUpdates.test.ts`) crashes the whole worker. +// Provide a no-op shim once per worker so the eventual load is safe. +for (const stream of [process.stdout, process.stderr] as const) { + if (typeof stream.getWindowSize !== 'function') { + Object.defineProperty(stream, 'getWindowSize', { + configurable: true, + value: () => [80, 24], + writable: true, + }) + } +}