Hi everyone! I was thinking about the following possible workflow in order to automatically run unit tests or smoke tests in an emulator:
build a docker image that contains the Espruino IDE (https://espruino.com/ide) or a smaller version of it
when a commit in a PR gets pushed, this triggers a GitHub action
optionally the smoke tests could also be run just once a day, e.g. at midnight, to save GitHub Actions minutes
this GitHub action uses the Espruino IDE docker image and automatically loads the newly added/changed code in the IDE
some test cases that check basic functionality of the app run and confirm the changes don't break other code
When it comes to test cases, obviously some mocking needs to be done, however I think this is perfectly doable. For example https://www.espruino.com/ReferenceBANGLEJS2#l_E_getTemperature always returns NaN in the emulator, but the easiest way to mock it for the test suite would be to call E.getTemperature = function() { return 20; }; at the start of the test suite.
For example, here's some pseudo code I came up with for activityreminder:
// Suite setup
// Mock some functions
E.getTemperature = function() { return 27; }; // assume the user is always wearing the smart watch
settings.maxInnactivityMin = 0; // immediately trigger an inactivity warning by setting max inactivity to 0 min
// Test cases
// wait a few seconds and assert E.showPrompt() got called (which should happen)
// if not, fail the test or raise a warning
// (optionally) take a screenshot and include it as an artifact
Why would this be useful?
Around 2 weeks ago there was an issue where (if I understood correctly) some firmware changes caused a new date format which broke activityreminder because it still expected/used the old date format. We could detect sudden breaking changes like this one using test cases. For example, the test case above would have failed after the new date format changes, because it couldn't have read the new date format.
Obviously this is a huge suggestion and is probably low priority, but I'm just sharing my ideas and I'm open for feedback! What are your thoughts about this?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi everyone! I was thinking about the following possible workflow in order to automatically run unit tests or smoke tests in an emulator:
When it comes to test cases, obviously some mocking needs to be done, however I think this is perfectly doable. For example https://www.espruino.com/ReferenceBANGLEJS2#l_E_getTemperature always returns
NaN
in the emulator, but the easiest way to mock it for the test suite would be to callE.getTemperature = function() { return 20; };
at the start of the test suite.For example, here's some pseudo code I came up with for
activityreminder
:Why would this be useful?
Around 2 weeks ago there was an issue where (if I understood correctly) some firmware changes caused a new date format which broke
activityreminder
because it still expected/used the old date format. We could detect sudden breaking changes like this one using test cases. For example, the test case above would have failed after the new date format changes, because it couldn't have read the new date format.Obviously this is a huge suggestion and is probably low priority, but I'm just sharing my ideas and I'm open for feedback! What are your thoughts about this?