Skip to content

Commit

Permalink
(fix) restore exit code on "npm outdated"
Browse files Browse the repository at this point in the history
closes: #2556
xref: #1750

The xref'ed PR apparently dropped this behavior
without any explanation.
  • Loading branch information
gfyoung committed Sep 26, 2021
1 parent 6ae8cbe commit 0e03826
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/outdated.js
Expand Up @@ -87,6 +87,8 @@ class Outdated extends ArboristWorkspaceCmd {
// sorts list alphabetically
const outdated = this.list.sort((a, b) => a.name.localeCompare(b.name, 'en'))

process.exitCode = outdated.length ? 1 : 0

// return if no outdated packages
if (outdated.length === 0 && !this.npm.config.get('json'))
return
Expand Down
31 changes: 31 additions & 0 deletions test/lib/outdated.js
Expand Up @@ -102,6 +102,10 @@ const outdated = (dir, opts) => {

t.beforeEach(() => logs = '')

const { exitCode } = process

t.afterEach(() => process.exitCode = exitCode)

const redactCwd = (path) => {
const normalizePath = p => p
.replace(/\\+/g, '/')
Expand Down Expand Up @@ -175,6 +179,7 @@ t.test('should display outdated deps', t => {
outdated(null, {
config: { global: true },
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -187,6 +192,7 @@ t.test('should display outdated deps', t => {
},
color: true,
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -200,6 +206,7 @@ t.test('should display outdated deps', t => {
},
color: true,
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -213,6 +220,7 @@ t.test('should display outdated deps', t => {
},
color: true,
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -226,6 +234,7 @@ t.test('should display outdated deps', t => {
},
color: true,
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -238,6 +247,7 @@ t.test('should display outdated deps', t => {
long: true,
},
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -250,6 +260,7 @@ t.test('should display outdated deps', t => {
json: true,
},
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -263,6 +274,7 @@ t.test('should display outdated deps', t => {
long: true,
},
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -275,6 +287,7 @@ t.test('should display outdated deps', t => {
parseable: true,
},
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -288,6 +301,7 @@ t.test('should display outdated deps', t => {
long: true,
},
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -299,6 +313,7 @@ t.test('should display outdated deps', t => {
all: true,
},
}).exec([], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand All @@ -310,6 +325,7 @@ t.test('should display outdated deps', t => {
global: false,
},
}).exec(['cat'], () => {
t.equal(process.exitCode, 1)
t.matchSnapshot(logs)
t.end()
})
Expand Down Expand Up @@ -341,6 +357,7 @@ t.test('should return if no outdated deps', t => {
global: false,
}).exec([], () => {
t.equal(logs.length, 0, 'no logs')
t.equal(process.exitCode, 0)
t.end()
})
})
Expand Down Expand Up @@ -388,6 +405,7 @@ t.test('should skip missing non-prod deps', t => {
global: false,
}).exec([], () => {
t.equal(logs.length, 0, 'no logs')
t.equal(process.exitCode, 0)
t.end()
})
})
Expand All @@ -413,6 +431,7 @@ t.test('should skip invalid pkg ranges', t => {

outdated(testDir, {}).exec([], () => {
t.equal(logs.length, 0, 'no logs')
t.equal(process.exitCode, 0)
t.end()
})
})
Expand All @@ -438,6 +457,7 @@ t.test('should skip git specs', t => {

outdated(testDir, {}).exec([], () => {
t.equal(logs.length, 0, 'no logs')
t.equal(process.exitCode, 0)
t.end()
})
})
Expand Down Expand Up @@ -540,6 +560,7 @@ t.test('workspaces', async t => {
rej(err)

t.matchSnapshot(logs, 'should display ws outdated deps human output')
t.equal(process.exitCode, 1)
res()
})
})
Expand All @@ -554,6 +575,7 @@ t.test('workspaces', async t => {
rej(err)

t.matchSnapshot(logs, 'should display ws outdated deps json output')
t.equal(process.exitCode, 1)
res()
})
})
Expand All @@ -568,6 +590,7 @@ t.test('workspaces', async t => {
rej(err)

t.matchSnapshot(logs, 'should display ws outdated deps parseable output')
t.equal(process.exitCode, 1)
res()
})
})
Expand All @@ -582,6 +605,7 @@ t.test('workspaces', async t => {
rej(err)

t.matchSnapshot(logs, 'should display all dependencies')
t.equal(process.exitCode, 1)
res()
})
})
Expand All @@ -594,6 +618,7 @@ t.test('workspaces', async t => {
rej(err)

t.matchSnapshot(logs, 'should highlight ws in dependend by section')
t.equal(process.exitCode, 1)
res()
})
})
Expand All @@ -604,6 +629,7 @@ t.test('workspaces', async t => {
rej(err)

t.matchSnapshot(logs, 'should display results filtered by ws')
t.equal(process.exitCode, 1)
res()
})
})
Expand All @@ -618,6 +644,7 @@ t.test('workspaces', async t => {
rej(err)

t.matchSnapshot(logs, 'should display json results filtered by ws')
t.equal(process.exitCode, 1)
res()
})
})
Expand All @@ -632,6 +659,7 @@ t.test('workspaces', async t => {
rej(err)

t.matchSnapshot(logs, 'should display parseable results filtered by ws')
t.equal(process.exitCode, 1)
res()
})
})
Expand All @@ -647,6 +675,7 @@ t.test('workspaces', async t => {

t.matchSnapshot(logs,
'should display nested deps when filtering by ws and using --all')
t.equal(process.exitCode, 1)
res()
})
})
Expand All @@ -658,6 +687,7 @@ t.test('workspaces', async t => {

t.matchSnapshot(logs,
'should display no results if ws has no deps to display')
t.equal(process.exitCode, 0)
res()
})
})
Expand All @@ -669,6 +699,7 @@ t.test('workspaces', async t => {

t.matchSnapshot(logs,
'should display missing deps when filtering by ws')
t.equal(process.exitCode, 1)
res()
})
})
Expand Down

0 comments on commit 0e03826

Please sign in to comment.