Skip to content

Commit c1e6911

Browse files
authored
Merge pull request #741 from adobe/bugfix/ACNA-3480
fix: fix the aio discover command and fix the unit tests
2 parents 74389d0 + 9695de4 commit c1e6911

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/commands/discover.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class DiscoCommand extends Command {
9898
// ours only, this could become a flag, searching for oclif-plugin reveals some more
9999
const adobeOnly = json.objects
100100
.map(e => e.package)
101-
.filter(elem => elem.scope === 'adobe')
101+
.filter(elem => elem.name && elem.name.startsWith('@adobe/aio-cli-plugin'))
102102

103103
sortValues(adobeOnly, {
104104
descending: flags['sort-order'] !== 'asc',
@@ -117,6 +117,7 @@ class DiscoCommand extends Command {
117117
}
118118

119119
DiscoCommand.description = `Discover plugins to install
120+
Lists only plugins with prefix '@adobe/aio-cli-plugin'
120121
To install a plugin, run 'aio plugins install NAME'
121122
`
122123

test/commands/discover.test.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ beforeEach(() => {
2323
fetch.resetMocks()
2424
command = new TheCommand([])
2525
command.config = {
26-
commands: [{ pluginName: 'baz' }],
26+
commands: [{ pluginName: '@adobe/aio-cli-plugin-baz' }],
2727
runCommand: jest.fn()
2828
}
2929
})
@@ -39,8 +39,8 @@ describe('sorting', () => {
3939

4040
const expectedResult = {
4141
objects: [
42-
{ package: { scope: 'adobe', name: 'foo', description: 'some foo', version: '1.0.0', date: genesis } },
43-
{ package: { scope: 'adobe', name: 'bar', description: 'some bar', version: '1.0.1', date: later } }
42+
{ package: { name: '@adobe/aio-cli-plugin-a', description: 'plugin a', version: '1.0.0', date: genesis } },
43+
{ package: { name: '@adobe/aio-cli-plugin-b', description: 'plugin b', version: '1.0.1', date: later } }
4444
]
4545
}
4646
beforeEach(() => {
@@ -59,32 +59,32 @@ describe('sorting', () => {
5959
command.argv = ['--sort-field', 'name', '--sort-order', 'asc']
6060
await command.run()
6161
const splitOutput = stdout.output.split('\n')
62-
expect(splitOutput[2]).toMatch('bar') // bar is first
63-
expect(splitOutput[3]).toMatch('foo') // foo is second
62+
expect(splitOutput[2]).toMatch('@adobe/aio-cli-plugin-a') // @adobe/aio-cli-plugin-a is first
63+
expect(splitOutput[3]).toMatch('@adobe/aio-cli-plugin-b') // @adobe/aio-cli-plugin-b is second
6464
})
6565

6666
test('sort-field=name, descending', async () => {
6767
command.argv = ['--sort-field', 'name', '--sort-order', 'desc']
6868
await command.run()
6969
const splitOutput = stdout.output.split('\n')
70-
expect(splitOutput[2]).toMatch('foo') // foo is first
71-
expect(splitOutput[3]).toMatch('bar') // bar is second
70+
expect(splitOutput[2]).toMatch('@adobe/aio-cli-plugin-b') // @adobe/aio-cli-plugin-b is first
71+
expect(splitOutput[3]).toMatch('@adobe/aio-cli-plugin-a') // @adobe/aio-cli-plugin-a is second
7272
})
7373

7474
test('sort-field=date, ascending', async () => {
7575
command.argv = ['--sort-field', 'date', '--sort-order', 'asc']
7676
await command.run()
7777
const splitOutput = stdout.output.split('\n')
78-
expect(splitOutput[2]).toMatch('foo') // foo is first
79-
expect(splitOutput[3]).toMatch('bar') // bar is second
78+
expect(splitOutput[2]).toMatch('@adobe/aio-cli-plugin-a') // @adobe/aio-cli-plugin-a is first
79+
expect(splitOutput[3]).toMatch('@adobe/aio-cli-plugin-b') // @adobe/aio-cli-plugin-b is second
8080
})
8181

8282
test('sort-field=date, descending', async () => {
8383
command.argv = ['--sort-field', 'date', '--sort-order', 'desc']
8484
await command.run()
8585
const splitOutput = stdout.output.split('\n')
86-
expect(splitOutput[2]).toMatch('bar') // bar is first
87-
expect(splitOutput[3]).toMatch('foo') // foo is second
86+
expect(splitOutput[2]).toMatch('@adobe/aio-cli-plugin-b') // @adobe/aio-cli-plugin-b is first
87+
expect(splitOutput[3]).toMatch('@adobe/aio-cli-plugin-a') // @adobe/aio-cli-plugin-a is second
8888
})
8989
})
9090

@@ -95,30 +95,30 @@ test('interactive install', async () => {
9595

9696
const expectedResult = {
9797
objects: [
98-
{ package: { scope: 'adobe', name: 'foo', description: 'some foo', version: '1.0.0', date: now } },
99-
{ package: { scope: 'adobe', name: 'bar', description: 'some bar', version: '1.0.1', date: tomorrow } },
100-
{ package: { scope: 'adobe', name: 'baz', description: 'some baz', version: '1.0.2', date: dayAfter } }
98+
{ package: { name: '@adobe/aio-cli-plugin-foo', description: 'some foo', version: '1.0.0', date: now } },
99+
{ package: { name: '@adobe/aio-cli-plugin-bar', description: 'some bar', version: '1.0.1', date: tomorrow } },
100+
{ package: { name: '@adobe/aio-cli-plugin-baz', description: 'some baz', version: '1.0.2', date: dayAfter } }
101101
]
102102
}
103103
fetch.mockResponseOnce(JSON.stringify(expectedResult))
104104

105105
command.argv = ['-i']
106106
inquirer.prompt = jest.fn().mockResolvedValue({
107-
plugins: ['bar', 'foo']
107+
plugins: ['@adobe/aio-cli-plugin-bar', '@adobe/aio-cli-plugin-foo']
108108
})
109109

110110
const result = await command.run()
111-
expect(result).toEqual(['bar', 'foo'])
111+
expect(result).toEqual(['@adobe/aio-cli-plugin-bar', '@adobe/aio-cli-plugin-foo'])
112112
const arg = inquirer.prompt.mock.calls[0][0] // first arg of first call
113-
expect(arg[0].choices.map(elem => elem.value)).toEqual(['bar', 'foo']) // baz was an existing plugin, filtered out
113+
expect(arg[0].choices.map(elem => elem.value)).toEqual(['@adobe/aio-cli-plugin-bar', '@adobe/aio-cli-plugin-foo']) // @adobe/aio-cli-plugin-baz was an existing plugin, filtered out
114114
})
115115

116116
test('interactive install - no choices', async () => {
117117
const now = new Date()
118118

119119
const expectedResult = {
120120
objects: [
121-
{ package: { scope: 'adobe', name: 'baz', description: 'some baz', version: '1.0.2', date: now } }
121+
{ package: { name: '@adobe/aio-cli-plugin-baz', description: 'some baz', version: '1.0.2', date: now } }
122122
]
123123
}
124124
fetch.mockResponseOnce(JSON.stringify(expectedResult))

0 commit comments

Comments
 (0)