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

whoami.js « lib « test « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9190e3858b137a5e6c7d5d22bccd6bf4467f3a8c (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
const t = require('tap')
const { fake: mockNpm } = require('../fixtures/mock-npm')

t.test('whoami', (t) => {
  t.plan(3)
  const Whoami = t.mock('../../lib/whoami.js', {
    '../../lib/utils/get-identity.js': () => Promise.resolve('foo'),
  })
  const npm = mockNpm({
    config: { json: false },
    output: (output) => {
      t.equal(output, 'foo', 'should output the username')
    },
  })

  const whoami = new Whoami(npm)

  whoami.exec([], (err) => {
    t.error(err, 'npm whoami')
    t.ok('should successfully print username')
  })
})

t.test('whoami json', (t) => {
  t.plan(3)
  const Whoami = t.mock('../../lib/whoami.js', {
    '../../lib/utils/get-identity.js': () => Promise.resolve('foo'),
  })
  const npm = mockNpm({
    config: { json: true },
    output: (output) => {
      t.equal(output, '"foo"', 'should output the username')
    },
  })
  const whoami = new Whoami(npm)

  whoami.exec([], (err) => {
    t.error(err, 'npm whoami')
    t.ok('should successfully print username as json')
  })
})