1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
'use strict'
const path = require('path')
const test = require('tap').test
const Tacks = require('tacks')
const Dir = Tacks.Dir
const File = Tacks.File
const common = require('../common-tap.js')
const base = common.pkg
const singlePackage = path.join(base, 'single-funding-package')
const multiplePackages = path.join(base, 'top-level-funding')
function getFixturePackage ({ name, version, dependencies, funding }) {
return Dir({
'package.json': File({
name,
version: version || '1.0.0',
funding: funding || {
type: 'individual',
url: 'http://example.com/donate'
},
dependencies: dependencies || {}
})
})
}
const fixture = new Tacks(Dir({
'package.json': File({}),
'single-funding-package': getFixturePackage({
name: 'single-funding-package'
}),
'top-level-funding': getFixturePackage({
name: 'top-level-funding',
dependencies: {
'dep-foo': 'file:../dep-foo',
'dep-bar': 'file:../dep-bar'
}
}),
'dep-foo': getFixturePackage({
name: 'dep-foo',
funding: {
type: 'corporate',
url: 'https://corp.example.com/sponsor'
},
dependencies: {
'sub-dep-bar': 'file:../sub-dep-bar'
}
}),
'dep-bar': getFixturePackage({
name: 'dep-bar',
version: '2.1.0',
dependencies: {
'sub-dep-bar': 'file:../sub-dep-bar'
}
}),
'sub-dep-bar': getFixturePackage({
name: 'sub-dep-bar',
funding: {
type: 'foo',
url: 'http://example.com/foo'
}
})
}))
test('mention npm fund upon installing single dependency', function (t) {
setup(t)
common.npm(['install', '--no-save', singlePackage], {cwd: base}, function (err, code, stdout, stderr) {
if (err) throw err
t.is(code, 0, 'installed successfully')
t.is(stderr, '', 'no warnings')
t.includes(stdout, '1 package is looking for funding', 'should print amount of packages needing funding')
t.includes(stdout, ' run `npm fund` for details', 'should print npm fund mention')
t.end()
})
})
test('mention npm fund upon installing multiple dependencies', function (t) {
setup(t)
common.npm(['install', '--no-save', multiplePackages], {cwd: base}, function (err, code, stdout, stderr) {
if (err) throw err
t.is(code, 0, 'installed successfully')
t.is(stderr, '', 'no warnings')
t.includes(stdout, '4 packages are looking for funding', 'should print amount of packages needing funding')
t.includes(stdout, ' run `npm fund` for details', 'should print npm fund mention')
t.end()
})
})
test('skips mention npm fund using --no-fund option', function (t) {
setup(t)
common.npm(['install', '--no-save', '--no-fund', multiplePackages], {cwd: base}, function (err, code, stdout, stderr) {
if (err) throw err
t.is(code, 0, 'installed successfully')
t.is(stderr, '', 'no warnings')
t.doesNotHave(stdout, '4 packages are looking for funding', 'should print amount of packages needing funding')
t.doesNotHave(stdout, ' run `npm fund` for details', 'should print npm fund mention')
t.end()
})
})
test('mention packages looking for funding using --json', function (t) {
setup(t)
common.npm(['install', '--no-save', '--json', multiplePackages], {cwd: base}, function (err, code, stdout, stderr) {
if (err) throw err
t.is(code, 0, 'installed successfully')
t.is(stderr, '', 'no warnings')
const res = JSON.parse(stdout)
t.match(res.funding, '4 packages are looking for funding', 'should print amount of packages needing funding')
t.end()
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})
function setup (t) {
fixture.create(base)
t.teardown(() => {
cleanup()
})
}
function cleanup () {
fixture.remove(base)
}
|