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