Skip to content

Commit

Permalink
chore: add whoami command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Sep 17, 2020
1 parent 24f3a54 commit 940e4a9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/lib/whoami.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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/npm.js': { flatOptions: {} },
'../../lib/utils/output.js': (output) => {
t.equal(output, 'foo', 'should output the username')
}
})

whoami([], (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/npm.js': { flatOptions: { json: true } },
'../../lib/utils/output.js': (output) => {
t.equal(output, '"foo"', 'should output the username as json')
}
})

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

0 comments on commit 940e4a9

Please sign in to comment.