|
1 |
| -import {Config, ux} from '@oclif/core' |
| 1 | +import {runCommand} from '@oclif/test' |
2 | 2 | import {expect} from 'chai'
|
3 | 3 | import {dirname, join} from 'node:path'
|
4 | 4 | import {fileURLToPath} from 'node:url'
|
5 |
| -import {SinonSandbox, createSandbox} from 'sinon' |
6 | 5 |
|
7 | 6 | const root = join(dirname(fileURLToPath(import.meta.url)), '..', 'fixtures/test-plugin')
|
8 | 7 |
|
9 | 8 | 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') |
26 | 12 | })
|
27 | 13 |
|
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') |
31 | 17 | })
|
32 | 18 |
|
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') |
36 | 22 | })
|
37 | 23 |
|
38 | 24 | 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') |
42 | 28 | })
|
43 | 29 |
|
44 | 30 | 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 |
48 | 34 | })
|
49 | 35 |
|
50 | 36 | 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') |
58 | 39 | })
|
59 | 40 | })
|
0 commit comments