Skip to content

Commit

Permalink
adding empty NO_COLOR test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyraspopov committed Oct 16, 2024
1 parent 99bf5ee commit 88eecaa
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ test("env NO_COLOR", () => {
assert.equal(pc.red("text"), pc.createColors(false).red("text"))
})

test("env NO_COLOR empty", () => {
let pc = initModuleEnv({ env: { NO_COLOR: "" } })
assert.equal(pc.isColorSupported, true)
assert.equal(pc.red("text"), pc.createColors(true).red("text"))
})

test("env FORCE_COLOR", () => {
let pc = initModuleEnv({ env: { TERM: "dumb", FORCE_COLOR: "1" } })
assert.equal(pc.isColorSupported, true)
Expand Down Expand Up @@ -62,8 +68,14 @@ function test(name, fn) {
}
}

function initModuleEnv({ env, argv = [], platform = "darwin", require = global.require }) {
let process = { env, argv, platform }
function initModuleEnv({
env,
argv = [],
platform = "darwin",
require = global.require,
stdout = process.stdout,
}) {
let process = { env, argv, platform, stdout }
let context = vm.createContext({ require, process, module: { exports: {} } })
let script = new vm.Script(source)
script.runInContext(context)
Expand Down

0 comments on commit 88eecaa

Please sign in to comment.