|
| 1 | +import "../src/global.js"; |
| 2 | +import chalkBase, {type ColorSupportLevel} from "chalk"; |
| 3 | +import {Argv} from "../src/argv.js"; |
| 4 | +import {WriteStreamsMock} from "../src/write-streams.js"; |
| 5 | + |
| 6 | +let writeStreams: WriteStreamsMock; |
| 7 | +let originalLevel: ColorSupportLevel; |
| 8 | +let originalNoColor: string | undefined; |
| 9 | + |
| 10 | +beforeEach(() => { |
| 11 | + writeStreams = new WriteStreamsMock(); |
| 12 | + originalLevel = chalkBase.level; |
| 13 | + originalNoColor = process.env.NO_COLOR; |
| 14 | +}); |
| 15 | + |
| 16 | +afterEach(() => { |
| 17 | + chalkBase.level = originalLevel; |
| 18 | + if (originalNoColor === undefined) { |
| 19 | + delete process.env.NO_COLOR; |
| 20 | + } else { |
| 21 | + process.env.NO_COLOR = originalNoColor; |
| 22 | + } |
| 23 | +}); |
| 24 | + |
| 25 | +test("color stays enabled by default", async () => { |
| 26 | + chalkBase.level = 2; |
| 27 | + delete process.env.NO_COLOR; |
| 28 | + await Argv.build({}, writeStreams); |
| 29 | + expect(chalkBase.level).toBe(2); |
| 30 | +}); |
| 31 | + |
| 32 | +test("--no-color disables color", async () => { |
| 33 | + chalkBase.level = 2; |
| 34 | + delete process.env.NO_COLOR; |
| 35 | + await Argv.build({color: false}, writeStreams); |
| 36 | + expect(chalkBase.level).toBe(0); |
| 37 | +}); |
| 38 | + |
| 39 | +test("NO_COLOR disables color", async () => { |
| 40 | + chalkBase.level = 2; |
| 41 | + process.env.NO_COLOR = "1"; |
| 42 | + await Argv.build({}, writeStreams); |
| 43 | + expect(chalkBase.level).toBe(0); |
| 44 | +}); |
| 45 | + |
| 46 | +test("an empty NO_COLOR leaves color enabled", async () => { |
| 47 | + chalkBase.level = 2; |
| 48 | + process.env.NO_COLOR = ""; |
| 49 | + await Argv.build({}, writeStreams); |
| 50 | + expect(chalkBase.level).toBe(2); |
| 51 | +}); |
0 commit comments