|
4 | 4 | 'use strict'; |
5 | 5 |
|
6 | 6 | import * as TypeMoq from 'typemoq'; |
| 7 | +import { expect } from 'chai'; |
7 | 8 | import { Terminal } from 'vscode'; |
8 | 9 | import { BaseTerminalActivator } from '../../../../client/common/terminal/activator/base'; |
9 | 10 | import { ITerminalActivator, ITerminalHelper } from '../../../../client/common/terminal/types'; |
10 | 11 | import { noop } from '../../../../client/common/utils/misc'; |
11 | 12 |
|
12 | | -// tslint:disable-next-line:max-func-body-length |
13 | | -suite('Terminalx Base Activator', () => { |
| 13 | +// tslint:disable:max-func-body-length no-any |
| 14 | +suite('Terminal Base Activator', () => { |
14 | 15 | let activator: ITerminalActivator; |
15 | 16 | let helper: TypeMoq.IMock<ITerminalHelper>; |
16 | 17 |
|
17 | 18 | setup(() => { |
18 | 19 | helper = TypeMoq.Mock.ofType<ITerminalHelper>(); |
19 | 20 | activator = new class extends BaseTerminalActivator { |
20 | 21 | public waitForCommandToProcess() { noop(); return Promise.resolve(); } |
21 | | - }(helper.object); |
| 22 | + }(helper.object) as any as ITerminalActivator; |
22 | 23 | }); |
23 | 24 | [ |
24 | 25 | { commandCount: 1, preserveFocus: false }, |
@@ -70,5 +71,30 @@ suite('Terminalx Base Activator', () => { |
70 | 71 |
|
71 | 72 | terminal.verifyAll(); |
72 | 73 | }); |
| 74 | + test(`Terminal is activated only once ${titleSuffix} (even when not waiting)`, async () => { |
| 75 | + helper.setup(h => h.getTerminalShellPath()).returns(() => ''); |
| 76 | + helper.setup(h => h.getEnvironmentActivationCommands(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(activationCommands)); |
| 77 | + const terminal = TypeMoq.Mock.ofType<Terminal>(); |
| 78 | + |
| 79 | + terminal |
| 80 | + .setup(t => t.show(TypeMoq.It.isValue(item.preserveFocus))) |
| 81 | + .returns(() => undefined) |
| 82 | + .verifiable(TypeMoq.Times.exactly(activationCommands.length)); |
| 83 | + activationCommands.forEach(cmd => { |
| 84 | + terminal |
| 85 | + .setup(t => t.sendText(TypeMoq.It.isValue(cmd))) |
| 86 | + .returns(() => undefined) |
| 87 | + .verifiable(TypeMoq.Times.exactly(1)); |
| 88 | + }); |
| 89 | + |
| 90 | + const activated = await Promise.all([ |
| 91 | + activator.activateEnvironmentInTerminal(terminal.object, undefined, item.preserveFocus), |
| 92 | + activator.activateEnvironmentInTerminal(terminal.object, undefined, item.preserveFocus), |
| 93 | + activator.activateEnvironmentInTerminal(terminal.object, undefined, item.preserveFocus) |
| 94 | + ]); |
| 95 | + |
| 96 | + terminal.verifyAll(); |
| 97 | + expect(activated).to.deep.equal([true, true, true], 'Invalid values'); |
| 98 | + }); |
73 | 99 | }); |
74 | 100 | }); |
0 commit comments