Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: tty.WriteStream method stubs for process.stdout/stderr (#29865)
Yury Semikhatsky59228f19cee6
diff --git a/packages/playwright/src/common/process.ts b/packages/playwright/src/common/process.tsindex f082e958c2..23de620649 100644--- a/packages/playwright/src/common/process.ts+++ b/packages/playwright/src/common/process.ts@@ -131,4 +131,26 @@ function setTtyParams(stream: WriteStream, params: TtyParams) {count = 16;return count <= 2 ** params.colorDepth;})as any;++ // Stubs for the rest of the methods to avoid exceptions in user code.+ stream.clearLine = (dir: any, callback?: () => void) => {+ callback?.();+ return true;+ };+ stream.clearScreenDown = (callback?: () => void) => {+ callback?.();+ return true;+ };+ (stream as any).cursorTo = (x: number, y?: number | (() => void), callback?: () => void) => {+ if (callback)+ callback();+ else if (y instanceof Function)+ y();+ return true;+ };+ stream.moveCursor = (dx: number, dy: number, callback?: () => void) => {+ callback?.();+ return true;+ };+ stream.getWindowSize = () => [stream.columns, stream.rows];}diff --git a/tests/playwright-test/stdio.spec.ts b/tests/playwright-test/stdio.spec.tsindex 251cf527bb..e0609b1ac6 100644--- a/tests/playwright-test/stdio.spec.ts+++ b/tests/playwright-test/stdio.spec.ts@@ -128,3 +128,30 @@ test('should not throw type error when using assert', async ({ runInlineTest })expect(result.output).not.toContain(`TypeError: process.stderr.hasColors is not a function`);expect(result.output).toContain(`AssertionError`);});++test('should provide stubs for tty.WriteStream methods on process.stdout/stderr', async ({ runInlineTest }) => {+ test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29839' });+ const result = await runInlineTest({+ 'a.spec.ts': `+ import { test, expect } from '@playwright/test';+ import type * as tty from 'tty';+ async function checkMethods(stream: tty.WriteStream) {+ expect(stream.isTTY).toBe(true);+ await new Promise<void>(r => stream.clearLine(-1, r));;+ await new Promise<void>(r => stream.clearScreenDown(r));;+ await new Promise<void>(r => stream.cursorTo(0, 0, r));;+ await new Promise<void>(r => stream.cursorTo(0, r));;+ await new Promise<void>(r => stream.moveCursor(1, 1, r));;+ expect(stream.getWindowSize()).toEqual([stream.columns, stream.rows]);+ // getColorDepth() and hasColors() are covered in other tests.+ }+ test('process.stdout implementd tty.WriteStream methods', () => {+ checkMethods(process.stdout);+ });+ test('process.stderr implementd tty.WriteStream methods', () => {+ checkMethods(process.stderr);+ });+ `+ });+ expect(result.exitCode).toBe(0);+});