mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-08 12:28:46 +03:00
fix: tty.WriteStream method stubs for process.stdout/stderr (#29865)
Fixes #29839
This commit is contained in:
parent
94e61fc95a
commit
59228f19ce
@ -131,4 +131,26 @@ function setTtyParams(stream: WriteStream, params: TtyParams) {
|
|||||||
count = 16;
|
count = 16;
|
||||||
return count <= 2 ** params.colorDepth;
|
return count <= 2 ** params.colorDepth;
|
||||||
})as any;
|
})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];
|
||||||
}
|
}
|
||||||
|
@ -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).not.toContain(`TypeError: process.stderr.hasColors is not a function`);
|
||||||
expect(result.output).toContain(`AssertionError`);
|
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);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user