Skip to content

Commit e4e52c5

Browse files
authored
Merge pull request #1288 from oclif/d/W-21178947
fix: corrected stubbing errors in tests @W-21178947@
2 parents fe31ecb + 95b072f commit e4e52c5

3 files changed

Lines changed: 73 additions & 153 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"eslint-config-prettier": "^10",
4040
"husky": "^9.1.7",
4141
"lint-staged": "^15.5.2",
42-
"mocha": "^10.8.2",
42+
"mocha": "^11",
4343
"oclif": "^4.22.79",
4444
"prettier": "^3.8.1",
4545
"shx": "^0.4.0",

test/commands/plugins/index.test.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,75 @@ describe('plugins', () => {
88
sinon.restore()
99
})
1010

11-
it('shows no plugins installed', async () => {
11+
it('when no plugins installed, says so', async () => {
1212
const config = await Config.load(import.meta.url)
13-
sinon.stub(config, 'getPluginsList').returns([])
1413

15-
const {stdout} = await runCommand('plugins', config, {print: true})
14+
const {error, stdout} = await runCommand('plugins', config, {print: true})
15+
expect(error).to.be.undefined
1616
expect(stdout).to.equal('No plugins installed.\n')
1717
})
1818

19-
it('lists user plugins in stdout', async () => {
19+
it('lists installed user plugins in stdout', async () => {
2020
const config = await Config.load(import.meta.url)
21+
config.options
2122
const plugins = [
2223
...config.getPluginsList(),
23-
{name: 'user-plugin-1', type: 'user', version: '1.0.0'},
24-
{name: 'user-plugin-2', type: 'user', version: '1.0.0'},
24+
{commands: [], hooks: new Map(), name: 'user-plugin-1', topics: [], type: 'user', version: '1.0.0'},
25+
{commands: [], hooks: new Map(), name: 'user-plugin-2', topics: [], type: 'user', version: '1.0.0'},
2526
]
2627
// @ts-expect-error because we aren't stubbing the entire Plugin instance
2728
sinon.stub(config, 'getPluginsList').returns(plugins)
2829

29-
const {stdout} = await runCommand('plugins', config)
30+
const {error, stdout} = await runCommand('plugins', config)
31+
expect(error).to.be.undefined
3032
expect(stdout).to.equal('user-plugin-1 1.0.0\nuser-plugin-2 1.0.0\n')
3133
})
3234

33-
it('lists nested user plugins in stdout', async () => {
35+
it('lists installed nested user plugins in stdout', async () => {
3436
const config = await Config.load(import.meta.url)
3537
const plugins = [
3638
...config.getPluginsList(),
3739
{
3840
children: [
3941
{
42+
commands: [],
43+
hooks: new Map(),
4044
name: 'user-plugin-2',
45+
topics: [],
4146
type: 'user',
4247
version: '1.0.0',
4348
},
4449
],
50+
commands: [],
51+
hooks: new Map(),
4552
name: 'user-plugin-1',
53+
topics: [],
4654
type: 'user',
4755
version: '1.0.0',
4856
},
4957
]
5058
// @ts-expect-error because we aren't stubbing the entire Plugin instance
5159
sinon.stub(config, 'getPluginsList').returns(plugins)
5260

53-
const {stdout} = await runCommand('plugins', config)
61+
const {error, stdout} = await runCommand('plugins', config)
62+
expect(error).to.be.undefined
5463
expect(stdout).to.equal(`user-plugin-1 1.0.0
5564
└─ user-plugin-2 1.0.0
5665
`)
5766
})
5867

59-
it('lists dev plugins in stdout with --core', async () => {
68+
it('lists installed dev plugins in stdout with --core', async () => {
6069
const config = await Config.load(import.meta.url)
6170
const plugins = [
6271
...config.getPluginsList(),
63-
{name: 'dev-plugin-1', type: 'dev', version: '1.0.0'},
64-
{name: 'user-plugin-1', type: 'user', version: '1.0.0'},
72+
{commands: [], hooks: new Map(), name: 'dev-plugin-1', topics: [], type: 'dev', version: '1.0.0'},
73+
{commands: [], hooks: new Map(), name: 'user-plugin-1', topics: [], type: 'user', version: '1.0.0'},
6574
]
6675
// @ts-expect-error because we aren't stubbing the entire Plugin instance
6776
sinon.stub(config, 'getPluginsList').returns(plugins)
6877

69-
const {stdout} = await runCommand('plugins --core', config)
78+
const {error, stdout} = await runCommand('plugins --core', config)
79+
expect(error).to.be.undefined
7080
expect(stdout).to.equal('dev-plugin-1 1.0.0 (dev)\nuser-plugin-1 1.0.0\n')
7181
})
7282

@@ -82,8 +92,8 @@ describe('plugins', () => {
8292
})
8393
const plugins = [
8494
...config.getPluginsList(),
85-
{name: 'user-plugin-1', type: 'user', version: '1.0.0'},
86-
{name: 'jit-plugin-1', type: 'user', version: '1.0.0'},
95+
{commands: [], hooks: new Map(), name: 'user-plugin-1', topics: [], type: 'user', version: '1.0.0'},
96+
{commands: [], hooks: new Map(), name: 'jit-plugin-1', topics: [], type: 'user', version: '1.0.0'},
8797
]
8898
// @ts-expect-error because we aren't stubbing the entire Plugin instance
8999
sinon.stub(config, 'getPluginsList').returns(plugins)
@@ -102,9 +112,9 @@ jit-plugin-3 1.0.0
102112
const config = await Config.load(import.meta.url)
103113
const plugins = [
104114
...config.getPluginsList(),
105-
{name: 'user-plugin-1', type: 'user', version: '1.0.0'},
106-
{name: 'dev-plugin-1', type: 'dev', version: '1.0.0'},
107-
{name: 'core-plugin-1', type: 'core', version: '1.0.0'},
115+
{commands: [], hooks: new Map(), name: 'user-plugin-1', topics: [], type: 'user', version: '1.0.0'},
116+
{commands: [], hooks: new Map(), name: 'dev-plugin-1', topics: [], type: 'dev', version: '1.0.0'},
117+
{commands: [], hooks: new Map(), name: 'core-plugin-1', topics: [], type: 'core', version: '1.0.0'},
108118
]
109119
// @ts-expect-error because we aren't stubbing the entire Plugin instance
110120
sinon.stub(config, 'getPluginsList').returns(plugins)

0 commit comments

Comments
 (0)