Skip to content

Commit 9473408

Browse files
committed
test: use oclif/test v4
1 parent 99777e6 commit 9473408

File tree

3 files changed

+262
-534
lines changed

3 files changed

+262
-534
lines changed

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"@oclif/core": "^3.26.6"
99
},
1010
"devDependencies": {
11-
"@commitlint/config-conventional": "^18",
11+
"@commitlint/config-conventional": "^19",
1212
"@oclif/plugin-help": "^6",
1313
"@oclif/prettier-config": "^0.2.1",
14+
"@oclif/test": "^4.0.2",
1415
"@types/chai": "^4.3.11",
1516
"@types/mocha": "^10.0.6",
1617
"@types/node": "^18",
17-
"@types/sinon": "^17.0.3",
1818
"chai": "^4.4.1",
19-
"commitlint": "^18",
19+
"commitlint": "^19",
2020
"eslint": "^8.57.0",
2121
"eslint-config-oclif": "^5.2.0",
2222
"eslint-config-oclif-typescript": "^3.1.7",
@@ -28,7 +28,6 @@
2828
"oclif": "^4.10.11",
2929
"prettier": "^3.2.5",
3030
"shx": "^0.3.4",
31-
"sinon": "^17.0.2",
3231
"ts-node": "^10.9.2",
3332
"typescript": "^5.4.5"
3433
},

test/commands/which.test.ts

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,40 @@
1-
import {Config, ux} from '@oclif/core'
1+
import {runCommand} from '@oclif/test'
22
import {expect} from 'chai'
33
import {dirname, join} from 'node:path'
44
import {fileURLToPath} from 'node:url'
5-
import {SinonSandbox, createSandbox} from 'sinon'
65

76
const root = join(dirname(fileURLToPath(import.meta.url)), '..', 'fixtures/test-plugin')
87

98
describe('which', () => {
10-
let sandbox: SinonSandbox
11-
let config: Config
12-
13-
beforeEach(async () => {
14-
sandbox = createSandbox()
15-
sandbox.stub(ux.write, 'stdout')
16-
config = await Config.load({root})
17-
})
18-
19-
afterEach(async () => {
20-
sandbox.restore()
21-
})
22-
23-
it('should return plugin name for colon separate command', async () => {
24-
const {plugin} = await config.runCommand<{plugin: string}>('which', ['foo:bar'])
25-
expect(plugin).to.equal('test-plugin')
9+
it('should return plugin name for colon separated command', async () => {
10+
const {result} = await runCommand<{plugin: string}>('which foo:bar', {root})
11+
expect(result?.plugin).to.equal('test-plugin')
2612
})
2713

28-
it('should return plugin name for quoted space separate command', async () => {
29-
const {plugin} = await config.runCommand<{plugin: string}>('which', ['foo bar'])
30-
expect(plugin).to.equal('test-plugin')
14+
it('should return plugin name for quoted space separated command', async () => {
15+
const {result} = await runCommand<{plugin: string}>('which "foo bar"', {root})
16+
expect(result?.plugin).to.equal('test-plugin')
3117
})
3218

33-
it('should return plugin name for unquoted space separate command', async () => {
34-
const {plugin} = await config.runCommand<{plugin: string}>('which', ['foo', 'bar'])
35-
expect(plugin).to.equal('test-plugin')
19+
it('should return plugin name for unquoted space separated command', async () => {
20+
const {result} = await runCommand<{plugin: string}>('which foo bar', {root})
21+
expect(result?.plugin).to.equal('test-plugin')
3622
})
3723

3824
it('should return plugin name and aliasOf for alias', async () => {
39-
const {aliasOf, plugin} = await config.runCommand<{aliasOf: string; plugin: string}>('which', ['foo:alias'])
40-
expect(plugin).to.equal('test-plugin')
41-
expect(aliasOf).to.equal('foo bar')
25+
const {result} = await runCommand<{aliasOf: string; plugin: string}>('which foo:alias', {root})
26+
expect(result?.plugin).to.equal('test-plugin')
27+
expect(result?.aliasOf).to.equal('foo bar')
4228
})
4329

4430
it('should not return aliasOf if not an alias', async () => {
45-
const {aliasOf, plugin} = await config.runCommand<{aliasOf: string; plugin: string}>('which', ['foo:bar'])
46-
expect(plugin).to.equal('test-plugin')
47-
expect(aliasOf).to.be.undefined
31+
const {result} = await runCommand<{aliasOf: string; plugin: string}>('which foo:bar', {root})
32+
expect(result?.plugin).to.equal('test-plugin')
33+
expect(result?.aliasOf).to.be.undefined
4834
})
4935

5036
it('should throw error if no command is provided', async () => {
51-
try {
52-
await config.runCommand('which')
53-
throw new Error('expected error')
54-
} catch (error) {
55-
const {message} = error as Error
56-
expect(message).to.contain('"which" expects a command name')
57-
}
37+
const {error} = await runCommand('which', {root})
38+
expect(error?.message).to.contain('"which" expects a command name')
5839
})
5940
})

0 commit comments

Comments
 (0)