diff --git a/cli/js/tests/console_test.ts b/cli/js/tests/console_test.ts index 43378e2cab..bceee94190 100644 --- a/cli/js/tests/console_test.ts +++ b/cli/js/tests/console_test.ts @@ -5,8 +5,6 @@ import { assert, assertEquals, unitTest } from "./test_util.ts"; // in order to "trick" TypeScript. const { inspect, - writeSync, - stdout, // eslint-disable-next-line @typescript-eslint/no-explicit-any } = Deno as any; @@ -744,21 +742,10 @@ unitTest(function consoleTestError(): void { }); unitTest(function consoleTestClear(): void { - const stdoutWriteSync = stdout.writeSync; - const uint8 = new TextEncoder().encode("\x1b[1;1H" + "\x1b[0J"); - let buffer = new Uint8Array(0); - - stdout.writeSync = (u8: Uint8Array): Promise => { - const tmp = new Uint8Array(buffer.length + u8.length); - tmp.set(buffer, 0); - tmp.set(u8, buffer.length); - buffer = tmp; - - return writeSync(stdout.rid, u8); - }; - console.clear(); - stdout.writeSync = stdoutWriteSync; - assertEquals(buffer, uint8); + mockConsole((console, out) => { + console.clear(); + assertEquals(out.toString(), "\x1b[1;1H" + "\x1b[0J"); + }); }); // Test bound this issue diff --git a/cli/js/web/console.ts b/cli/js/web/console.ts index 0611478871..5544ded3c0 100644 --- a/cli/js/web/console.ts +++ b/cli/js/web/console.ts @@ -1,8 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { isTypedArray, TypedArray } from "./util.ts"; -import { TextEncoder } from "./text_encoding.ts"; -import { SyncWriter } from "../io.ts"; -import { stdout } from "../files.ts"; import { cliTable } from "./console_table.ts"; import { exposeForTest } from "../internals.ts"; import { PromiseState } from "./promise.ts"; @@ -39,16 +36,6 @@ export class CSI { /* eslint-disable @typescript-eslint/no-use-before-define */ -function cursorTo(stream: SyncWriter, _x: number, _y?: number): void { - const uint8 = new TextEncoder().encode(CSI.kClear); - stream.writeSync(uint8); -} - -function clearScreenDown(stream: SyncWriter): void { - const uint8 = new TextEncoder().encode(CSI.kClearScreenDown); - stream.writeSync(uint8); -} - function getClassInstanceName(instance: unknown): string { if (typeof instance !== "object") { return ""; @@ -934,8 +921,8 @@ export class Console { clear = (): void => { this.indentLevel = 0; - cursorTo(stdout, 0, 0); - clearScreenDown(stdout); + this.#printFunc(CSI.kClear, false); + this.#printFunc(CSI.kClearScreenDown, false); }; trace = (...args: unknown[]): void => {