Skip to content

Commit fdbc5aa

Browse files
committed
test: add outdated tests
1 parent 1dbec09 commit fdbc5aa

File tree

3 files changed

+479
-21
lines changed

3 files changed

+479
-21
lines changed

lib/outdated.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const usage = usageUtil('outdated',
2222
const completion = require('./utils/completion/none.js')
2323

2424
function cmd (args, cb) {
25-
outdated(args, cb)
25+
outdated(args)
2626
.then(() => cb())
2727
.catch(cb)
2828
}
@@ -78,14 +78,12 @@ async function outdated (args) {
7878
}
7979
output(table(outTable, tableOpts))
8080
}
81-
82-
process.exitCode = outdated.length ? 1 : 0
8381
}
8482

8583
async function outdated_ (tree, deps, opts) {
8684
const list = []
87-
const edges = new Set()
8885

86+
const edges = new Set()
8987
function getEdges (nodes, type) {
9088
const getEdgesIn = (node) => {
9189
for (const edge of node.edgesIn) {
@@ -94,8 +92,14 @@ async function outdated_ (tree, deps, opts) {
9492
}
9593

9694
const getEdgesOut = (node) => {
97-
for (const edge of node.edgesOut.values()) {
98-
edges.add(edge)
95+
if (opts.global) {
96+
for (const child of node.children.values()) {
97+
edges.add(child)
98+
}
99+
} else {
100+
for (const edge of node.edgesOut.values()) {
101+
edges.add(edge)
102+
}
99103
}
100104
}
101105

@@ -107,30 +111,19 @@ async function outdated_ (tree, deps, opts) {
107111
}
108112
}
109113

110-
// packument fetching memoizing
111-
const packuments = new Map()
112114
async function getPackument (spec) {
113-
if (packuments.has(spec)) {
114-
return packuments.get(spec)
115-
}
116115
const packument = await pacote.packument(spec, {
117116
fullMetadata: npm.flatOptions.long,
118117
preferOnline: true
119118
})
120-
packuments.set(spec, packument)
121119
return packument
122120
}
123121

124122
async function getOutdatedInfo (edge) {
125123
const spec = npa(edge.name)
126-
const node = edge.to
127-
const {
128-
path,
129-
location,
130-
package: {
131-
version: current
132-
}
133-
} = node || { package: {} }
124+
const node = edge.to || edge
125+
const { path, location } = node
126+
const { version: current } = node.package || {}
134127

135128
const type = edge.optional ? 'optionalDependencies'
136129
: edge.peer ? 'peerDependencies'
@@ -160,7 +153,7 @@ async function outdated_ (tree, deps, opts) {
160153
location,
161154
wanted: wanted.version,
162155
latest: latest.version,
163-
dependent: edge.from.name,
156+
dependent: edge.from ? edge.from.name : 'global',
164157
homepage: packument.homepage
165158
})
166159
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/* IMPORTANT
2+
* This snapshot file is auto-generated, but designed for humans.
3+
* It should be checked into source control and tracked carefully.
4+
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
5+
* Make sure to inspect the output below. Do not ignore changes!
6+
*/
7+
'use strict'
8+
exports[`test/lib/outdated.js TAP should display outdated deps outdated --all > must match snapshot 1`] = `
9+
10+
Package Current Wanted Latest Location Depended by
11+
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps
12+
beta 1.0.0 1.0.1 1.0.1 node_modules/beta outdated-should-display-outdated-deps
13+
gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-outdated-deps
14+
theta MISSING 1.0.1 1.0.1 - outdated-should-display-outdated-deps
15+
`
16+
17+
exports[`test/lib/outdated.js TAP should display outdated deps outdated --json --long > must match snapshot 1`] = `
18+
19+
{
20+
"alpha": {
21+
"current": "1.0.0",
22+
"wanted": "1.0.1",
23+
"latest": "1.0.1",
24+
"dependent": "outdated-should-display-outdated-deps",
25+
"location": "/cli/test/lib/outdated-should-display-outdated-deps/node_modules/alpha",
26+
"type": "dependencies"
27+
},
28+
"beta": {
29+
"current": "1.0.0",
30+
"wanted": "1.0.1",
31+
"latest": "1.0.1",
32+
"dependent": "outdated-should-display-outdated-deps",
33+
"location": "/cli/test/lib/outdated-should-display-outdated-deps/node_modules/beta",
34+
"type": "peerDependencies"
35+
},
36+
"gamma": {
37+
"current": "1.0.1",
38+
"wanted": "1.0.1",
39+
"latest": "2.0.0",
40+
"dependent": "outdated-should-display-outdated-deps",
41+
"location": "/cli/test/lib/outdated-should-display-outdated-deps/node_modules/gamma",
42+
"type": "dependencies"
43+
},
44+
"theta": {
45+
"wanted": "1.0.1",
46+
"latest": "1.0.1",
47+
"dependent": "outdated-should-display-outdated-deps",
48+
"type": "dependencies"
49+
}
50+
}
51+
`
52+
53+
exports[`test/lib/outdated.js TAP should display outdated deps outdated --json > must match snapshot 1`] = `
54+
55+
{
56+
"alpha": {
57+
"current": "1.0.0",
58+
"wanted": "1.0.1",
59+
"latest": "1.0.1",
60+
"dependent": "outdated-should-display-outdated-deps",
61+
"location": "/cli/test/lib/outdated-should-display-outdated-deps/node_modules/alpha"
62+
},
63+
"beta": {
64+
"current": "1.0.0",
65+
"wanted": "1.0.1",
66+
"latest": "1.0.1",
67+
"dependent": "outdated-should-display-outdated-deps",
68+
"location": "/cli/test/lib/outdated-should-display-outdated-deps/node_modules/beta"
69+
},
70+
"gamma": {
71+
"current": "1.0.1",
72+
"wanted": "1.0.1",
73+
"latest": "2.0.0",
74+
"dependent": "outdated-should-display-outdated-deps",
75+
"location": "/cli/test/lib/outdated-should-display-outdated-deps/node_modules/gamma"
76+
},
77+
"theta": {
78+
"wanted": "1.0.1",
79+
"latest": "1.0.1",
80+
"dependent": "outdated-should-display-outdated-deps"
81+
}
82+
}
83+
`
84+
85+
exports[`test/lib/outdated.js TAP should display outdated deps outdated --long > must match snapshot 1`] = `
86+
87+
Package Current Wanted Latest Location Depended by Package Type Homepage
88+
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps dependencies
89+
beta 1.0.0 1.0.1 1.0.1 node_modules/beta outdated-should-display-outdated-deps peerDependencies
90+
gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-outdated-deps dependencies
91+
theta MISSING 1.0.1 1.0.1 - outdated-should-display-outdated-deps dependencies
92+
`
93+
94+
exports[`test/lib/outdated.js TAP should display outdated deps outdated --parseable --long > must match snapshot 1`] = `
95+
96+
/cli/test/lib/outdated-should-display-outdated-deps/node_modules/alpha:[email protected]:[email protected]:[email protected]:outdated-should-display-outdated-deps:dependencies:
97+
/cli/test/lib/outdated-should-display-outdated-deps/node_modules/beta:[email protected]:[email protected]:[email protected]:outdated-should-display-outdated-deps:peerDependencies:
98+
/cli/test/lib/outdated-should-display-outdated-deps/node_modules/gamma:[email protected]:[email protected]:[email protected]:outdated-should-display-outdated-deps:dependencies:
99+
:[email protected]:MISSING:[email protected]:outdated-should-display-outdated-deps:dependencies:
100+
`
101+
102+
exports[`test/lib/outdated.js TAP should display outdated deps outdated --parseable > must match snapshot 1`] = `
103+
104+
/cli/test/lib/outdated-should-display-outdated-deps/node_modules/alpha:[email protected]:[email protected]:[email protected]:outdated-should-display-outdated-deps
105+
/cli/test/lib/outdated-should-display-outdated-deps/node_modules/beta:[email protected]:[email protected]:[email protected]:outdated-should-display-outdated-deps
106+
/cli/test/lib/outdated-should-display-outdated-deps/node_modules/gamma:[email protected]:[email protected]:[email protected]:outdated-should-display-outdated-deps
107+
:[email protected]:MISSING:[email protected]:outdated-should-display-outdated-deps
108+
`
109+
110+
exports[`test/lib/outdated.js TAP should display outdated deps outdated > must match snapshot 1`] = `
111+
112+
Package Current Wanted Latest Location Depended by
113+
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps
114+
beta 1.0.0 1.0.1 1.0.1 node_modules/beta outdated-should-display-outdated-deps
115+
gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-outdated-deps
116+
theta MISSING 1.0.1 1.0.1 - outdated-should-display-outdated-deps
117+
`
118+
119+
exports[`test/lib/outdated.js TAP should display outdated deps outdated global > must match snapshot 1`] = `
120+
121+
Package Current Wanted Latest Location Depended by
122+
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha global
123+
`
124+
125+
exports[`test/lib/outdated.js TAP should display outdated deps outdated specific dep > must match snapshot 1`] = `
126+
127+
Package Current Wanted Latest Location Depended by
128+
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps
129+
`

0 commit comments

Comments
 (0)