Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class Argv {
}

private constructor (argv: any, writeStreams?: WriteStreams) {
if (argv.noColor) {
if (argv.noColor || argv.color === false || (process.env.NO_COLOR ?? "") !== "") {
chalkBase.level = 0;
}
this.writeStreams = writeStreams;
Expand Down
51 changes: 51 additions & 0 deletions tests/argv-color.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import "../src/global.js";
import chalkBase from "chalk";
import {Argv} from "../src/argv.js";
import {WriteStreamsMock} from "../src/write-streams.js";

let writeStreams: WriteStreamsMock;
let originalLevel: number;
let originalNoColor: string | undefined;

beforeEach(() => {
writeStreams = new WriteStreamsMock();
originalLevel = chalkBase.level;
originalNoColor = process.env.NO_COLOR;
});

afterEach(() => {
chalkBase.level = originalLevel;
if (originalNoColor === undefined) {
delete process.env.NO_COLOR;
} else {
process.env.NO_COLOR = originalNoColor;
}
});

test("color stays enabled by default", async () => {
chalkBase.level = 2;
delete process.env.NO_COLOR;
await Argv.build({}, writeStreams);
expect(chalkBase.level).toBe(2);
});

test("--no-color disables color", async () => {
chalkBase.level = 2;
delete process.env.NO_COLOR;
await Argv.build({color: false}, writeStreams);
expect(chalkBase.level).toBe(0);
});

test("NO_COLOR disables color", async () => {
chalkBase.level = 2;
process.env.NO_COLOR = "1";
await Argv.build({}, writeStreams);
expect(chalkBase.level).toBe(0);
});

test("an empty NO_COLOR leaves color enabled", async () => {
chalkBase.level = 2;
process.env.NO_COLOR = "";
await Argv.build({}, writeStreams);
expect(chalkBase.level).toBe(2);
});
Loading