Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2019-11-20 00:32:57 +0300
committerMichael Perrotte <mike@npmjs.com>2019-12-03 20:13:43 +0300
commit1c65d26ac9f10ac0037094c207d216fbf0e969bf (patch)
treed3588f74b51b66f024df0c9f0e66d9a0cf695bb4 /test
parente4b97962e5fce0d49beb541ce5a0f96aee0525de (diff)
fix(fund): open url for string shorthand
Trying to open url for a package that is using the string shorthand is currently broken using: `npm fund <pkg>` This commit fixes the issue and adds the missing unit and integration tests covering that usecase. Fixes #498 PR-URL: https://github.com/npm/cli/pull/501 Credit: @ruyadorno Close: #501 Reviewed-by: @mikemimik
Diffstat (limited to 'test')
-rw-r--r--test/tap/fund.js15
-rw-r--r--test/tap/utils.funding.js69
2 files changed, 83 insertions, 1 deletions
diff --git a/test/tap/fund.js b/test/tap/fund.js
index 364dc1b6f..97b414bf6 100644
--- a/test/tap/fund.js
+++ b/test/tap/fund.js
@@ -14,6 +14,7 @@ const base = common.pkg
const noFunding = path.join(base, 'no-funding-package')
const maintainerOwnsAllDeps = path.join(base, 'maintainer-owns-all-deps')
const nestedNoFundingPackages = path.join(base, 'nested-no-funding-packages')
+const fundingStringShorthand = path.join(base, 'funding-string-shorthand')
function getFixturePackage ({ name, version, dependencies, funding }, extras) {
const getDeps = () => Object
@@ -36,6 +37,13 @@ function getFixturePackage ({ name, version, dependencies, funding }, extras) {
}
const fixture = new Tacks(Dir({
+ 'funding-string-shorthand': Dir({
+ 'package.json': File({
+ name: 'funding-string-shorthand',
+ version: '0.0.0',
+ funding: 'https://example.com/sponsor'
+ })
+ }),
'no-funding-package': Dir({
'package.json': File({
name: 'no-funding-package',
@@ -254,6 +262,13 @@ testFundCmd({
})
testFundCmd({
+ title: 'fund using string shorthand',
+ assertionMsg: 'should open string-only url',
+ args: ['.', '--no-browser'],
+ opts: { cwd: fundingStringShorthand }
+})
+
+testFundCmd({
title: 'fund using package argument with no browser, using --json option',
assertionMsg: 'should open funding url',
args: ['.', '--json', '--no-browser'],
diff --git a/test/tap/utils.funding.js b/test/tap/utils.funding.js
index 51b89e5f8..709762eac 100644
--- a/test/tap/utils.funding.js
+++ b/test/tap/utils.funding.js
@@ -1,7 +1,7 @@
'use strict'
const { test } = require('tap')
-const { getFundingInfo } = require('../../lib/utils/funding')
+const { retrieveFunding, getFundingInfo } = require('../../lib/utils/funding')
test('empty tree', (t) => {
t.deepEqual(
@@ -545,3 +545,70 @@ test('handle different versions', (t) => {
)
t.end()
})
+
+test('retrieve funding info from valid objects', (t) => {
+ t.deepEqual(
+ retrieveFunding({
+ url: 'http://example.com',
+ type: 'Foo'
+ }),
+ {
+ url: 'http://example.com',
+ type: 'Foo'
+ },
+ 'should return standard object fields'
+ )
+ t.deepEqual(
+ retrieveFunding({
+ extra: 'Foo',
+ url: 'http://example.com',
+ type: 'Foo'
+ }),
+ {
+ extra: 'Foo',
+ url: 'http://example.com',
+ type: 'Foo'
+ },
+ 'should leave untouched extra fields'
+ )
+ t.deepEqual(
+ retrieveFunding({
+ url: 'http://example.com'
+ }),
+ {
+ url: 'http://example.com'
+ },
+ 'should accept url-only objects'
+ )
+ t.end()
+})
+
+test('retrieve funding info from invalid objects', (t) => {
+ t.deepEqual(
+ retrieveFunding({}),
+ {},
+ 'should passthrough empty objects'
+ )
+ t.deepEqual(
+ retrieveFunding(),
+ undefined,
+ 'should not care about undefined'
+ )
+ t.deepEqual(
+ retrieveFunding(),
+ null,
+ 'should not care about null'
+ )
+ t.end()
+})
+
+test('retrieve funding info string shorthand', (t) => {
+ t.deepEqual(
+ retrieveFunding('http://example.com'),
+ {
+ url: 'http://example.com'
+ },
+ 'should accept string shorthand'
+ )
+ t.end()
+})