From 7101f4f0fab373935b61ec944496afbdb8cd45d5 Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Fri, 16 Aug 2024 13:58:50 -0700 Subject: [PATCH] Stop on `EndEvolutionPhase` to prevent game state leak in tests --- src/test/evolution.test.ts | 26 +++++++++++++------------- src/test/utils/phaseInterceptor.ts | 3 ++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/test/evolution.test.ts b/src/test/evolution.test.ts index 319ce7f9d7a..3faad179617 100644 --- a/src/test/evolution.test.ts +++ b/src/test/evolution.test.ts @@ -114,7 +114,7 @@ describe("Evolution", () => { expect(golem.hp).toBe(1); game.doAttack(getMovePosition(game.scene, 0, Moves.SURF)); - await game.phaseInterceptor.to("EvolutionPhase"); + await game.phaseInterceptor.to("EndEvolutionPhase"); expect(totodile.hp).toBe(totodile.getMaxHp()); expect(totodile.hp).toBeGreaterThan(hpBefore); @@ -125,17 +125,17 @@ describe("Evolution", () => { .enemySpecies(Species.GOLEM) .enemyMoveset(SPLASH_ONLY) .startingWave(21) - .startingLevel(16) - .enemyLevel(50); + .startingLevel(13) + .enemyLevel(30); - await game.startBattle([Species.TOTODILE]); + await game.startBattle([Species.CYNDAQUIL]); - const totodile = game.scene.getPlayerPokemon()!; - totodile.hp = totodile.getMaxHp() / 2; - const hpBefore = totodile.hp; - const maxHpBefore = totodile.getMaxHp(); + const cyndaquil = game.scene.getPlayerPokemon()!; + cyndaquil.hp = Math.floor(cyndaquil.getMaxHp() / 2); + const hpBefore = cyndaquil.hp; + const maxHpBefore = cyndaquil.getMaxHp(); - expect(totodile.hp).toBe(totodile.getMaxHp() / 2); + expect(cyndaquil.hp).toBe(Math.floor(cyndaquil.getMaxHp() / 2)); const golem = game.scene.getEnemyPokemon()!; golem.hp = 1; @@ -143,10 +143,10 @@ describe("Evolution", () => { expect(golem.hp).toBe(1); game.doAttack(getMovePosition(game.scene, 0, Moves.SURF)); - await game.phaseInterceptor.to("EvolutionPhase"); + await game.phaseInterceptor.to("EndEvolutionPhase"); - expect(totodile.getMaxHp()).toBeGreaterThan(maxHpBefore); - expect(totodile.hp).toBeGreaterThan(hpBefore); - expect(totodile.hp).toBeLessThan(totodile.getMaxHp()); + expect(cyndaquil.getMaxHp()).toBeGreaterThan(maxHpBefore); + expect(cyndaquil.hp).toBeGreaterThan(hpBefore); + expect(cyndaquil.hp).toBeLessThan(cyndaquil.getMaxHp()); }, TIMEOUT); }); diff --git a/src/test/utils/phaseInterceptor.ts b/src/test/utils/phaseInterceptor.ts index d404afe04d4..f09b63fc846 100644 --- a/src/test/utils/phaseInterceptor.ts +++ b/src/test/utils/phaseInterceptor.ts @@ -38,7 +38,7 @@ import UI, { Mode } from "#app/ui/ui"; import { Phase } from "#app/phase"; import ErrorInterceptor from "#app/test/utils/errorInterceptor"; import { QuietFormChangePhase } from "#app/form-change-phase"; -import { EvolutionPhase } from "#app/evolution-phase.js"; +import { EndEvolutionPhase, EvolutionPhase } from "#app/evolution-phase.js"; export default class PhaseInterceptor { public scene; @@ -94,6 +94,7 @@ export default class PhaseInterceptor { [SwitchPhase, this.startPhase], [SwitchSummonPhase, this.startPhase], [EvolutionPhase, this.startPhase], + [EndEvolutionPhase, this.startPhase], ]; private endBySetMode = [