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

Commit 081bfd1

Browse files
committed
FUSETOOLS2-1152 fixing test
Signed-off-by: Brian Fitzpatrick <[email protected]>
1 parent 0abbd17 commit 081bfd1

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';
@@ -33,11 +33,29 @@ const TERMINAL_WAIT_RETRY = 2000;
3333

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

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

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

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

0 commit comments

Comments
 (0)