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

bugs.js « commands « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 91d144b6bdc97073195b240f16e2499b2f6e7ac2 (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
100
const t = require('tap')

const pacote = {
  manifest: async (spec, options) => {
    return spec === 'nobugs' ? {
      name: 'nobugs',
      version: '1.2.3',
    }
      : spec === 'bugsurl' ? {
        name: 'bugsurl',
        version: '1.2.3',
        bugs: 'https://bugzilla.localhost/bugsurl',
      }
      : spec === 'bugsobj' ? {
        name: 'bugsobj',
        version: '1.2.3',
        bugs: { url: 'https://bugzilla.localhost/bugsobj' },
      }
      : spec === 'bugsobj-nourl' ? {
        name: 'bugsobj-nourl',
        version: '1.2.3',
        bugs: { no: 'url here' },
      }
      : spec === 'repourl' ? {
        name: 'repourl',
        version: '1.2.3',
        repository: 'https://github.com/foo/repourl',
      }
      : spec === 'repoobj' ? {
        name: 'repoobj',
        version: '1.2.3',
        repository: { url: 'https://github.com/foo/repoobj' },
      }
      : spec === 'mailtest' ? {
        name: 'mailtest',
        version: '3.7.4',
        bugs: { email: 'hello@example.com' },
      }
      : spec === 'secondmailtest' ? {
        name: 'secondmailtest',
        version: '0.1.1',
        bugs: { email: 'ABC432abc@a.b.example.net' },
      }
      : spec === '.' ? {
        name: 'thispkg',
        version: '1.2.3',
        bugs: 'https://example.com',
      }
      : null
  },
}

// keep a tally of which urls got opened
let opened = {}
const openUrl = async (npm, url, errMsg) => {
  opened[url] = opened[url] || 0
  opened[url]++
}

const Bugs = t.mock('../../../lib/commands/bugs.js', {
  pacote,
  '../../../lib/utils/open-url.js': openUrl,
})

const bugs = new Bugs({ flatOptions: {}, config: { validate: () => {} } })

t.test('usage', (t) => {
  t.match(bugs.usage, 'bugs', 'usage has command name in it')
  t.end()
})

t.afterEach(() => {
  opened = {}
})
t.test('open bugs urls & emails', t => {
  const expect = {
    nobugs: 'https://www.npmjs.com/package/nobugs',
    'bugsobj-nourl': 'https://www.npmjs.com/package/bugsobj-nourl',
    bugsurl: 'https://bugzilla.localhost/bugsurl',
    bugsobj: 'https://bugzilla.localhost/bugsobj',
    repourl: 'https://github.com/foo/repourl/issues',
    repoobj: 'https://github.com/foo/repoobj/issues',
    mailtest: 'mailto:hello@example.com',
    secondmailtest: 'mailto:ABC432abc@a.b.example.net',
    '.': 'https://example.com',
  }
  const keys = Object.keys(expect)
  t.plan(keys.length)
  keys.forEach(pkg => {
    t.test(pkg, async t => {
      await bugs.exec([pkg])
      t.equal(opened[expect[pkg]], 1, 'opened expected url', { opened })
    })
  })
})

t.test('open default package if none specified', async t => {
  await bugs.exec([])
  t.equal(opened['https://example.com'], 1, 'opened expected url', { opened })
})