summaryrefslogtreecommitdiff
path: root/deps/npm/test/lib/commands/team.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/test/lib/commands/team.js')
-rw-r--r--deps/npm/test/lib/commands/team.js294
1 files changed, 162 insertions, 132 deletions
diff --git a/deps/npm/test/lib/commands/team.js b/deps/npm/test/lib/commands/team.js
index 792418788b..a13a56d986 100644
--- a/deps/npm/test/lib/commands/team.js
+++ b/deps/npm/test/lib/commands/team.js
@@ -1,39 +1,33 @@
const t = require('tap')
-const { fake: mockNpm } = require('../../fixtures/mock-npm')
-
-let result = ''
-const libnpmteam = {
- async add () {},
- async create () {},
- async destroy () {},
- async lsTeams () {},
- async lsUsers () {},
- async rm () {},
-}
-const npm = mockNpm({
- flatOptions: {},
- config: {
- loglevel: 'info',
- },
- output: (...msg) => {
- result += msg.join('\n')
- },
-})
-const mocks = {
- libnpmteam,
- 'cli-columns': a => a.join(' '),
-}
-
-t.afterEach(() => {
- result = ''
- npm.flatOptions = {}
- npm.config.set('loglevel', 'info')
-})
+const mockNpm = require('../../fixtures/mock-npm')
+
+t.cleanSnapshot = s => s.trim().replace(/\n+/g, '\n')
+
+const mockTeam = async (t, { libnpmteam, ...opts } = {}) => {
+ const mock = await mockNpm(t, {
+ ...opts,
+ mocks: {
+ // XXX: this should be refactored to use the mock registry
+ libnpmteam: libnpmteam || {
+ async add () {},
+ async create () {},
+ async destroy () {},
+ async lsTeams () {},
+ async lsUsers () {},
+ async rm () {},
+ },
+ },
+ })
-const Team = t.mock('../../../lib/commands/team.js', mocks)
-const team = new Team(npm)
+ return {
+ ...mock,
+ team: { exec: (args) => mock.npm.exec('team', args) },
+ result: () => mock.joinedOutput(),
+ }
+}
t.test('no args', async t => {
+ const { team } = await mockTeam(t)
await t.rejects(
team.exec([]),
'usage instructions',
@@ -43,29 +37,35 @@ t.test('no args', async t => {
t.test('team add <scope:team> <user>', async t => {
t.test('default output', async t => {
+ const { team, result } = await mockTeam(t)
+
await team.exec(['add', '@npmcli:developers', 'foo'])
- t.matchSnapshot(result, 'should output success result for add user')
+ t.matchSnapshot(result(), 'should output success result for add user')
})
t.test('--parseable', async t => {
- npm.flatOptions.parseable = true
+ const { team, result } = await mockTeam(t, {
+ config: { parseable: true },
+ })
await team.exec(['add', '@npmcli:developers', 'foo'])
t.matchSnapshot(
- result,
+ result(),
'should output success result for parseable add user'
)
})
t.test('--json', async t => {
- npm.flatOptions.json = true
+ const { team, result } = await mockTeam(t, {
+ config: { json: true },
+ })
await team.exec(['add', '@npmcli:developers', 'foo'])
t.same(
- JSON.parse(result),
+ JSON.parse(result()),
{
added: true,
team: 'npmcli:developers',
@@ -76,39 +76,47 @@ t.test('team add <scope:team> <user>', async t => {
})
t.test('--silent', async t => {
- npm.config.set('loglevel', 'silent')
+ const { team, result } = await mockTeam(t, {
+ config: { silent: true },
+ })
await team.exec(['add', '@npmcli:developers', 'foo'])
- t.same(result, '', 'should not output success if silent')
+ t.same(result(), '', 'should not output success if silent')
})
})
t.test('team create <scope:team>', async t => {
t.test('default output', async t => {
+ const { team, result } = await mockTeam(t)
+
await team.exec(['create', '@npmcli:newteam'])
- t.matchSnapshot(result, 'should output success result for create team')
+ t.matchSnapshot(result(), 'should output success result for create team')
})
t.test('--parseable', async t => {
- npm.flatOptions.parseable = true
+ const { team, result } = await mockTeam(t, {
+ config: { parseable: true },
+ })
await team.exec(['create', '@npmcli:newteam'])
t.matchSnapshot(
- result,
+ result(),
'should output parseable success result for create team'
)
})
t.test('--json', async t => {
- npm.flatOptions.json = true
+ const { team, result } = await mockTeam(t, {
+ config: { json: true },
+ })
await team.exec(['create', '@npmcli:newteam'])
t.same(
- JSON.parse(result),
+ JSON.parse(result()),
{
created: true,
team: 'npmcli:newteam',
@@ -118,31 +126,38 @@ t.test('team create <scope:team>', async t => {
})
t.test('--silent', async t => {
- npm.config.set('loglevel', 'silent')
+ const { team, result } = await mockTeam(t, {
+ config: { silent: true },
+ })
await team.exec(['create', '@npmcli:newteam'])
- t.same(result, '', 'should not output create success if silent')
+ t.same(result(), '', 'should not output create success if silent')
})
})
t.test('team destroy <scope:team>', async t => {
t.test('default output', async t => {
+ const { team, result } = await mockTeam(t)
await team.exec(['destroy', '@npmcli:newteam'])
- t.matchSnapshot(result, 'should output success result for destroy team')
+ t.matchSnapshot(result(), 'should output success result for destroy team')
})
t.test('--parseable', async t => {
- npm.flatOptions.parseable = true
+ const { team, result } = await mockTeam(t, {
+ config: { parseable: true },
+ })
await team.exec(['destroy', '@npmcli:newteam'])
- t.matchSnapshot(result, 'should output parseable result for destroy team')
+ t.matchSnapshot(result(), 'should output parseable result for destroy team')
})
t.test('--json', async t => {
- npm.flatOptions.json = true
+ const { team, result } = await mockTeam(t, {
+ config: { json: true },
+ })
await team.exec(['destroy', '@npmcli:newteam'])
t.same(
- JSON.parse(result),
+ JSON.parse(result()),
{
deleted: true,
team: 'npmcli:newteam',
@@ -152,14 +167,16 @@ t.test('team destroy <scope:team>', async t => {
})
t.test('--silent', async t => {
- npm.config.set('loglevel', 'silent')
+ const { team, result } = await mockTeam(t, {
+ config: { silent: true },
+ })
await team.exec(['destroy', '@npmcli:newteam'])
- t.same(result, '', 'should not output destroy if silent')
+ t.same(result(), '', 'should not output destroy if silent')
})
})
t.test('team ls <scope>', async t => {
- const libnpmteam = {
+ const teams = {
async lsTeams () {
return [
'npmcli:developers',
@@ -169,28 +186,43 @@ t.test('team ls <scope>', async t => {
},
}
- const Team = t.mock('../../../lib/commands/team.js', {
- ...mocks,
- libnpmteam,
- })
- const team = new Team(npm)
+ const noTeam = {
+ async lsTeams () {
+ return []
+ },
+ }
+
+ const singleTeam = {
+ async lsTeams () {
+ return ['npmcli:developers']
+ },
+ }
t.test('default output', async t => {
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: teams,
+ })
await team.exec(['ls', '@npmcli'])
- t.matchSnapshot(result, 'should list teams for a given scope')
+ t.matchSnapshot(result(), 'should list teams for a given scope')
})
t.test('--parseable', async t => {
- npm.flatOptions.parseable = true
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: teams,
+ config: { parseable: true },
+ })
await team.exec(['ls', '@npmcli'])
- t.matchSnapshot(result, 'should list teams for a parseable scope')
+ t.matchSnapshot(result(), 'should list teams for a parseable scope')
})
t.test('--json', async t => {
- npm.flatOptions.json = true
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: teams,
+ config: { json: true },
+ })
await team.exec(['ls', '@npmcli'])
t.same(
- JSON.parse(result),
+ JSON.parse(result()),
[
'npmcli:designers',
'npmcli:developers',
@@ -201,75 +233,78 @@ t.test('team ls <scope>', async t => {
})
t.test('--silent', async t => {
- npm.config.set('loglevel', 'silent')
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: teams,
+ config: { silent: true },
+ })
await team.exec(['ls', '@npmcli'])
- t.same(result, '', 'should not list teams if silent')
+ t.same(result(), '', 'should not list teams if silent')
})
t.test('no teams', async t => {
- const libnpmteam = {
- async lsTeams () {
- return []
- },
- }
-
- const Team = t.mock('../../../lib/commands/team.js', {
- ...mocks,
- libnpmteam,
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: noTeam,
})
- const team = new Team(npm)
await team.exec(['ls', '@npmcli'])
- t.matchSnapshot(result, 'should list no teams for a given scope')
+ t.matchSnapshot(result(), 'should list no teams for a given scope')
})
t.test('single team', async t => {
- const libnpmteam = {
- async lsTeams () {
- return ['npmcli:developers']
- },
- }
-
- const Team = t.mock('../../../lib/commands/team.js', {
- ...mocks,
- libnpmteam,
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: singleTeam,
})
- const team = new Team(npm)
await team.exec(['ls', '@npmcli'])
- t.matchSnapshot(result, 'should list single team for a given scope')
+ t.matchSnapshot(result(), 'should list single team for a given scope')
})
})
t.test('team ls <scope:team>', async t => {
- const libnpmteam = {
+ const users = {
async lsUsers () {
return ['nlf', 'ruyadorno', 'darcyclarke', 'isaacs']
},
}
- const Team = t.mock('../../../lib/commands/team.js', {
- ...mocks,
- libnpmteam,
- })
- const team = new Team(npm)
+
+ const singleUser = {
+ async lsUsers () {
+ return ['foo']
+ },
+ }
+
+ const noUsers = {
+ async lsUsers () {
+ return []
+ },
+ }
t.test('default output', async t => {
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: users,
+ })
await team.exec(['ls', '@npmcli:developers'])
- t.matchSnapshot(result, 'should list users for a given scope:team')
+ t.matchSnapshot(result(), 'should list users for a given scope:team')
})
t.test('--parseable', async t => {
- npm.flatOptions.parseable = true
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: users,
+ config: { parseable: true },
+ })
await team.exec(['ls', '@npmcli:developers'])
- t.matchSnapshot(result, 'should list users for a parseable scope:team')
+ t.matchSnapshot(result(), 'should list users for a parseable scope:team')
})
t.test('--json', async t => {
- npm.flatOptions.json = true
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: users,
+ config: { json: true },
+ })
await team.exec(['ls', '@npmcli:developers'])
t.same(
- JSON.parse(result),
+ JSON.parse(result()),
[
'darcyclarke',
'isaacs',
@@ -281,63 +316,55 @@ t.test('team ls <scope:team>', async t => {
})
t.test('--silent', async t => {
- npm.config.set('loglevel', 'silent')
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: users,
+ config: { silent: true },
+ })
await team.exec(['ls', '@npmcli:developers'])
- t.same(result, '', 'should not output users if silent')
+ t.same(result(), '', 'should not output users if silent')
})
t.test('no users', async t => {
- const libnpmteam = {
- async lsUsers () {
- return []
- },
- }
-
- const Team = t.mock('../../../lib/commands/team.js', {
- ...mocks,
- libnpmteam,
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: noUsers,
})
- const team = new Team(npm)
await team.exec(['ls', '@npmcli:developers'])
- t.matchSnapshot(result, 'should list no users for a given scope')
+ t.matchSnapshot(result(), 'should list no users for a given scope')
})
t.test('single user', async t => {
- const libnpmteam = {
- async lsUsers () {
- return ['foo']
- },
- }
-
- const Team = t.mock('../../../lib/commands/team.js', {
- ...mocks,
- libnpmteam,
+ const { team, result } = await mockTeam(t, {
+ libnpmteam: singleUser,
})
- const team = new Team(npm)
await team.exec(['ls', '@npmcli:developers'])
- t.matchSnapshot(result, 'should list single user for a given scope')
+ t.matchSnapshot(result(), 'should list single user for a given scope')
})
})
t.test('team rm <scope:team> <user>', async t => {
t.test('default output', async t => {
+ const { team, result } = await mockTeam(t)
await team.exec(['rm', '@npmcli:newteam', 'foo'])
- t.matchSnapshot(result, 'should output success result for remove user')
+ t.matchSnapshot(result(), 'should output success result for remove user')
})
t.test('--parseable', async t => {
- npm.flatOptions.parseable = true
+ const { team, result } = await mockTeam(t, {
+ config: { parseable: true },
+ })
await team.exec(['rm', '@npmcli:newteam', 'foo'])
- t.matchSnapshot(result, 'should output parseable result for remove user')
+ t.matchSnapshot(result(), 'should output parseable result for remove user')
})
t.test('--json', async t => {
- npm.flatOptions.json = true
+ const { team, result } = await mockTeam(t, {
+ config: { json: true },
+ })
await team.exec(['rm', '@npmcli:newteam', 'foo'])
t.same(
- JSON.parse(result),
+ JSON.parse(result()),
{
removed: true,
team: 'npmcli:newteam',
@@ -348,14 +375,17 @@ t.test('team rm <scope:team> <user>', async t => {
})
t.test('--silent', async t => {
- npm.config.set('loglevel', 'silent')
+ const { team, result } = await mockTeam(t, {
+ config: { silent: true },
+ })
await team.exec(['rm', '@npmcli:newteam', 'foo'])
- t.same(result, '', 'should not output rm result if silent')
+ t.same(result(), '', 'should not output rm result if silent')
})
})
-t.test('completion', t => {
- const { completion } = team
+t.test('completion', async t => {
+ const { npm } = await mockTeam(t)
+ const { completion } = await npm.cmd('team')
t.test('npm team autocomplete', async t => {
const res = await completion({