mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
ab0c33ebf8
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.
32 lines
875 B
TypeScript
32 lines
875 B
TypeScript
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
import { assert } from "./test_util.ts";
|
|
|
|
// Note tests for Deno.stdin.setRaw is in integration tests.
|
|
|
|
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() {
|
|
// CI not under TTY, so cannot test stdin/stdout/stderr.
|
|
const f = Deno.openSync("cli/tests/testdata/assets/hello.txt");
|
|
assert(!Deno.isatty(f.rid));
|
|
f.close();
|
|
});
|
|
|
|
Deno.test(function isattyError() {
|
|
let caught = false;
|
|
try {
|
|
// Absurdly large rid.
|
|
Deno.isatty(0x7fffffff);
|
|
} catch (e) {
|
|
caught = true;
|
|
assert(e instanceof Deno.errors.BadResource);
|
|
}
|
|
assert(caught);
|
|
});
|