From 9814dd424c853932a04a995228ad9a05d9e48453 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Mon, 13 May 2024 19:00:01 +0200 Subject: [PATCH] runapptests - Rename sleep to advanceTime and add documentation --- apps/android/test.json | 2 +- bin/runapptests.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/android/test.json b/apps/android/test.json index 8e9b6ced2..1a1436ccd 100644 --- a/apps/android/test.json +++ b/apps/android/test.json @@ -92,7 +92,7 @@ {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 0 } ], "text": "internal GPS switched off"}, {"t":"resetCall", "id": "gpspower"}, - {"t":"sleep", "ms":"12000", "text": "wait for fallback"}, + {"t":"advanceTime", "ms":"12000", "text": "wait for fallback"}, {"t":"assertCall", "id": "gpspower", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ], "text": "internal GPS switched on caused by missing GB event"} ] }] diff --git a/bin/runapptests.js b/bin/runapptests.js index 92d480c18..6ac290fc2 100755 --- a/bin/runapptests.js +++ b/bin/runapptests.js @@ -57,10 +57,17 @@ const DEMOTEST = { {"t":"assertArray", "js": "[1,2,3]", "is":"notEmpty", "text": "Evaluates the content of 'js' on the device and asserts if the result is an array with more than 0 entries"}, {"t":"cmd", "js": "global.testfunction(1)", "text": "Call function for the following asserts"}, {"t":"assertCall", "id": "testfunc", "argAsserts": [ { "t": "assert", "arg": "0", "is": "equal", "to": 1 } ] , "text": "Asserts if a wrapped function has been called with the expected arguments"}, - {"t":"assertCall", "id": "testfunc", "count": 1 , "text": "Asserts if a wrapped function has been called the expected number of times"}, {"t":"resetCall", "id": "testfunc", "text": "Reset the recorded calls"}, {"t":"assertCall", "id": "testfunc", "count": 0 , "text": "Asserts if a wrapped function has been called the expected number of times"} ] + }, { + "description": "Emulator time can advanced by a given amount. This currently works for timeouts,intervals and Date.now() calls", + "steps": [ + {"t":"cmd", "js":"setTimeout(()=>{global.waited = true},60000)", "text": "Set a timeout for 60 seconds"}, + {"t":"assert", "js":"global.waited", "is": "falsy", "text": "Timeout has not yet fired"}, + {"t":"advanceTime", "ms":60000}, + {"t":"assert", "js":"global.waited", "is": "true", "text": "Timeout has fired"} + ] }] } @@ -316,9 +323,9 @@ function runStep(step, subtest, test, state){ } }); break; - case "sleep" : + case "advanceTime" : p = p.then(()=>{ - console.log("> SLEEP FOR", step.ms + "ms"); + console.log("> ADVANCE TIME BY", step.ms + "ms"); if (!subtest.wrappedDateNow){ emu.tx(`Date.now = (o)=>{return ()=>{ return o() + global.APPTESTS.timeOffset;