From ab0c33ebf83f25b526f732e3e07de5e75a6e69bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 26 Oct 2022 00:23:21 +0200 Subject: feat: Stabilize Deno.consoleSize() API (#15933) This commit stabilizes "Deno.consoleSize()" API. There is one change compared to previous unstable API, in that the API doesn't accept any arguments. Console size is established by querying syscalls for stdio streams at fd 0, 1 and 2. --- cli/tests/unit/tty_test.ts | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'cli/tests') diff --git a/cli/tests/unit/tty_test.ts b/cli/tests/unit/tty_test.ts index 8787db3e1..88b25d758 100644 --- a/cli/tests/unit/tty_test.ts +++ b/cli/tests/unit/tty_test.ts @@ -1,21 +1,15 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -import { assert, assertThrows } from "./test_util.ts"; +import { assert } from "./test_util.ts"; // Note tests for Deno.stdin.setRaw is in integration tests. -Deno.test({ permissions: { read: true } }, function consoleSizeFile() { - const file = Deno.openSync("cli/tests/testdata/assets/hello.txt"); - assertThrows(() => { - Deno.consoleSize(file.rid); - }, Error); - file.close(); -}); - -Deno.test(function consoleSizeError() { - assertThrows(() => { - // Absurdly large rid. - Deno.consoleSize(0x7fffffff); - }, Deno.errors.BadResource); +Deno.test(function consoleSize() { + if (!Deno.isatty(Deno.stdout.rid)) { + return; + } + const result = Deno.consoleSize(); + assert(typeof result.columns !== "undefined"); + assert(typeof result.rows !== "undefined"); }); Deno.test({ permissions: { read: true } }, function isatty() { -- cgit v1.2.3