|
6 | 6 | import { expect } from 'chai'; |
7 | 7 | import * as TypeMoq from 'typemoq'; |
8 | 8 | import { LanguageServerOutputChannel } from '../../../client/activation/languageServer/outputChannel'; |
9 | | -import { IApplicationShell } from '../../../client/common/application/types'; |
| 9 | +import { IApplicationShell, ICommandManager } from '../../../client/common/application/types'; |
10 | 10 | import { IOutputChannel } from '../../../client/common/types'; |
| 11 | +import { sleep } from '../../../client/common/utils/async'; |
11 | 12 | import { OutputChannelNames } from '../../../client/common/utils/localize'; |
12 | 13 |
|
| 14 | +// tslint:disable-next-line:max-func-body-length |
13 | 15 | suite('Language Server Output Channel', () => { |
14 | 16 | let appShell: TypeMoq.IMock<IApplicationShell>; |
15 | 17 | let languageServerOutputChannel: LanguageServerOutputChannel; |
16 | | - let output: IOutputChannel; |
| 18 | + let commandManager: TypeMoq.IMock<ICommandManager>; |
| 19 | + let output: TypeMoq.IMock<IOutputChannel>; |
17 | 20 | setup(() => { |
18 | 21 | appShell = TypeMoq.Mock.ofType<IApplicationShell>(); |
19 | | - output = TypeMoq.Mock.ofType<IOutputChannel>().object; |
20 | | - languageServerOutputChannel = new LanguageServerOutputChannel(appShell.object); |
| 22 | + output = TypeMoq.Mock.ofType<IOutputChannel>(); |
| 23 | + commandManager = TypeMoq.Mock.ofType<ICommandManager>(); |
| 24 | + languageServerOutputChannel = new LanguageServerOutputChannel(appShell.object, commandManager.object); |
21 | 25 | }); |
22 | 26 |
|
23 | 27 | test('Create output channel if one does not exist before and return it', async () => { |
24 | 28 | appShell |
25 | 29 | .setup(a => a.createOutputChannel(OutputChannelNames.languageServer())) |
26 | | - .returns(() => output) |
| 30 | + .returns(() => output.object) |
27 | 31 | .verifiable(TypeMoq.Times.once()); |
28 | 32 | const channel = languageServerOutputChannel.channel; |
29 | 33 | appShell.verifyAll(); |
30 | 34 | expect(channel).to.not.equal(undefined, 'Channel should not be undefined'); |
31 | 35 | }); |
32 | 36 |
|
33 | 37 | test('Do not create output channel if one already exists', async () => { |
34 | | - languageServerOutputChannel.output = output; |
| 38 | + languageServerOutputChannel.output = output.object; |
35 | 39 | appShell |
36 | 40 | .setup(a => a.createOutputChannel(TypeMoq.It.isAny())) |
37 | | - .returns(() => output) |
| 41 | + .returns(() => output.object) |
38 | 42 | .verifiable(TypeMoq.Times.never()); |
39 | 43 | const channel = languageServerOutputChannel.channel; |
40 | 44 | appShell.verifyAll(); |
41 | 45 | expect(channel).to.not.equal(undefined, 'Channel should not be undefined'); |
42 | 46 | }); |
| 47 | + test('Register Command to display output panel', async () => { |
| 48 | + appShell |
| 49 | + .setup(a => a.createOutputChannel(TypeMoq.It.isAny())) |
| 50 | + .returns(() => output.object) |
| 51 | + .verifiable(TypeMoq.Times.once()); |
| 52 | + commandManager |
| 53 | + .setup(c => c.executeCommand(TypeMoq.It.isValue('setContext'), |
| 54 | + TypeMoq.It.isValue('python.hasLanguageServerOutputChannel'), |
| 55 | + TypeMoq.It.isValue(true))) |
| 56 | + .returns(() => Promise.resolve()) |
| 57 | + .verifiable(TypeMoq.Times.once()); |
| 58 | + commandManager |
| 59 | + .setup(c => c.registerCommand(TypeMoq.It.isValue('python.viewLanguageServerOutput'), |
| 60 | + TypeMoq.It.isAny())) |
| 61 | + .verifiable(TypeMoq.Times.once()); |
| 62 | + |
| 63 | + // Doesn't matter how many times we access channel propery. |
| 64 | + let channel = languageServerOutputChannel.channel; |
| 65 | + channel = languageServerOutputChannel.channel; |
| 66 | + channel = languageServerOutputChannel.channel; |
| 67 | + |
| 68 | + await sleep(1); |
| 69 | + |
| 70 | + appShell.verifyAll(); |
| 71 | + commandManager.verifyAll(); |
| 72 | + expect(channel).to.not.equal(undefined, 'Channel should not be undefined'); |
| 73 | + }); |
| 74 | + test('Display panel when invoking command python.viewLanguageServerOutput', async () => { |
| 75 | + let cmdCallback: Function | undefined; |
| 76 | + appShell |
| 77 | + .setup(a => a.createOutputChannel(TypeMoq.It.isAny())) |
| 78 | + .returns(() => output.object) |
| 79 | + .verifiable(TypeMoq.Times.once()); |
| 80 | + commandManager |
| 81 | + .setup(c => c.executeCommand(TypeMoq.It.isValue('setContext'), |
| 82 | + TypeMoq.It.isValue('python.hasLanguageServerOutputChannel'), |
| 83 | + TypeMoq.It.isValue(true))) |
| 84 | + .returns(() => Promise.resolve()) |
| 85 | + .verifiable(TypeMoq.Times.once()); |
| 86 | + commandManager |
| 87 | + .setup(c => c.registerCommand(TypeMoq.It.isValue('python.viewLanguageServerOutput'), |
| 88 | + TypeMoq.It.isAny())) |
| 89 | + .callback((_: string, callback: Function) => cmdCallback = callback) |
| 90 | + .verifiable(TypeMoq.Times.once()); |
| 91 | + output |
| 92 | + .setup(o => o.show(true)) |
| 93 | + .verifiable(TypeMoq.Times.never()); |
| 94 | + // Doesn't matter how many times we access channel propery. |
| 95 | + let channel = languageServerOutputChannel.channel; |
| 96 | + channel = languageServerOutputChannel.channel; |
| 97 | + channel = languageServerOutputChannel.channel; |
| 98 | + |
| 99 | + await sleep(1); |
| 100 | + |
| 101 | + appShell.verifyAll(); |
| 102 | + commandManager.verifyAll(); |
| 103 | + output.verifyAll(); |
| 104 | + expect(channel).to.not.equal(undefined, 'Channel should not be undefined'); |
| 105 | + expect(cmdCallback).to.not.equal(undefined, 'Command handler should not be undefined'); |
| 106 | + |
| 107 | + // Confirm panel is displayed when command handler is invoked. |
| 108 | + output.reset(); |
| 109 | + output |
| 110 | + .setup(o => o.show(true)) |
| 111 | + .verifiable(TypeMoq.Times.once()); |
| 112 | + |
| 113 | + // Invoke callback. |
| 114 | + cmdCallback!(); |
| 115 | + |
| 116 | + output.verifyAll(); |
| 117 | + }); |
43 | 118 | }); |
0 commit comments