Closed rdw-software closed 3 years ago
After looking into this, here's my preliminary conclusion:
The unfortunate part is that the APIs are exposed as globals (by design, similar to the WOW client's Lua environment it was modeled after). That doesn't work with offline testing, so in-browser tests are the best approach.
This isn't an issue since the client doesn't do anything that would affect the tests on its own, assuming no addons are installed and no APIs called/UI events fired. I found https://github.com/jprichardson/electron-mocha to make up for this and was able to run tests in the render thread (no UI), which could be automated in a pipeline as follows:
electron-mocha --url index.html --renderer <path to test file or directory>
This is looking like the best bet so far, and could possibly be combined with "regular" mocha for displaying test reports in-app (manually started), if the re-run issue is resolved. That is, in the CI pipeline or CLI we use electron-mocha
, and for unit tests or in-browser visualization simply mocha
. Electron is needed for integration and system tests anyway, and it's better to use the same framework/syntax for both instead of having to write a custom testing framework.
Awkwardly, I managed to make the tests run repeatedly. It requires a ton of hacks and I'm not a fan of this approach. Even then, a few problems remain while running mocha in the browser directly:
All things considered, I see only two viable options:
mocha
and mocha-electron
, but create a separate "test runner" version of the app (or a way to load tests with some flag only, that could be triggered via CI or CLI)Too bad they didn't account for this use case, but it might be easiest to just run tests visually in a separate config if needed.
Honestly, this framework just gives me one headache after the other when it comes to running tests in the browser. I think I'll just remove that feature and settle for CLI, as that at least works reliably. If we ever need more, it's probably time to write our own framework unless there exists one that doesn't behave erratically... :weary:
There's so many, I don't even know which to pick. An overview: https://www.lambdatest.com/blog/top-javascript-automation-testing-framework/
Goals:
It should be possible to run both engine and addon tests from inside the app and display a report windowRoadmap:
mocha
andelectron-mocha
npm dependenciesAdd a shortcut (cmd) to run the tests in the browser (HTML report)C_Testing
API to collect functions related to running and setting up the testsAdd a way to load all the mocha stuff on demand, viaC_Testing.enterTestMode()
or similarAddC_Testing.showReport()
to show the latest rest reportIntroduce aTEST_RUNNER_STARTED
event to allow addons to hook into the runTrigger this event when theelectron-mocha
runner starts or the client is started in test mode