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

whoami.js « lib « test - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3d9618ffa71504959541609e058ac657b82c0d7f (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
const { test } = require('tap')
const requireInject = require('require-inject')

test('whoami', (t) => {
  t.plan(3)
  const Whoami = requireInject('../../lib/whoami.js', {
    '../../lib/utils/get-identity.js': () => Promise.resolve('foo'),
    '../../lib/utils/output.js': (output) => {
      t.equal(output, 'foo', 'should output the username')
    },
  })
  const whoami = new Whoami({ flatOptions: {} })

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

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

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