1'use strict' 2 3const { test } = require('tap') 4const { getPrintFundingReport } = require('../../lib/install/fund') 5 6test('message when there are no funding found', (t) => { 7 t.equal( 8 getPrintFundingReport({}), 9 '', 10 'should not print any message if missing info' 11 ) 12 t.equal( 13 getPrintFundingReport({ 14 name: 'foo', 15 version: '1.0.0', 16 dependencies: {} 17 }), 18 '', 19 'should not print any message if package has no dependencies' 20 ) 21 t.equal( 22 getPrintFundingReport({ 23 fund: true, 24 idealTree: { 25 name: 'foo', 26 version: '1.0.0', 27 dependencies: { 28 bar: {}, 29 lorem: {} 30 } 31 } 32 }), 33 '', 34 'should not print any message if no package has funding info' 35 ) 36 t.end() 37}) 38 39test('print appropriate message for a single package', (t) => { 40 t.equal( 41 getPrintFundingReport({ 42 fund: true, 43 idealTree: { 44 name: 'foo', 45 version: '1.0.0', 46 children: [ 47 { 48 package: { 49 name: 'bar', 50 version: '1.0.0', 51 funding: { type: 'foo', url: 'http://example.com' } 52 } 53 } 54 ] 55 } 56 }).replace(/[\r\n]+/g, '\n'), 57 `\n1 package is looking for funding\n run \`npm fund\` for details\n`, 58 'should print single package message' 59 ) 60 t.end() 61}) 62 63test('print appropriate message for many packages', (t) => { 64 t.equal( 65 getPrintFundingReport({ 66 fund: true, 67 idealTree: { 68 name: 'foo', 69 version: '1.0.0', 70 children: [ 71 { 72 package: { 73 name: 'bar', 74 version: '1.0.0', 75 funding: { type: 'foo', url: 'http://example.com' } 76 } 77 }, 78 { 79 package: { 80 name: 'lorem', 81 version: '1.0.0', 82 funding: { type: 'foo', url: 'http://example.com' } 83 } 84 }, 85 { 86 package: { 87 name: 'ipsum', 88 version: '1.0.0', 89 funding: { type: 'foo', url: 'http://example.com' } 90 } 91 } 92 ] 93 } 94 }).replace(/[\r\n]+/g, '\n'), 95 `\n3 packages are looking for funding\n run \`npm fund\` for details\n`, 96 'should print many package message' 97 ) 98 t.end() 99}) 100