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

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/test/lib/whoami.js')
-rw-r--r--deps/npm/test/lib/whoami.js50
1 files changed, 17 insertions, 33 deletions
diff --git a/deps/npm/test/lib/whoami.js b/deps/npm/test/lib/whoami.js
index 9190e3858b1..c54ee2a5a2b 100644
--- a/deps/npm/test/lib/whoami.js
+++ b/deps/npm/test/lib/whoami.js
@@ -1,41 +1,25 @@
const t = require('tap')
-const { fake: mockNpm } = require('../fixtures/mock-npm')
+const { real: 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)
+const username = 'foo'
+const { joinedOutput, command, npm } = mockNpm(t, {
+ '../../lib/utils/get-identity.js': () => Promise.resolve(username),
+})
- whoami.exec([], (err) => {
- t.error(err, 'npm whoami')
- t.ok('should successfully print username')
- })
+t.before(async () => {
+ await npm.load()
})
-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)
+t.test('npm whoami', async (t) => {
+ await command('whoami')
+ t.equal(joinedOutput(), username, 'should print username')
+})
- whoami.exec([], (err) => {
- t.error(err, 'npm whoami')
- t.ok('should successfully print username as json')
+t.test('npm whoami --json', async (t) => {
+ t.teardown(() => {
+ npm.config.set('json', false)
})
+ npm.config.set('json', true)
+ await command('whoami')
+ t.equal(JSON.parse(joinedOutput()), username, 'should print username')
})