@@ -60,6 +60,19 @@ async function navigateToTab(browser: CompassBrowser, tabName: string) {
6060 await tabSelectedSelectorElement . waitForDisplayed ( ) ;
6161}
6262
63+ async function waitForJSON ( browser : CompassBrowser , element : Element < 'async' > ) {
64+ // Sometimes the line numbers end up in the text for some reason. Probably
65+ // because we get the text before the component is properly initialised.
66+ await browser . waitUntil ( async ( ) => {
67+ const text = await element . getText ( ) ;
68+ const isJSON = text . replace ( / \s + / g, ' ' ) . startsWith ( '{' ) ;
69+ if ( ! isJSON ) {
70+ console . log ( { text } ) ;
71+ }
72+ return isJSON ;
73+ } ) ;
74+ }
75+
6376describe ( 'Collection documents tab' , function ( ) {
6477 let compass : Compass ;
6578 let browser : CompassBrowser ;
@@ -338,6 +351,9 @@ FindIterable<Document> result = collection.find(filter);`);
338351
339352 const document = await browser . $ ( Selectors . DocumentJSONEntry ) ;
340353 await document . waitForDisplayed ( ) ;
354+
355+ await waitForJSON ( browser , document ) ;
356+
341357 const json = await document . getText ( ) ;
342358 expect ( json . replace ( / \s + / g, ' ' ) ) . to . match (
343359 / ^ \{ " _ i d " : \{ " \$ o i d " : " [ a - f 0 - 9 ] { 24 } " \} , " i " : 3 2 , " j " : 0 \} $ /
@@ -365,6 +381,9 @@ FindIterable<Document> result = collection.find(filter);`);
365381
366382 const modifiedDocument = await browser . $ ( Selectors . DocumentJSONEntry ) ;
367383 await modifiedDocument . waitForDisplayed ( ) ;
384+
385+ await waitForJSON ( browser , modifiedDocument ) ;
386+
368387 expect ( ( await modifiedDocument . getText ( ) ) . replace ( / \s + / g, ' ' ) ) . to . match (
369388 / ^ \{ " _ i d " : \{ " \$ o i d " : " [ a - f 0 - 9 ] { 24 } " \} , " i " : 3 2 , " j " : 1 2 3 4 \} $ /
370389 ) ;
0 commit comments