Refactor Import Functions to Resolve Circular Dependency Issues in Tests #1125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are the changes?
I've refactored the code by converting all anonymous functions executed during imports into named functions.
These named functions are now executed in the loading scene.
This change prevents crashes during tests caused by circular dependencies, which occur when anonymous functions are imported in an unpredictable order.
This refactoring is crucial because, for example, the biomes module crashes if the pokemon-evolution module isn't imported first, and the pokemon-evolution module crashes if the pokemon-forms module isn't imported first, and so on.
Why am I doing these changes?
This change is introduced to fix the circular dependency issues causing crashes during imports in tests. This improvement comes from the need to write better tests and ensure stable imports. The current state with anonymous functions executed at import leads to unpredictable behavior and crashes.
What did change?
Explicitly, the changes involve wrapping the previously anonymous functions into named functions. For example:
Before:
After:
This change was applied to the following files:
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()
With these changes, we can now write tests like:
Without this fix, errors occur when importing. With this fix, no more errors are present.
Screenshots/Videos
Without this fix:
With this fix
How to test the changes?
To test these changes:
Checklist