aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/install.fund.js
blob: fca5fb3afd123cea0772f10e86d86a118c8fe0cc (plain)
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
'use strict'

const { test } = require('tap')
const { getPrintFundingReport } = require('../../lib/install/fund')

test('message when there are no funding found', (t) => {
  t.equal(
    getPrintFundingReport({}),
    '',
    'should not print any message if missing info'
  )
  t.equal(
    getPrintFundingReport({
      name: 'foo',
      version: '1.0.0',
      dependencies: {}
    }),
    '',
    'should not print any message if package has no dependencies'
  )
  t.equal(
    getPrintFundingReport({
      fund: true,
      idealTree: {
        name: 'foo',
        version: '1.0.0',
        dependencies: {
          bar: {},
          lorem: {}
        }
      }
    }),
    '',
    'should not print any message if no package has funding info'
  )
  t.end()
})

test('print appropriate message for a single package', (t) => {
  t.equal(
    getPrintFundingReport({
      fund: true,
      idealTree: {
        name: 'foo',
        version: '1.0.0',
        children: [
          {
            package: {
              name: 'bar',
              version: '1.0.0',
              funding: { type: 'foo', url: 'http://example.com' }
            }
          }
        ]
      }
    }).replace(/[\r\n]+/g, '\n'),
    `\n1 package is looking for funding\n  run \`npm fund\` for details\n`,
    'should print single package message'
  )
  t.end()
})

test('print appropriate message for many packages', (t) => {
  t.equal(
    getPrintFundingReport({
      fund: true,
      idealTree: {
        name: 'foo',
        version: '1.0.0',
        children: [
          {
            package: {
              name: 'bar',
              version: '1.0.0',
              funding: { type: 'foo', url: 'http://example.com' }
            }
          },
          {
            package: {
              name: 'lorem',
              version: '1.0.0',
              funding: { type: 'foo', url: 'http://example.com' }
            }
          },
          {
            package: {
              name: 'ipsum',
              version: '1.0.0',
              funding: { type: 'foo', url: 'http://example.com' }
            }
          }
        ]
      }
    }).replace(/[\r\n]+/g, '\n'),
    `\n3 packages are looking for funding\n  run \`npm fund\` for details\n`,
    'should print many package message'
  )
  t.end()
})