From 8e9ab9e33ea2c972762cc345c584391c37731b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 27 Apr 2020 15:40:47 +0200 Subject: refactor: decouple Console implementation from stdout (#4899) When creating a console instance, one must pass "printFunc" arg which is used internally by Console to output messages. Due to numerous refactors there was a single method ("console.clear()") that used "Deno.stdout" instead of "printFunc". This commit unifies how "Console" outpus message, by using "printFunc" in all methods; consequently "Deno.stdout" is no longer imported in "cli/js/console.ts" making it a standalone module that doesn't depend on any CLI-specific APIs. --- cli/js/tests/console_test.ts | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'cli/js/tests') diff --git a/cli/js/tests/console_test.ts b/cli/js/tests/console_test.ts index 43378e2ca..bceee9419 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 -- cgit v1.2.3