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(view): fix git specs #3209

Merged
merged 1 commit into from
May 10, 2021
Merged
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
5 changes: 4 additions & 1 deletion lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ class View extends BaseCommand {
const spec = npa(pkg)

// get the data about this package
let version = spec.rawSpec || this.npm.config.get('tag')
let version = this.npm.config.get('tag')
// rawSpec is the git url if this is from git
if (spec.type !== 'git' && spec.rawSpec)
version = spec.rawSpec

const pckmnt = await packument(spec, opts)

Expand Down
46 changes: 40 additions & 6 deletions tap-snapshots/test/lib/view.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dist
.unpackedSize:1 B

dist-tags:

latest: 1.0.0

published a year ago
`
Expand All @@ -97,18 +97,50 @@ dist
.unpackedSize:1 B

dist-tags:

latest: 1.0.0

published a year ago
`

exports[`test/lib/view.js TAP should log package info package from git > must match snapshot 1`] = `


green@1.0.0 | ACME | deps: 2 | versions: 2
green is a very important color

DEPRECATED!! - true

keywords:colors, green, crayola

bin:green

dist
.tarball:http://hm.green.com/1.0.0.tgz
.shasum:123
.integrity:---
.unpackedSize:1 B

dependencies:
red: 1.0.0
yellow: 1.0.0

maintainers:
-claudia <[[email protected]>
-isaacs <[[email protected]>

dist-tags:
latest: 1.0.0
`

exports[`test/lib/view.js TAP should log package info package with --json and semver range > must match snapshot 1`] = `

[
{
"_npmUser": "claudia <[email protected]>",
"name": "cyan",
"dist-tags": {},
"dist-tags": {
"latest": "1.0.0"
},
"versions": [
"1.0.0",
"1.0.1"
Expand All @@ -125,7 +157,9 @@ exports[`test/lib/view.js TAP should log package info package with --json and se
{
"_npmUser": "claudia <[email protected]>",
"name": "cyan",
"dist-tags": {},
"dist-tags": {
"latest": "1.0.0"
},
"versions": [
"1.0.0",
"1.0.1"
Expand Down Expand Up @@ -249,7 +283,7 @@ dist
.unpackedSize:1 B

dist-tags:

latest: 1.0.0

published by claudia <[[email protected]>
`
Expand All @@ -266,7 +300,7 @@ dist
.unpackedSize:1 B

dist-tags:

latest: 1.0.0

published a year ago
`
Expand Down
28 changes: 24 additions & 4 deletions test/lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const packument = (nv, opts) => {
},
blue: {
name: 'blue',
'dist-tags': {},
'dist-tags': {
latest: '1.0.0',
},
time: {
'1.0.0': '2019-08-06T16:21:09.842Z',
},
Expand All @@ -59,7 +61,9 @@ const packument = (nv, opts) => {
email: '[email protected]',
},
name: 'cyan',
'dist-tags': {},
'dist-tags': {
latest: '1.0.0',
},
versions: {
'1.0.0': {
version: '1.0.0',
Expand Down Expand Up @@ -236,6 +240,8 @@ const packument = (nv, opts) => {
},
},
}
if (nv.type === 'git')
return mocks[nv.hosted.project]
return mocks[nv.name]
}

Expand All @@ -258,7 +264,10 @@ t.test('should log package info', t => {
},
})
const jsonNpm = mockNpm({
config: { json: true },
config: {
json: true,
tag: 'latest',
},
})
const viewJson = new ViewJson(jsonNpm)

Expand All @@ -272,6 +281,13 @@ t.test('should log package info', t => {
})
const viewUnicode = new ViewUnicode(unicodeNpm)

t.test('package from git', t => {
view.exec(['https://github.com/npm/green'], () => {
t.matchSnapshot(logs)
t.end()
})
})

t.test('package with license, bugs, repository and other fields', t => {
view.exec(['[email protected]'], () => {
t.matchSnapshot(logs)
Expand Down Expand Up @@ -384,6 +400,7 @@ t.test('should log info by field name', t => {
})
const jsonNpm = mockNpm({
config: {
tag: 'latest',
json: true,
},
})
Expand Down Expand Up @@ -467,7 +484,10 @@ t.test('should log info by field name', t => {
t.test('throw error if global mode', (t) => {
const View = t.mock('../../lib/view.js')
const npm = mockNpm({
config: { global: true },
config: {
global: true,
tag: 'latest',
},
})
const view = new View(npm)
view.exec([], (err) => {
Expand Down