@@ -84,7 +84,7 @@ async function main() {
8484
8585 if ( args [ '--version' ] === true || args [ '--short-version' ] === true ) {
8686 printVersion ( args [ '--short-version' ] ) ;
87- process . exit ( 0 ) ;
87+ return ;
8888 }
8989
9090 if ( ! quiet ) {
@@ -93,12 +93,12 @@ async function main() {
9393
9494 if ( args [ '--help' ] ) {
9595 cliHelp ( ) ;
96- process . exit ( 0 ) ;
96+ return ;
9797 }
9898
9999 if ( args . _ [ 0 ] === 'init' ) {
100100 await initProjectWizard ( args . _ [ 1 ] ?? '.' , { diagramFile } ) ;
101- process . exit ( 0 ) ;
101+ return ;
102102 }
103103
104104 const token = process . env . WOKWI_CLI_TOKEN ;
@@ -250,36 +250,6 @@ async function main() {
250250
251251 const serialLogStream = serialLogFile ? createWriteStream ( serialLogFile ) : null ;
252252
253- if ( expectText ) {
254- expectEngine . expectTexts . push ( expectText ) ;
255- expectEngine . on ( 'match' , ( text ) => {
256- if ( text !== expectText ) {
257- return ;
258- }
259-
260- if ( ! quiet ) {
261- console . log ( chalkTemplate `\n\nExpected text found: {green "${ expectText } "}` ) ;
262- console . log ( 'TEST PASSED.' ) ;
263- }
264- client . close ( ) ;
265- process . exit ( 0 ) ;
266- } ) ;
267- }
268-
269- if ( failText ) {
270- expectEngine . failTexts . push ( failText ) ;
271- expectEngine . on ( 'fail' , ( text ) => {
272- if ( text !== failText ) {
273- return ;
274- }
275-
276- console . error ( chalkTemplate `\n\n{red Error:} Unexpected text found: {yellow "${ text } "}` ) ;
277- console . error ( 'TEST FAILED.' ) ;
278- client . close ( ) ;
279- process . exit ( 1 ) ;
280- } ) ;
281- }
282-
283253 const transport = new WebSocketTransport ( token , DEFAULT_SERVER , version , sha ) ;
284254 const client = new APIClient ( transport ) ;
285255 client . onConnected = ( hello ) => {
@@ -309,8 +279,29 @@ async function main() {
309279 }
310280
311281 const promises = [ ] ;
312- let screenshotPromise = Promise . resolve ( ) ;
313282
283+ if ( expectText ) {
284+ promises . push (
285+ expectEngine . waitForMatch ( expectText ) . then ( ( ) => {
286+ if ( ! quiet ) {
287+ console . log ( chalkTemplate `\n\nExpected text found: {green "${ expectText } "}` ) ;
288+ console . log ( 'TEST PASSED.' ) ;
289+ }
290+ } ) ,
291+ ) ;
292+ }
293+ if ( failText ) {
294+ void expectEngine . waitForMatch ( failText ) . then ( ( ) => {
295+ console . error (
296+ chalkTemplate `\n\n{red Error:} Unexpected text found: {yellow "${ failText } "}` ,
297+ ) ;
298+ console . error ( 'TEST FAILED.' ) ;
299+ client . close ( ) ;
300+ process . exit ( 1 ) ;
301+ } ) ;
302+ }
303+
304+ let screenshotPromise = Promise . resolve ( ) ;
314305 if ( screenshotPart != null && screenshotTime != null ) {
315306 if ( timeout && screenshotTime > timeout ) {
316307 console . error (
0 commit comments