Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cli/unstable_spinner_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...",
Expand Down Expand Up @@ -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 ",
Expand Down Expand Up @@ -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 🦕",
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 ",
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 ",
Expand Down Expand Up @@ -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 🦕",
Expand Down
9 changes: 8 additions & 1 deletion fmt/colors_test.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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");
Expand Down
8 changes: 6 additions & 2 deletions fmt/printf_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 7 additions & 2 deletions internal/styles_test.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
Loading