Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore exit code on "npm outdated" #3799

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/outdated.js
Expand Up @@ -87,6 +87,9 @@ class Outdated extends ArboristWorkspaceCmd {
// sorts list alphabetically
const outdated = this.list.sort((a, b) => a.name.localeCompare(b.name, 'en'))

if (outdated.length > 0)
gfyoung marked this conversation as resolved.
Show resolved Hide resolved
process.exitCode = 1

// return if no outdated packages
if (outdated.length === 0 && !this.npm.config.get('json'))
return
Expand Down
8 changes: 6 additions & 2 deletions smoke-tests/index.js
Expand Up @@ -174,9 +174,13 @@ t.test('npm diff', async t => {

t.test('npm outdated', async t => {
const cmd = `${npmBin} outdated`
const cmdRes = await exec(cmd)
const cmdRes = await exec(cmd).catch(err => {
t.equal(err.code, 1, 'should exit with error code')
return err
})

t.matchSnapshot(cmdRes,
t.not(cmdRes.stderr, '', 'should have stderr output')
t.matchSnapshot(String(cmdRes.stdout),
'should have expected outdated output')
})

Expand Down
26 changes: 26 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 @@ -540,6 +556,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 +571,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 +586,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 +601,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 +614,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 +625,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 +640,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 +655,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 +671,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 @@ -669,6 +694,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