diff --git a/package-lock.json b/package-lock.json index 28749bcd..6441983a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3419,9 +3419,9 @@ "dev": true }, "vscode-test": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/vscode-test/-/vscode-test-1.5.2.tgz", - "integrity": "sha512-x9PVfKxF6EInH9iSFGQi0V8H5zIW1fC7RAer6yNQR6sy3WyOwlWkuT3I+wf75xW/cO53hxMi1aj/EvqQfDFOAg==", + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/vscode-test/-/vscode-test-1.6.1.tgz", + "integrity": "sha512-086q88T2ca1k95mUzffvbzb7esqQNvJgiwY4h29ukPhFo8u+vXOOmelUoU5EQUHs3Of8+JuQ3oGdbVCqaxuTXA==", "dev": true, "requires": { "http-proxy-agent": "^4.0.1", diff --git a/package.json b/package.json index f93c9eec..7146576f 100644 --- a/package.json +++ b/package.json @@ -298,7 +298,7 @@ "mocha-jenkins-reporter": "^0.4.4", "sinon": "11.1.1", "typescript": "^4.3.5", - "vscode-test": "^1.5.2", + "vscode-test": "^1.6.1", "y18n": ">=4.0.1" }, "dependencies": { diff --git a/src/test/suite/stubDemoTutorial.test.ts b/src/test/suite/stubDemoTutorial.test.ts index bc9c676a..6b08531d 100644 --- a/src/test/suite/stubDemoTutorial.test.ts +++ b/src/test/suite/stubDemoTutorial.test.ts @@ -16,7 +16,7 @@ */ import { expect } from 'chai'; -import { window, commands, env, Uri, Terminal } from 'vscode'; +import { window, commands, env, Uri, Terminal, Disposable } from 'vscode'; import { START_DIDACT_COMMAND, sendTerminalText, gatherAllCommandsLinks, getContext } from '../../extensionFunctions'; import { didactManager } from '../../didactManager'; import { DidactUri } from '../../didactUri'; @@ -33,11 +33,29 @@ const TERMINAL_WAIT_RETRY = 2000; suite('stub out a tutorial', () => { + let disposables: Disposable[] = []; + + teardown(() => { + disposables.forEach(d => d.dispose()); + disposables.length = 0; + }); + test('that we can send an echo command to the terminal and get the response', async () => { const name = 'echoTerminal'; const text = `echo \"Hello World ${name}\"`; const result = `Hello World echoTerminal`; - await validateTerminalResponse(name, text, result); + const winResult = [ + `Hello`, + `World`, + `echoTerminal` + ]; + await validateTerminalResponseWin(name, text, result); + + // if (process.platform === 'win32') { + // await validateTerminalResponseWin(name, text, winResult); + // } else { + // await validateTerminalResponse(name, text, result); + // } }); test('that we can get a response from each command in the demo tutorial', async () => { @@ -97,6 +115,53 @@ suite('stub out a tutorial', () => { } } + async function validateTerminalResponseWin(terminalName : string, terminalText : string, terminalResponse : string) { + let terminalData:string[] = []; + console.log(`validateTerminalResponse terminal ${terminalName} executing text ${terminalText}`); + const term = window.createTerminal(terminalName); + expect(term).to.not.be.null; + if (term) { + console.log(`-current terminal = ${term?.name}`); + await sendTerminalText(terminalName, terminalText); + await waitUntil(async () => { + await focusOnNamedTerminal(terminalName); + return terminalName === window.activeTerminal?.name; + }, 1000); + try { + const predicate = async () => { + const result: string = await getActiveTerminalOutput(); + await commands.executeCommand('workbench.action.terminal.clear'); + if (result.trim().length > 0) terminalData.push(result.trim()); + return true; + }; + var numberOfTimes = 5; + const delay = 1000; + for (let i = 0; i < numberOfTimes; i++) { + await predicate(); + await new Promise((res) => { setTimeout(res, delay); }); + } + console.log(`-terminal output = ${terminalData}`); + + const foundIt = searchStringInArray(terminalResponse, terminalData); + if (foundIt > -1) { + return; + } else { + fail(`Searching for ${terminalResponse} but not found in current content of active terminal ${window.activeTerminal?.name} : ${terminalData}`); + }; + } catch (error){ + fail(error); + } + findAndDisposeTerminal(terminalName); + } + } + + function searchStringInArray (strToFind : string, strArray : string[]) : number { + for (var j=0; j { const term = window.activeTerminal; console.log(`-current terminal = ${term?.name}`);