summaryrefslogtreecommitdiff
path: root/tests/unit_node/tty_test.ts
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-07-19 12:39:05 +0200
committerGitHub <noreply@github.com>2024-07-19 12:39:05 +0200
commitee2e6933403811d398540e0e8275b2d216546dd8 (patch)
tree4ed2944dfbc516ea127c4bee50cc771ac12f902d /tests/unit_node/tty_test.ts
parent76b8ecbb6d8c07d29c34fb0b301cc3bf3351e3aa (diff)
fix(node): support `tty.hasColors()` and `tty.getColorDepth()` (#24619)
This PR adds support for [`tty.WriteStream.prototype.hasColors()`](https://nodejs.org/api/tty.html#writestreamhascolorscount-env) and [`tty.WriteStream.prototype.getColorDepth()`](https://nodejs.org/api/tty.html#writestreamgetcolordepthenv). I couldn't find any usage on GitHub which passes parameters to it. Therefore I've skipped adding support for the `env` parameter to keep our snapshot size small. Based on https://github.com/denoland/deno_terminal/pull/3 Fixes https://github.com/denoland/deno/issues/24616
Diffstat (limited to 'tests/unit_node/tty_test.ts')
-rw-r--r--tests/unit_node/tty_test.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/unit_node/tty_test.ts b/tests/unit_node/tty_test.ts
index 39ab4fe17..cde05b9ff 100644
--- a/tests/unit_node/tty_test.ts
+++ b/tests/unit_node/tty_test.ts
@@ -3,6 +3,7 @@
import { assert } from "@std/assert/mod.ts";
import { isatty } from "node:tty";
+import tty from "node:tty";
import process from "node:process";
Deno.test("[node/tty isatty] returns true when fd is a tty, false otherwise", () => {
@@ -34,3 +35,11 @@ Deno.test("[node/tty WriteStream.isTTY] returns true when fd is a tty", () => {
assert(Deno.stdin.isTerminal() === process.stdin.isTTY);
assert(Deno.stdout.isTerminal() === process.stdout.isTTY);
});
+
+Deno.test("[node/tty WriteStream.hasColors] returns true when colors are supported", () => {
+ assert(tty.WriteStream.prototype.hasColors() === !Deno.noColor);
+});
+
+Deno.test("[node/tty WriteStream.getColorDepth] returns current terminal color depth", () => {
+ assert([1, 4, 8, 24].includes(tty.WriteStream.prototype.getColorDepth()));
+});