rdw-archive / WebClient

[Proof of Concept] Browser-based client capable of rendering networked multiplayer games using modern web technologies
1 stars 0 forks source link

Integrate mocha (and electron-mocha) testing framework #4

Closed rdw-software closed 3 years ago

rdw-software commented 3 years ago

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:

Roadmap:

rdw-software commented 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.

rdw-software commented 3 years ago

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:

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.

rdw-software commented 3 years ago

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: