Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit eac9a41

Browse files
committed
FUSETOOLS2-1152 fixing test
Signed-off-by: Brian Fitzpatrick <[email protected]>
1 parent c69777b commit eac9a41

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

src/test/suite/stubDemoTutorial.test.ts

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { expect } from 'chai';
19-
import { window, commands, env, Uri, Terminal } from 'vscode';
19+
import { window, commands, env, Uri, Terminal, Disposable } from 'vscode';
2020
import { START_DIDACT_COMMAND, sendTerminalText, gatherAllCommandsLinks, getContext } from '../../extensionFunctions';
2121
import { didactManager } from '../../didactManager';
2222
import { DidactUri } from '../../didactUri';
@@ -34,11 +34,29 @@ const TERMINAL_WAIT_RETRY = 2000;
3434

3535
suite('stub out a tutorial', () => {
3636

37+
let disposables: Disposable[] = [];
38+
39+
teardown(() => {
40+
disposables.forEach(d => d.dispose());
41+
disposables.length = 0;
42+
});
43+
3744
test('that we can send an echo command to the terminal and get the response', async () => {
3845
const name = 'echoTerminal';
3946
const text = `echo \"Hello World ${name}\"`;
4047
const result = `Hello World echoTerminal`;
41-
await validateTerminalResponse(name, text, result);
48+
const winResult = [
49+
`Hello`,
50+
`World`,
51+
`echoTerminal`
52+
];
53+
await validateTerminalResponseWin(name, text, result);
54+
55+
// if (process.platform === 'win32') {
56+
// await validateTerminalResponseWin(name, text, winResult);
57+
// } else {
58+
// await validateTerminalResponse(name, text, result);
59+
// }
4260
});
4361

4462
test('that we can get a response from each command in the demo tutorial', async () => {
@@ -98,6 +116,53 @@ suite('stub out a tutorial', () => {
98116
}
99117
}
100118

119+
async function validateTerminalResponseWin(terminalName : string, terminalText : string, terminalResponse : string) {
120+
let terminalData:string[] = [];
121+
console.log(`validateTerminalResponse terminal ${terminalName} executing text ${terminalText}`);
122+
const term = window.createTerminal(terminalName);
123+
expect(term).to.not.be.null;
124+
if (term) {
125+
console.log(`-current terminal = ${term?.name}`);
126+
await sendTerminalText(terminalName, terminalText);
127+
await waitUntil(async () => {
128+
await focusOnNamedTerminal(terminalName);
129+
return terminalName === window.activeTerminal?.name;
130+
}, 1000);
131+
try {
132+
const predicate = async () => {
133+
const result: string = await getActiveTerminalOutput();
134+
await commands.executeCommand('workbench.action.terminal.clear');
135+
if (result.trim().length > 0) terminalData.push(result.trim());
136+
return true;
137+
};
138+
var numberOfTimes = 5;
139+
const delay = 1000;
140+
for (let i = 0; i < numberOfTimes; i++) {
141+
await predicate();
142+
await new Promise((res) => { setTimeout(res, delay); });
143+
}
144+
console.log(`-terminal output = ${terminalData}`);
145+
146+
const foundIt = searchStringInArray(terminalResponse, terminalData);
147+
if (foundIt > -1) {
148+
return;
149+
} else {
150+
fail(`Searching for ${terminalResponse} but not found in current content of active terminal ${window.activeTerminal?.name} : ${terminalData}`);
151+
};
152+
} catch (error){
153+
fail(error);
154+
}
155+
findAndDisposeTerminal(terminalName);
156+
}
157+
}
158+
159+
function searchStringInArray (strToFind : string, strArray : string[]) : number {
160+
for (var j=0; j<strArray.length; j++) {
161+
if (strArray[j].match(strToFind)) return j;
162+
}
163+
return -1;
164+
}
165+
101166
async function getActiveTerminalOutput() : Promise<string> {
102167
const term = window.activeTerminal;
103168
console.log(`-current terminal = ${term?.name}`);

0 commit comments

Comments
 (0)