Concept: Run smoke tests / unit tests in custom built Espruino IDE docker images with GitHub actions #6910
Replies: 1 comment
-
Posted at 2024-04-09 by @gfwilliams There is already something available - it doesn't use the IDE but does use the emulator and run it within Node.js on the command-line - it doesn't need Docker. It's at https://github.com/espruino/BangleApps/blob/master/bin/runapptests.js It'll scan through all apps for test files of a certain format, load the app up and try and run through a test script - which eventually could involve comparing screenshots at different points (it's just a matter of including the code from https://github.com/espruino/BangleApps/blob/master/bin/thumbnailer.js). The thing is though, there was some talk about this and I made the rough framework but nobody seems particularly bothered about actually creating any tests. For something to catch the One thing that might be a big improvement for reliability is actually to catch any Errors created on the watch itself (or even within BangleApps) and bring them into some kind of database - but I've been resisting that as I wonder if there might be privacy implications if somehow personal data could included in the errors. Posted at 2024-04-09 by Ishidres Thanks for the info. If this already exists, cool, no need to build any new images then. And yes, I get the point that automatically catching and uploading errors would definitely be a problem regarding privacy. Posted at 2024-04-10 by @halemmerich I had done this a while ago: https://github.com/espruino/BangleApps/blob/master/apps/android/test.js Every step in that would probably map nicely to a test object in the json. I think I could refactor that. Maybe some of the asserts would be useful as a teststep in the apptests? I could try to integrate those. How does the emulator handle "hardware" like GPS? If it does not I probably need to find a new way to track the state of the "internal" GPS instead of checking the PIN mode like it does currently. Posted at 2024-04-10 by @gfwilliams
That would be great!
Yes, absolutely - I was expecting that as tests got added we might want to have some different steps in there.
Right now it doesn't, but I guess a good option would be to have a test step like As I understand it right now things like GPS power are always off in the emulator, but maybe that could be changed or we just upload some boilerplate before the test that replaces Posted at 2024-04-20 by @halemmerich I've had a play around porting the first of the test cases to json: https://gist.github.com/halemmerich/3d0f1d41d8eebe76eedc8553530e5dd5 I think this should be all the asserts/features I need. I have a rough implementation for those but it is not yet working correctly. Why did you decide on the json based format for test cases? Wouldn't javascript files be better for editing/linting/syntax highlighting? Posted at 2024-04-22 by @gfwilliams Thanks! Well, really it was a few things:
But yes, potentially we could just have JS files and work around that stuff above. There's nothing in place at the moment, so if you wanted to do a PR I'm all for it. Posted at 2024-04-22 by @halemmerich
I think this speaks most to me personally :D Posted at 2024-04-22 by @gfwilliams
Yes - that sounds like a great plan for the future Posted at 2024-05-03 by @halemmerich I have done a draft at espruino/BangleApps#3399. Output currently looks like the attached image. Attachments: Posted at 2024-05-05 by @halemmerich The current state seems to work more or less. It is however a bit cumbersome finding/debugging problems. Posted at 2024-05-07 by @gfwilliams That's great, thanks!
Possibly - I think you can get called back whenever you get data from the emulator, and then you could pass that on (same with injecting characters in). It is possible to serve up an iframe with a websocket server, and then you can link it to the IDE and have it magically work that way. A lot of work though! I guess this would be a benefit of your JS-only approach - you could just copy/paste the code in the IDE and see what happened. Posted at 2024-05-07 by @halemmerich I have found a way to implement a command for opening an interactive console. It "works" with the current state of the pull request alone with three major gotchas:
1 and 2 work with these two changes: Do you think the changes in core and IDE would have unwanted side effects elsewhere? There seems to be a race condition somewhere that causes the result of the call ( Posted at 2024-05-09 by @gfwilliams Yes, I think those changes would be ok. I think the idea with the emulator was that actually the debugger will basically never work as-is. I'm not sure we even build it in (we shouldn't anyway). The issue is the emulator is single-threaded - it just executes and returns each time. But because the debugger has to stop execution in the middle the To make it work you'd have to swap to using the emulator in a web worker/similar which seems like a much larger task. Right now we just feed the characters in one at a time and ask the emulator to go around it's idle loop once per character, and then hopefully during the call where
I'm not sure I understand here... Do you think you could give an example of what's on the console when it happens? Posted at 2024-05-09 by @halemmerich
Ah, that explains why everything halts on entering As for the example:
The first time there is an Posted at 2024-05-09 by @gfwilliams Ahh, ok. That's expected - you enter the command, and it's executed, so it prints 158, but then Just send the command, prefixed with char code 16 (so I'll see about removing the debugger from emulator builds... Posted at 2024-05-09 by @halemmerich The Posted at 2024-05-09 by @halemmerich Found it... the wrap command that runs before in the demo test did not have a Posted at 2024-05-09 by @gfwilliams
Exactly, yes - that's great - thanks! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2024-04-04 by Ishidres
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?
Beta Was this translation helpful? Give feedback.
All reactions