summaryrefslogtreecommitdiff
path: root/tests/unit/tty_color_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/tty_color_test.ts')
-rw-r--r--tests/unit/tty_color_test.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/unit/tty_color_test.ts b/tests/unit/tty_color_test.ts
new file mode 100644
index 000000000..6f26891e3
--- /dev/null
+++ b/tests/unit/tty_color_test.ts
@@ -0,0 +1,55 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+import { assertEquals } from "./test_util.ts";
+
+// Note tests for Deno.stdin.setRaw is in integration tests.
+
+Deno.test(
+ { permissions: { run: true, read: true } },
+ async function noColorIfNotTty() {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
+ args: ["eval", "console.log(1)"],
+ }).output();
+ const output = new TextDecoder().decode(stdout);
+ assertEquals(output, "1\n");
+ },
+);
+
+Deno.test(
+ { permissions: { run: true, read: true } },
+ async function denoNoColorIsNotAffectedByNonTty() {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
+ args: ["eval", "console.log(Deno.noColor)"],
+ }).output();
+ const output = new TextDecoder().decode(stdout);
+ assertEquals(output, "false\n");
+ },
+);
+
+Deno.test(
+ { permissions: { run: true, read: true } },
+ async function denoNoColorTrueEmptyVar() {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
+ args: ["eval", "console.log(Deno.noColor)"],
+ env: {
+ // https://no-color.org/ -- should not be true when empty
+ NO_COLOR: "",
+ },
+ }).output();
+ const output = new TextDecoder().decode(stdout);
+ assertEquals(output, "false\n");
+ },
+);
+
+Deno.test(
+ { permissions: { run: true, read: true } },
+ async function denoNoColorTrueEmptyVar() {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
+ args: ["eval", "console.log(Deno.noColor)"],
+ env: {
+ NO_COLOR: "1",
+ },
+ }).output();
+ const output = new TextDecoder().decode(stdout);
+ assertEquals(output, "true\n");
+ },
+);