pokerogue
pokerogue copied to clipboard
Tests - Fix imports to use them in tests
I've put all the anonymous function executed at the import into a named function, and all these named function are executed in the loading-scene. it allow us to import stuff in tests without crash since we have a lot of circular dependency, that import these anonymous function without any particular order. (and it's important since biomes crash if pokemon-evolution is not imported before and pokemon-evolution crash if pokemon-forms is not imported before and so on.)
The diff seems big but i did not change anything in the legacy code.
For example, in this code:
this code is executed directly when game-stats-ui-handler is imported. here is the "adjusted" code:
This is the same code, but within a named function.
it's the case for:
- src/ui/game-stats-ui-handler.ts -> initStatsKeys()
- src/data/pokemon-evolutions.ts -> initPokemonPrevolutions()
- src/data/biomes.ts -> initBiomes()
- src/data/egg-moves.ts -> initEggMoves()
- src/data/pokemon-forms.ts -> initPokemonForms()
At the end, we now can do this kind of test:
it's not over yet though, it's the very first step we need to do in order to write better tests. indeed, it does not allow to instantiate any Class with a Scene in parameters. We'll need to detach the logic code from the engine code, and it can'b be done in a single run, unless you are VERY motivated.
EDIT:
Without this fix:
With this fix