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

test: add outdated tests #1750

Closed
wants to merge 2 commits into from
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions lib/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const usage = usageUtil('outdated',
const completion = require('./utils/completion/none.js')

function cmd (args, cb) {
outdated(args, cb)
outdated(args)
.then(() => cb())
.catch(cb)
}
Expand Down Expand Up @@ -78,14 +78,12 @@ async function outdated (args) {
}
output(table(outTable, tableOpts))
}

process.exitCode = outdated.length ? 1 : 0
}

async function outdated_ (tree, deps, opts) {
const list = []
const edges = new Set()

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

const getEdgesOut = (node) => {
for (const edge of node.edgesOut.values()) {
edges.add(edge)
if (opts.global) {
for (const child of node.children.values()) {
edges.add(child)
}
} else {
for (const edge of node.edgesOut.values()) {
edges.add(edge)
}
}
}

Expand All @@ -107,30 +111,19 @@ async function outdated_ (tree, deps, opts) {
}
}

// packument fetching memoizing
const packuments = new Map()
async function getPackument (spec) {
if (packuments.has(spec)) {
return packuments.get(spec)
}
const packument = await pacote.packument(spec, {
fullMetadata: npm.flatOptions.long,
preferOnline: true
})
packuments.set(spec, packument)
return packument
}

async function getOutdatedInfo (edge) {
const spec = npa(edge.name)
const node = edge.to
const {
path,
location,
package: {
version: current
}
} = node || { package: {} }
const node = edge.to || edge
const { path, location } = node
const { version: current } = node.package || {}

const type = edge.optional ? 'optionalDependencies'
: edge.peer ? 'peerDependencies'
Expand Down Expand Up @@ -160,7 +153,7 @@ async function outdated_ (tree, deps, opts) {
location,
wanted: wanted.version,
latest: latest.version,
dependent: edge.from.name,
dependent: edge.from ? edge.from.name : 'global',
homepage: packument.homepage
})
}
Expand Down
129 changes: 129 additions & 0 deletions tap-snapshots/test-lib-outdated.js-TAP.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/lib/outdated.js TAP should display outdated deps outdated --all > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps
beta 1.0.0 1.0.1 1.0.1 node_modules/beta outdated-should-display-outdated-deps
gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-outdated-deps
theta MISSING 1.0.1 1.0.1 - outdated-should-display-outdated-deps
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --json --long > must match snapshot 1`] = `

{
"alpha": {
"current": "1.0.0",
"wanted": "1.0.1",
"latest": "1.0.1",
"dependent": "outdated-should-display-outdated-deps",
"location": "{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/alpha",
"type": "dependencies"
},
"beta": {
"current": "1.0.0",
"wanted": "1.0.1",
"latest": "1.0.1",
"dependent": "outdated-should-display-outdated-deps",
"location": "{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/beta",
"type": "peerDependencies"
},
"gamma": {
"current": "1.0.1",
"wanted": "1.0.1",
"latest": "2.0.0",
"dependent": "outdated-should-display-outdated-deps",
"location": "{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/gamma",
"type": "dependencies"
},
"theta": {
"wanted": "1.0.1",
"latest": "1.0.1",
"dependent": "outdated-should-display-outdated-deps",
"type": "dependencies"
}
}
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --json > must match snapshot 1`] = `

{
"alpha": {
"current": "1.0.0",
"wanted": "1.0.1",
"latest": "1.0.1",
"dependent": "outdated-should-display-outdated-deps",
"location": "{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/alpha"
},
"beta": {
"current": "1.0.0",
"wanted": "1.0.1",
"latest": "1.0.1",
"dependent": "outdated-should-display-outdated-deps",
"location": "{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/beta"
},
"gamma": {
"current": "1.0.1",
"wanted": "1.0.1",
"latest": "2.0.0",
"dependent": "outdated-should-display-outdated-deps",
"location": "{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/gamma"
},
"theta": {
"wanted": "1.0.1",
"latest": "1.0.1",
"dependent": "outdated-should-display-outdated-deps"
}
}
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --long > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by Package Type Homepage
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps dependencies
beta 1.0.0 1.0.1 1.0.1 node_modules/beta outdated-should-display-outdated-deps peerDependencies
gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-outdated-deps dependencies
theta MISSING 1.0.1 1.0.1 - outdated-should-display-outdated-deps dependencies
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --parseable --long > must match snapshot 1`] = `

{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/alpha:alpha@1.0.1:alpha@1.0.0:alpha@1.0.1:outdated-should-display-outdated-deps:dependencies:
{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/beta:beta@1.0.1:beta@1.0.0:beta@1.0.1:outdated-should-display-outdated-deps:peerDependencies:
{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/gamma:gamma@1.0.1:gamma@1.0.1:gamma@2.0.0:outdated-should-display-outdated-deps:dependencies:
:theta@1.0.1:MISSING:theta@1.0.1:outdated-should-display-outdated-deps:dependencies:
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated --parseable > must match snapshot 1`] = `

{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/alpha:alpha@1.0.1:alpha@1.0.0:alpha@1.0.1:outdated-should-display-outdated-deps
{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/beta:beta@1.0.1:beta@1.0.0:beta@1.0.1:outdated-should-display-outdated-deps
{CWD}/test/lib/outdated-should-display-outdated-deps/node_modules/gamma:gamma@1.0.1:gamma@1.0.1:gamma@2.0.0:outdated-should-display-outdated-deps
:theta@1.0.1:MISSING:theta@1.0.1:outdated-should-display-outdated-deps
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps
beta 1.0.0 1.0.1 1.0.1 node_modules/beta outdated-should-display-outdated-deps
gamma 1.0.1 1.0.1 2.0.0 node_modules/gamma outdated-should-display-outdated-deps
theta MISSING 1.0.1 1.0.1 - outdated-should-display-outdated-deps
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated global > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha global
`

exports[`test/lib/outdated.js TAP should display outdated deps outdated specific dep > must match snapshot 1`] = `

Package Current Wanted Latest Location Depended by
alpha 1.0.0 1.0.1 1.0.1 node_modules/alpha outdated-should-display-outdated-deps
`
Loading