@@ -8,6 +8,7 @@ import { parse } from 'node-html-parser';
88import * as React from 'react' ;
99import { Disposable } from 'vscode' ;
1010
11+ import { InteractiveWindowMessages } from '../../client/datascience/interactive-common/interactiveWindowTypes' ;
1112import { IJupyterVariable } from '../../client/datascience/types' ;
1213import { InteractivePanel } from '../../datascience-ui/history-react/interactivePanel' ;
1314import { VariableExplorer } from '../../datascience-ui/interactive-common/variableExplorer' ;
@@ -16,7 +17,7 @@ import { DataScienceIocContainer } from './dataScienceIocContainer';
1617import { addCode } from './interactiveWindowTestHelpers' ;
1718import { addCell , createNewEditor } from './nativeEditorTestHelpers' ;
1819import { waitForUpdate } from './reactHelpers' ;
19- import { runDoubleTest } from './testHelpers' ;
20+ import { runDoubleTest , waitForMessage } from './testHelpers' ;
2021
2122// tslint:disable:max-func-body-length trailing-comma no-any no-multiline-string
2223suite ( 'DataScience Interactive Window variable explorer tests' , ( ) => {
@@ -60,10 +61,17 @@ suite('DataScience Interactive Window variable explorer tests', () => {
6061 // asyncDump();
6162 //});
6263
63- async function addCodeImpartial ( wrapper : ReactWrapper < any , Readonly < { } > , React . Component > , code : string , expectedRenderCount : number = 4 , expectError : boolean = false ) : Promise < ReactWrapper < any , Readonly < { } > , React . Component > > {
64+ async function waitForVariablesUpdated ( ) : Promise < void > {
65+ return waitForMessage ( ioc , InteractiveWindowMessages . VariablesComplete ) ;
66+ }
67+
68+ async function addCodeImpartial ( wrapper : ReactWrapper < any , Readonly < { } > , React . Component > , code : string , waitForVariables : boolean = true , expectedRenderCount : number = 4 , expectError : boolean = false ) : Promise < ReactWrapper < any , Readonly < { } > , React . Component > > {
69+ const variablesUpdated = waitForVariables ? waitForVariablesUpdated ( ) : Promise . resolve ( ) ;
6470 const nodes = wrapper . find ( 'InteractivePanel' ) ;
6571 if ( nodes . length > 0 ) {
66- return addCode ( ioc , wrapper , code , expectedRenderCount , expectError ) ;
72+ const result = await addCode ( ioc , wrapper , code , expectedRenderCount , expectError ) ;
73+ await variablesUpdated ;
74+ return result ;
6775 } else {
6876 // For the native editor case, we need to create an editor before hand.
6977 if ( ! createdNotebook ) {
@@ -72,6 +80,7 @@ suite('DataScience Interactive Window variable explorer tests', () => {
7280 expectedRenderCount += 1 ;
7381 }
7482 await addCell ( wrapper , code , true , expectedRenderCount ) ;
83+ await variablesUpdated ;
7584 return wrapper ;
7685 }
7786 }
@@ -85,8 +94,7 @@ value = 'hello world'`;
8594 openVariableExplorer ( wrapper ) ;
8695
8796 await addCodeImpartial ( wrapper , 'a=1\na' ) ;
88- await addCodeImpartial ( wrapper , basicCode , 4 ) ;
89- await waitForUpdate ( wrapper , VariableExplorer , 3 ) ;
97+ await addCodeImpartial ( wrapper , basicCode , true , 4 ) ;
9098
9199 // We should show a string and show an int, the modules should be hidden
92100 let targetVariables : IJupyterVariable [ ] = [
@@ -100,8 +108,7 @@ value = 'hello world'`;
100108 ioc . getSettings ( ) . datascience . variableExplorerExclude = `${ ioc . getSettings ( ) . datascience . variableExplorerExclude } ;str` ;
101109
102110 // Add another string and check our vars, strings should be hidden
103- await addCodeImpartial ( wrapper , basicCode2 , 4 ) ;
104- await waitForUpdate ( wrapper , VariableExplorer , 2 ) ;
111+ await addCodeImpartial ( wrapper , basicCode2 , true , 4 ) ;
105112
106113 targetVariables = [
107114 { name : 'a' , value : '1' , supportsDataExplorer : false , type : 'int' , size : 54 , shape : '' , count : 0 , truncated : false }
@@ -116,7 +123,6 @@ value = 'hello world'`;
116123 openVariableExplorer ( wrapper ) ;
117124
118125 await addCodeImpartial ( wrapper , 'a=1\na' ) ;
119- await waitForUpdate ( wrapper , VariableExplorer , 2 ) ;
120126
121127 // Check that we have just the 'a' variable
122128 let targetVariables : IJupyterVariable [ ] = [
@@ -125,8 +131,7 @@ value = 'hello world'`;
125131 verifyVariables ( wrapper , targetVariables ) ;
126132
127133 // Add another variable and check it
128- await addCodeImpartial ( wrapper , basicCode , 4 ) ;
129- await waitForUpdate ( wrapper , VariableExplorer , 3 ) ;
134+ await addCodeImpartial ( wrapper , basicCode , true , 4 ) ;
130135
131136 targetVariables = [
132137 { name : 'a' , value : '1' , supportsDataExplorer : false , type : 'int' , size : 54 , shape : '' , count : 0 , truncated : false } ,
@@ -136,8 +141,7 @@ value = 'hello world'`;
136141 verifyVariables ( wrapper , targetVariables ) ;
137142
138143 // Add a second variable and check it
139- await addCodeImpartial ( wrapper , basicCode2 , 4 ) ;
140- await waitForUpdate ( wrapper , VariableExplorer , 4 ) ;
144+ await addCodeImpartial ( wrapper , basicCode2 , true , 4 ) ;
141145
142146 targetVariables = [
143147 { name : 'a' , value : '1' , supportsDataExplorer : false , type : 'int' , size : 54 , shape : '' , count : 0 , truncated : false } ,
@@ -155,7 +159,7 @@ value = 'hello world'`;
155159 openVariableExplorer ( wrapper ) ;
156160
157161 await addCodeImpartial ( wrapper , 'a=1\na' ) ;
158- await addCodeImpartial ( wrapper , basicCode , 4 ) ;
162+ await addCodeImpartial ( wrapper , basicCode , false , 4 ) ;
159163
160164 // Here we are only going to wait for two renders instead of the needed three
161165 // a should have the value updated, but value should still be loading
@@ -187,11 +191,7 @@ myDict = {'a': 1}`;
187191 openVariableExplorer ( wrapper ) ;
188192
189193 await addCodeImpartial ( wrapper , 'a=1\na' ) ;
190- await addCodeImpartial ( wrapper , basicCode , 4 ) ;
191-
192- // Verify that we actually update the variable explorer
193- // Count here is our main render + a render for each variable row as they come in
194- await waitForUpdate ( wrapper , VariableExplorer , 5 ) ;
194+ await addCodeImpartial ( wrapper , basicCode , true , 4 ) ;
195195
196196 const targetVariables : IJupyterVariable [ ] = [
197197 { name : 'a' , value : '1' , supportsDataExplorer : false , type : 'int' , size : 54 , shape : '' , count : 0 , truncated : false } ,
@@ -219,11 +219,7 @@ myTuple = 1,2,3,4,5,6,7,8,9
219219 openVariableExplorer ( wrapper ) ;
220220
221221 await addCodeImpartial ( wrapper , 'a=1\na' ) ;
222- await addCodeImpartial ( wrapper , basicCode , 4 ) ;
223-
224- // Verify that we actually update the variable explorer
225- // Count here is our main render + a render for each variable row as they come in
226- await waitForUpdate ( wrapper , VariableExplorer , 9 ) ;
222+ await addCodeImpartial ( wrapper , basicCode , true , 4 ) ;
227223
228224 const targetVariables : IJupyterVariable [ ] = [
229225 { name : 'a' , value : '1' , supportsDataExplorer : false , type : 'int' , size : 54 , shape : '' , count : 0 , truncated : false } ,
@@ -255,9 +251,7 @@ strc = 'c'`;
255251 openVariableExplorer ( wrapper ) ;
256252
257253 await addCodeImpartial ( wrapper , 'a=1\na' ) ;
258- await addCodeImpartial ( wrapper , basicCode , 4 ) ;
259-
260- await waitForUpdate ( wrapper , VariableExplorer , 7 ) ;
254+ await addCodeImpartial ( wrapper , basicCode , true , 4 ) ;
261255
262256 let targetVariables : IJupyterVariable [ ] = [
263257 { name : 'a' , value : '1' , supportsDataExplorer : false , type : 'int' , size : 54 , shape : '' , count : 0 , truncated : false } ,
@@ -318,6 +312,10 @@ function sortVariableExplorer(wrapper: ReactWrapper<any, Readonly<{}>, React.Com
318312
319313// Verify a set of rows versus a set of expected variables
320314function verifyVariables ( wrapper : ReactWrapper < any , Readonly < { } > , React . Component > , targetVariables : IJupyterVariable [ ] ) {
315+ // Force an update so we render whatever the current state is
316+ wrapper . update ( ) ;
317+
318+ // Then search for results.
321319 const foundRows = wrapper . find ( 'div.react-grid-Row' ) ;
322320
323321 expect ( foundRows . length ) . to . be . equal ( targetVariables . length , 'Different number of variable explorer rows and target variables' ) ;
0 commit comments