1616 */
1717
1818import { expect } from 'chai' ;
19- import { window , commands , env , Uri , Terminal , Disposable } from 'vscode' ;
19+ import { window , commands , env , Uri , Terminal } from 'vscode' ;
2020import { START_DIDACT_COMMAND , sendTerminalText , gatherAllCommandsLinks , getContext } from '../../extensionFunctions' ;
2121import { didactManager } from '../../didactManager' ;
2222import { DidactUri } from '../../didactUri' ;
@@ -34,29 +34,11 @@ const TERMINAL_WAIT_RETRY = 2000;
3434
3535suite ( 'stub out a tutorial' , ( ) => {
3636
37- let disposables : Disposable [ ] = [ ] ;
38-
39- teardown ( ( ) => {
40- disposables . forEach ( d => d . dispose ( ) ) ;
41- disposables . length = 0 ;
42- } ) ;
43-
4437 test ( 'that we can send an echo command to the terminal and get the response' , async ( ) => {
4538 const name = 'echoTerminal' ;
4639 const text = `echo \"Hello World ${ name } \"` ;
4740 const result = `Hello World echoTerminal` ;
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- // }
41+ await validateTerminalResponse ( name , text , result ) ;
6042 } ) ;
6143
6244 test ( 'that we can get a response from each command in the demo tutorial' , async ( ) => {
@@ -116,53 +98,6 @@ suite('stub out a tutorial', () => {
11698 }
11799 }
118100
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-
166101 async function getActiveTerminalOutput ( ) : Promise < string > {
167102 const term = window . activeTerminal ;
168103 console . log ( `-current terminal = ${ term ?. name } ` ) ;
0 commit comments