From a89680fbb8d937495272f51230dd868a75d44003 Mon Sep 17 00:00:00 2001 From: miso-devel Date: Sat, 26 Sep 2026 15:47:59 +0900 Subject: [PATCH 1/4] test(fmt): make color tests independent of NO_COLOR --- fmt/colors_test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fmt/colors_test.ts b/fmt/colors_test.ts index bdd2cde34d37..fb08b7538031 100644 --- a/fmt/colors_test.ts +++ b/fmt/colors_test.ts @@ -1,6 +1,10 @@ // Copyright 2018-2026 the Deno authors. MIT license. import { assertEquals } from "@std/assert"; -import * as c from "./colors.ts"; +import { stubProperty } from "@std/testing/unstable-stub-property"; + +// Enable colors before importing to prevent test failures when NO_COLOR=1. +using _ = stubProperty(Deno, "noColor", false); +const c = await import("./colors.ts"); Deno.test("reset()", function () { assertEquals(c.reset("foo bar"), "foo bar"); @@ -19,6 +23,9 @@ Deno.test("red() replaces close characters", function () { }); Deno.test("getColorEnabled() handles enabled colors", function () { + // setColorEnabled() ignores changes while Deno.noColor is true. + // Stub it again during this test so NO_COLOR cannot prevent toggling colors. + using _ = stubProperty(Deno, "noColor", false); assertEquals(c.getColorEnabled(), true); c.setColorEnabled(false); assertEquals(c.bgBlue(c.red("foo bar")), "foo bar"); From a1470bb9f420f7c58373bc5b97d038845df803ae Mon Sep 17 00:00:00 2001 From: miso-devel Date: Sat, 26 Sep 2026 16:01:45 +0900 Subject: [PATCH 2/4] test(internal): make style tests independent of NO_COLOR --- internal/styles_test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/styles_test.ts b/internal/styles_test.ts index 1f529c0acddf..bf82f1656bd4 100644 --- a/internal/styles_test.ts +++ b/internal/styles_test.ts @@ -1,6 +1,11 @@ // Copyright 2018-2026 the Deno authors. MIT license. -import { assertEquals } from "@std/assert"; -import * as c from "./styles.ts"; +import { stubProperty } from "@std/testing/unstable-stub-property"; + +// styles.ts captures Deno.noColor on import and is also loaded by @std/assert. +// Enable colors before importing either module. +using _ = stubProperty(Deno, "noColor", false); +const { assertEquals } = await import("@std/assert"); +const c = await import("./styles.ts"); Deno.test("red() single color", function () { assertEquals(c.red("foo bar"), "foo bar"); From 51530b598637186056bd3a1b7aa5ec7ee0e1bb20 Mon Sep 17 00:00:00 2001 From: miso-devel Date: Sat, 26 Sep 2026 16:37:30 +0900 Subject: [PATCH 3/4] test(cli/unstable): make spinner tests independent of NO_COLOR --- cli/unstable_spinner_test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cli/unstable_spinner_test.ts b/cli/unstable_spinner_test.ts index b8c6575d2be9..ae8e3c88d4ec 100644 --- a/cli/unstable_spinner_test.ts +++ b/cli/unstable_spinner_test.ts @@ -2,11 +2,14 @@ import { assertEquals } from "@std/assert"; import { Spinner } from "./unstable_spinner.ts"; import { restore, stub } from "@std/testing/mock"; +import { stubProperty } from "@std/testing/unstable-stub-property"; import { FakeTime } from "@std/testing/time"; const decoder = new TextDecoder(); Deno.test("Spinner can start and stop", async () => { + // Spinner.start() reads Deno.noColor, so enable colors while this test runs. + using _ = stubProperty(Deno, "noColor", false); try { const expectedOutput = [ "\r\x1b[K⠋\x1b[0m Loading...", @@ -49,6 +52,7 @@ Deno.test("Spinner can start and stop", async () => { }); Deno.test("Spinner constructor accepts spinner", async () => { + using _ = stubProperty(Deno, "noColor", false); try { const expectedOutput = [ "\r\x1b[K0\x1b[0m ", @@ -93,6 +97,7 @@ Deno.test("Spinner constructor accepts spinner", async () => { }); Deno.test("Spinner constructor accepts message", async () => { + using _ = stubProperty(Deno, "noColor", false); try { const expectedOutput = [ "\r\x1b[K⠋\x1b[0m Spinning with Deno 🦕", @@ -128,6 +133,7 @@ Deno.test("Spinner constructor accepts message", async () => { }); Deno.test("Spinner constructor accepts interval", async () => { + using _ = stubProperty(Deno, "noColor", false); try { using time = new FakeTime(); const expectedOutput = [ @@ -161,6 +167,7 @@ Deno.test("Spinner constructor accepts interval", async () => { }); Deno.test("Spinner constructor accepts output", async () => { + using _ = stubProperty(Deno, "noColor", false); try { const expectedOutput = [ "\r\x1b[K⠋\x1b[0m ", @@ -203,6 +210,7 @@ Deno.test("Spinner constructor accepts output", async () => { }); Deno.test("Spinner constructor accepts each color", async (t) => { + using _ = stubProperty(Deno, "noColor", false); await t.step("black", async () => { try { const expectedOutput = [ @@ -521,6 +529,7 @@ Deno.test("Spinner constructor accepts each color", async (t) => { }); Deno.test("Spinner.color can set each color", async () => { + using _ = stubProperty(Deno, "noColor", false); try { const expectedOutput = [ "\r\x1b[K⠋\x1b[0m ", @@ -588,6 +597,7 @@ Deno.test("Spinner.color can get each color", () => { }); Deno.test("Spinner.message can be updated", async () => { + using _ = stubProperty(Deno, "noColor", false); try { const expectedOutput = [ "\r\x1b[K⠋\x1b[0m One dino 🦕", From 7dc3b2c3cbc7c73ad2ae0c075d8cd60e1c21ad63 Mon Sep 17 00:00:00 2001 From: miso-devel Date: Sat, 26 Sep 2026 16:54:20 +0900 Subject: [PATCH 4/4] test(fmt): make printf tests independent of NO_COLOR --- fmt/printf_test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fmt/printf_test.ts b/fmt/printf_test.ts index 94427f425653..eaf2ddfeba25 100644 --- a/fmt/printf_test.ts +++ b/fmt/printf_test.ts @@ -5,10 +5,14 @@ // https://golang.org/src/fmt/fmt_test.go // BSD: Copyright (c) 2009 The Go Authors. All rights reserved. -import { printf, sprintf } from "./printf.ts"; import { assertEquals, assertThrows } from "@std/assert"; import { assertSpyCall, spy, stub } from "@std/testing/mock"; -import * as c from "./colors.ts"; +import { stubProperty } from "@std/testing/unstable-stub-property"; + +// Enable colors before importing to prevent test failures when NO_COLOR=1. +using _ = stubProperty(Deno, "noColor", false); +const { printf, sprintf } = await import("./printf.ts"); +const c = await import("./colors.ts"); Deno.test("sprintf() handles noVerb", function () { assertEquals(sprintf("bla"), "bla");