diff --git a/tests/call_js_from_v_test.v b/tests/call_js_from_v_test.v index afa54be..10c44a3 100644 --- a/tests/call_js_from_v_test.v +++ b/tests/call_js_from_v_test.v @@ -19,15 +19,20 @@ fn test_js_fn_call() { await webui.call("close_window") }' // Show window, wait for it to be recognized as shown. - w.show(utils.gen_html(@FN, script), - await: true - ) or { assert false, err.str() } + w.show(utils.gen_html(@FN, script), await: true) or { assert false, err.str() } // We call `w.close()` from the last V function that is called from JS. // Ensure that it closes, otherwise the test can run infinitely. Timeout after 1min. - if !utils.timeout(30, fn [w] () bool { - return !w.is_shown() - }) { - assert false, 'Timeout while waiting for JS to call V.' - } + spawn fn [w] () { + if !utils.timeout(30, fn [w] () bool { + return !w.is_shown() + }) { + assert false, 'Timeout while waiting for JS to call V.' + exit(1) + } + }() +} + +fn test_run_wait() { + ui.wait() // Call wait once at the end of all tests. } diff --git a/tests/call_v_from_js_test.v b/tests/call_v_from_js_test.v index e8cf7dd..9aa9e90 100644 --- a/tests/call_v_from_js_test.v +++ b/tests/call_v_from_js_test.v @@ -20,16 +20,16 @@ fn test_v_fn_call() { }, 500)' // Show window, wait for it to be recognized as shown. - w.show(utils.gen_html(@FN, script), - await: true - ) or { assert false, err.str() } + w.show(utils.gen_html(@FN, script), await: true) or { assert false, err.str() } // Wait for v_fn to be called. - if !utils.timeout(30, fn [mut app] () bool { - return app.fn_was_called - }) { - assert false, 'Timeout while waiting for JS to call V.' - } + spawn fn [mut app] () { + if !utils.timeout(30, fn [mut app] () bool { + return app.fn_was_called + }) { + assert false, 'Timeout while waiting for JS to call V.' + } + }() } struct Person { @@ -80,11 +80,13 @@ fn test_get_js_arg() { // We call `w.close()` from the last V function that is called from JS. // Ensure that it closes, otherwise the test can run infinitely. Timeout after 1min. - if !utils.timeout(60, fn [w] () bool { - return !w.is_shown() - }) { - assert false, 'Timeout while waiting JS calling V.' - } + spawn fn [w] () { + if !utils.timeout(60, fn [w] () bool { + return !w.is_shown() + }) { + assert false, 'Timeout while waiting JS calling V.' + } + }() } // V function bound to JS callback in next tests @@ -117,11 +119,13 @@ fn test_get_js_arg_at_idx() { await: true ) or { assert false, err.str() } - if !utils.timeout(60, fn [w] () bool { - return !w.is_shown() - }) { - assert false, 'Timeout while waiting JS calling V.' - } + spawn fn [w] () { + if !utils.timeout(60, fn [w] () bool { + return !w.is_shown() + }) { + assert false, 'Timeout while waiting JS calling V.' + } + }() } fn test_return_value_to_js() { @@ -160,9 +164,16 @@ fn test_return_value_to_js() { await: true ) or { assert false, err.str() } - if !utils.timeout(60, fn [w] () bool { - return !w.is_shown() - }) { - assert false, 'Timeout while waiting JS calling V.' - } + spawn fn [w] () { + if !utils.timeout(60, fn [w] () bool { + return !w.is_shown() + }) { + assert false, 'Timeout while waiting JS calling V.' + exit(1) + } + }() +} + +fn test_run_wait() { + ui.wait() // Call wait once at the end of the test. } diff --git a/tests/thread_gc_test.v b/tests/thread_gc_test.v index c3db9c2..8f2858c 100644 --- a/tests/thread_gc_test.v +++ b/tests/thread_gc_test.v @@ -49,9 +49,16 @@ fn test_thread_gc() { ) or { assert false, err.str() } log.info('> w.is_shown: ${w.is_shown()}') - if !utils.timeout(30, fn [mut app] () bool { - return app.fn_was_called - }) { - assert false, 'Timeout while waiting for the v binded callback to be called' - } + spawn fn [mut app] () { + if !utils.timeout(30, fn [mut app] () bool { + return app.fn_was_called + }) { + assert false, 'Timeout while waiting for the V callback to be called' + exit(1) + } + }() +} + +fn test_run_wait() { + ui.wait() // Call wait once at the end of all tests. } diff --git a/tests/window_close_test.v b/tests/window_close_test.v index 98ad48f..def5570 100644 --- a/tests/window_close_test.v +++ b/tests/window_close_test.v @@ -7,12 +7,7 @@ fn test_window_close() { // Wait for the window to show ui.set_timeout(30) - w.show(' - -${@FN} -') or { - assert false, err.str() - } + w.show(utils.gen_html(@FN, '')) or { assert false, err.str() } for i in 0 .. 30 { if w.is_shown() { break @@ -25,9 +20,15 @@ fn test_window_close() { w.close() // Wait for the window to close - if !utils.timeout(10, fn [w] () bool { - return !w.is_shown() - }) { - assert false, 'Failed closing window.' - } + spawn fn [w] () { + if !utils.timeout(10, fn [w] () bool { + return !w.is_shown() + }) { + assert false, 'Failed closing window.' + } + }() +} + +fn test_run_wait() { + ui.wait() // Call wait once at the end of all tests. }