Skip to content

Commit

Permalink
fix(npm.color): refer to npm.color
Browse files Browse the repository at this point in the history
not npm.config.get('color')
  • Loading branch information
wraithgar committed Mar 18, 2021
1 parent b216114 commit 52165d6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/fund.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Fund extends BaseCommand {
}

printHuman (fundingInfo) {
const color = this.npm.config.get('color')
const color = !!this.npm.color
const unicode = this.npm.config.get('unicode')
const seenUrls = new Map()

Expand Down
2 changes: 1 addition & 1 deletion lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LS extends BaseCommand {

async ls (args) {
const all = this.npm.config.get('all')
const color = !!this.npm.config.get('color')
const color = !!this.npm.color
const depth = this.npm.config.get('depth')
const dev = this.npm.config.get('dev')
const development = this.npm.config.get('development')
Expand Down
4 changes: 2 additions & 2 deletions lib/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Outdated extends BaseCommand {
outHead.push('Package Type', 'Homepage')
const outTable = [outHead].concat(outList)

if (this.npm.config.get('color'))
if (this.npm.color)
outTable[0] = outTable[0].map(heading => styles.underline(heading))

const tableOpts = {
Expand Down Expand Up @@ -216,7 +216,7 @@ class Outdated extends BaseCommand {
columns[7] = homepage
}

if (this.npm.config.get('color')) {
if (this.npm.color) {
columns[0] = color[current === wanted ? 'yellow' : 'red'](columns[0]) // current
columns[2] = color.green(columns[2]) // wanted
columns[3] = color.magenta(columns[3]) // latest
Expand Down
4 changes: 2 additions & 2 deletions test/lib/fund.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,14 @@ test('fund colors', t => {
},
},
})
config.color = true
npm.color = true

fund.exec([], (err) => {
t.ifError(err, 'should not error out')
t.matchSnapshot(result, 'should print output with color info')

result = ''
config.color = false
npm.color = false
t.end()
})
})
Expand Down
24 changes: 12 additions & 12 deletions test/lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ t.test('ls', (t) => {
})

t.test('with filter arg', (t) => {
config.color = true
npm.color = true
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
Expand All @@ -197,7 +197,7 @@ t.test('ls', (t) => {
ls.exec(['lorem'], (err) => {
t.ifError(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should output tree contaning only occurrences of filtered by package and colored output')
config.color = false
npm.color = false
t.end()
})
})
Expand Down Expand Up @@ -431,7 +431,7 @@ t.test('ls', (t) => {
})

t.test('colored output', (t) => {
config.color = true
npm.color = true
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
Expand All @@ -446,7 +446,7 @@ t.test('ls', (t) => {
ls.exec([], (err) => {
t.equal(err.code, 'ELSPROBLEMS', 'should have error code')
t.matchSnapshot(redactCwd(result), 'should output tree containing color info')
config.color = false
npm.color = false
t.end()
})
})
Expand Down Expand Up @@ -752,7 +752,7 @@ t.test('ls', (t) => {
})

t.test('invalid deduped dep', (t) => {
config.color = true
npm.color = true
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'invalid-deduped-dep',
Expand Down Expand Up @@ -782,7 +782,7 @@ t.test('ls', (t) => {
})
ls.exec([], () => {
t.matchSnapshot(redactCwd(result), 'should output tree signaling mismatching peer dep in problems')
config.color = false
npm.color = false
t.end()
})
})
Expand Down Expand Up @@ -836,7 +836,7 @@ t.test('ls', (t) => {
})

t.test('unmet optional dep', (t) => {
config.color = true
npm.color = true
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
Expand All @@ -862,7 +862,7 @@ t.test('ls', (t) => {
t.match(err.code, 'ELSPROBLEMS', 'should have ELSPROBLEMS error code')
t.match(err.message, /invalid: optional-dep@1.0.0/, 'should have invalid dep error msg')
t.matchSnapshot(redactCwd(result), 'should output tree with empty entry for missing optional deps')
config.color = false
npm.color = false
t.end()
})
})
Expand Down Expand Up @@ -905,7 +905,7 @@ t.test('ls', (t) => {
})

t.test('cycle deps with filter args', (t) => {
config.color = true
npm.color = true
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'test-npm-ls',
Expand Down Expand Up @@ -938,7 +938,7 @@ t.test('ls', (t) => {
ls.exec(['a'], (err) => {
t.ifError(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref')
config.color = false
npm.color = false
t.end()
})
})
Expand Down Expand Up @@ -1042,7 +1042,7 @@ t.test('ls', (t) => {
})

t.test('with args and dedupe entries', (t) => {
config.color = true
npm.color = true
npm.prefix = t.testdir({
'package.json': JSON.stringify({
name: 'dedupe-entries',
Expand Down Expand Up @@ -1085,7 +1085,7 @@ t.test('ls', (t) => {
ls.exec(['@npmcli/b'], (err) => {
t.ifError(err, 'npm ls')
t.matchSnapshot(redactCwd(result), 'should print tree output containing deduped ref')
config.color = false
npm.color = false
t.end()
})
})
Expand Down
69 changes: 46 additions & 23 deletions test/lib/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ const outdated = (dir, opts) => {
},
})
const npm = mockNpm({
...opts,
prefix: dir,
globalDir: `${globalDir}/node_modules`,
config: opts,
output,
})
return new Outdated(npm)
Expand Down Expand Up @@ -175,16 +175,19 @@ t.test('should display outdated deps', t => {

t.test('outdated global', t => {
outdated(null, {
global: true,
config: { global: true },
}).exec([], () => {
console.log(logs)
t.matchSnapshot(logs)
t.end()
})
})

t.test('outdated', t => {
outdated(testDir, {
global: false,
config: {
global: false,
},
color: true,
}).exec([], () => {
t.matchSnapshot(logs)
Expand All @@ -194,9 +197,11 @@ t.test('should display outdated deps', t => {

t.test('outdated --omit=dev', t => {
outdated(testDir, {
global: false,
config: {
global: false,
omit: ['dev'],
},
color: true,
omit: ['dev'],
}).exec([], () => {
t.matchSnapshot(logs)
t.end()
Expand All @@ -205,9 +210,11 @@ t.test('should display outdated deps', t => {

t.test('outdated --omit=dev --omit=peer', t => {
outdated(testDir, {
global: false,
config: {
global: false,
omit: ['dev', 'peer'],
},
color: true,
omit: ['dev', 'peer'],
}).exec([], () => {
t.matchSnapshot(logs)
t.end()
Expand All @@ -216,9 +223,11 @@ t.test('should display outdated deps', t => {

t.test('outdated --omit=prod', t => {
outdated(testDir, {
global: false,
config: {
global: false,
omit: ['prod'],
},
color: true,
omit: ['prod'],
}).exec([], () => {
t.matchSnapshot(logs)
t.end()
Expand All @@ -227,8 +236,10 @@ t.test('should display outdated deps', t => {

t.test('outdated --long', t => {
outdated(testDir, {
global: false,
long: true,
config: {
global: false,
long: true,
},
}).exec([], () => {
t.matchSnapshot(logs)
t.end()
Expand All @@ -237,8 +248,10 @@ t.test('should display outdated deps', t => {

t.test('outdated --json', t => {
outdated(testDir, {
global: false,
json: true,
config: {
global: false,
json: true,
},
}).exec([], () => {
t.matchSnapshot(logs)
t.end()
Expand All @@ -247,9 +260,11 @@ t.test('should display outdated deps', t => {

t.test('outdated --json --long', t => {
outdated(testDir, {
global: false,
json: true,
long: true,
config: {
global: false,
json: true,
long: true,
},
}).exec([], () => {
t.matchSnapshot(logs)
t.end()
Expand All @@ -258,8 +273,10 @@ t.test('should display outdated deps', t => {

t.test('outdated --parseable', t => {
outdated(testDir, {
global: false,
parseable: true,
config: {
global: false,
parseable: true,
},
}).exec([], () => {
t.matchSnapshot(logs)
t.end()
Expand All @@ -268,9 +285,11 @@ t.test('should display outdated deps', t => {

t.test('outdated --parseable --long', t => {
outdated(testDir, {
global: false,
parseable: true,
long: true,
config: {
global: false,
parseable: true,
long: true,
},
}).exec([], () => {
t.matchSnapshot(logs)
t.end()
Expand All @@ -279,7 +298,9 @@ t.test('should display outdated deps', t => {

t.test('outdated --all', t => {
outdated(testDir, {
all: true,
config: {
all: true,
},
}).exec([], () => {
t.matchSnapshot(logs)
t.end()
Expand All @@ -288,7 +309,9 @@ t.test('should display outdated deps', t => {

t.test('outdated specific dep', t => {
outdated(testDir, {
global: false,
config: {
global: false,
},
}).exec(['alpha'], () => {
t.matchSnapshot(logs)
t.end()
Expand Down

0 comments on commit 52165d6

Please sign in to comment.