[Qol] Load i18n en locales during tests (#4553)

* add: i18n backend support

the backend is being supported by using msw which will import the correct file from the local locales folder

* fix: tests to no longer rely on static i18n keys

* Update src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Update src/test/mystery-encounter/encounters/teleporting-hijinks-encounter.test.ts

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Update src/test/ui/type-hints.test.ts

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Update src/test/mystery-encounter/encounters/a-trainers-test-encounter.test.ts

Co-authored-by: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com>

* Fix typos

Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com>

* Fix linting

* update locales submodule

update reference to `56eeb809eb5a2de40cfc5bc6128a78bef14deea9` (from `3ccef8472dd7cc7c362538489954cb8fdad27e5f`)

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
Co-authored-by: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com>
Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com>
This commit is contained in:
flx-sta 2024-10-09 13:01:49 -07:00 committed by GitHub
parent ffe941d235
commit f180b6070e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 166 additions and 126 deletions

14
global.d.ts vendored Normal file
View File

@ -0,0 +1,14 @@
import type { SetupServerApi } from "msw/node";
export {};
declare global {
/**
* Only used in testing.
* Can technically be undefined/null but for ease of use we are going to assume it is always defined.
* Used to load i18n files exclusively.
*
* To set up your own server in a test see `game_data.test.ts`
*/
var i18nServer: SetupServerApi;
}

View File

@ -1,13 +1,13 @@
import { BattleStyle } from "#app/enums/battle-style"; import { BattleStyle } from "#app/enums/battle-style";
import { CommandPhase } from "#app/phases/command-phase"; import { CommandPhase } from "#app/phases/command-phase";
import { TurnInitPhase } from "#app/phases/turn-init-phase"; import { TurnInitPhase } from "#app/phases/turn-init-phase";
import i18next, { initI18n } from "#app/plugins/i18n"; import i18next from "#app/plugins/i18n";
import { Mode } from "#app/ui/ui"; import { Mode } from "#app/ui/ui";
import { Abilities } from "#enums/abilities"; import { Abilities } from "#enums/abilities";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Ability Timing", () => { describe("Ability Timing", () => {
@ -32,11 +32,10 @@ describe("Ability Timing", () => {
.enemySpecies(Species.MAGIKARP) .enemySpecies(Species.MAGIKARP)
.enemyAbility(Abilities.INTIMIDATE) .enemyAbility(Abilities.INTIMIDATE)
.ability(Abilities.BALL_FETCH); .ability(Abilities.BALL_FETCH);
vi.spyOn(i18next, "t");
}); });
it("should trigger after switch check", async () => { it("should trigger after switch check", async () => {
initI18n();
i18next.changeLanguage("en");
game.settings.battleStyle = BattleStyle.SWITCH; game.settings.battleStyle = BattleStyle.SWITCH;
await game.classicMode.runToSummon([ Species.EEVEE, Species.FEEBAS ]); await game.classicMode.runToSummon([ Species.EEVEE, Species.FEEBAS ]);
@ -46,7 +45,6 @@ describe("Ability Timing", () => {
}, () => game.isCurrentPhase(CommandPhase) || game.isCurrentPhase(TurnInitPhase)); }, () => game.isCurrentPhase(CommandPhase) || game.isCurrentPhase(TurnInitPhase));
await game.phaseInterceptor.to("MessagePhase"); await game.phaseInterceptor.to("MessagePhase");
const message = game.textInterceptor.getLatestMessage(); expect(i18next.t).toHaveBeenCalledWith("battle:statFell", expect.objectContaining({ count: 1 }));
expect(message).toContain("battle:statFell");
}, 5000); }, 5000);
}); });

View File

@ -2,13 +2,13 @@ import { StatusEffect } from "#app/data/status-effect";
import { EnemyCommandPhase } from "#app/phases/enemy-command-phase"; import { EnemyCommandPhase } from "#app/phases/enemy-command-phase";
import { MessagePhase } from "#app/phases/message-phase"; import { MessagePhase } from "#app/phases/message-phase";
import { TurnEndPhase } from "#app/phases/turn-end-phase"; import { TurnEndPhase } from "#app/phases/turn-end-phase";
import i18next, { initI18n } from "#app/plugins/i18n"; import i18next from "#app/plugins/i18n";
import { Abilities } from "#enums/abilities"; import { Abilities } from "#enums/abilities";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
describe("Items - Toxic orb", () => { describe("Items - Toxic orb", () => {
@ -39,11 +39,11 @@ describe("Items - Toxic orb", () => {
game.override.startingHeldItems([{ game.override.startingHeldItems([{
name: "TOXIC_ORB", name: "TOXIC_ORB",
}]); }]);
vi.spyOn(i18next, "t");
}); });
it("TOXIC ORB", async () => { it("TOXIC ORB", async () => {
initI18n();
i18next.changeLanguage("en");
const moveToUse = Moves.GROWTH; const moveToUse = Moves.GROWTH;
await game.startBattle([ await game.startBattle([
Species.MIGHTYENA, Species.MIGHTYENA,
@ -57,11 +57,10 @@ describe("Items - Toxic orb", () => {
await game.phaseInterceptor.runFrom(EnemyCommandPhase).to(TurnEndPhase); await game.phaseInterceptor.runFrom(EnemyCommandPhase).to(TurnEndPhase);
// Toxic orb should trigger here // Toxic orb should trigger here
await game.phaseInterceptor.run(MessagePhase); await game.phaseInterceptor.run(MessagePhase);
const message = game.textInterceptor.getLatestMessage(); expect(i18next.t).toHaveBeenCalledWith("statusEffect:toxic.obtainSource", expect.anything());
expect(message).toContain("statusEffect:toxic.obtainSource");
await game.phaseInterceptor.run(MessagePhase); await game.phaseInterceptor.run(MessagePhase);
const message2 = game.textInterceptor.getLatestMessage(); expect(i18next.t).toHaveBeenCalledWith("statusEffect:toxic.activation", expect.anything());
expect(message2).toBe("statusEffect:toxic.activation");
expect(game.scene.getParty()[0].status!.effect).toBe(StatusEffect.TOXIC); expect(game.scene.getParty()[0].status!.effect).toBe(StatusEffect.TOXIC);
}, 20000); }, 20000);
}); });

View File

@ -16,6 +16,7 @@ import { EggTier } from "#enums/egg-type";
import { CommandPhase } from "#app/phases/command-phase"; import { CommandPhase } from "#app/phases/command-phase";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import { PartyHealPhase } from "#app/phases/party-heal-phase"; import { PartyHealPhase } from "#app/phases/party-heal-phase";
import i18next from "i18next";
const namespace = "mysteryEncounters/aTrainersTest"; const namespace = "mysteryEncounters/aTrainersTest";
const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ]; const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ];
@ -106,7 +107,8 @@ describe("A Trainer's Test - Mystery Encounter", () => {
expect(scene.getCurrentPhase()?.constructor.name).toBe(CommandPhase.name); expect(scene.getCurrentPhase()?.constructor.name).toBe(CommandPhase.name);
expect(enemyField.length).toBe(1); expect(enemyField.length).toBe(1);
expect(scene.currentBattle.trainer).toBeDefined(); expect(scene.currentBattle.trainer).toBeDefined();
expect([ "trainerNames:buck", "trainerNames:cheryl", "trainerNames:marley", "trainerNames:mira", "trainerNames:riley" ].includes(scene.currentBattle.trainer!.config.name)).toBeTruthy(); expect([ i18next.t("trainerNames:buck"), i18next.t("trainerNames:cheryl"), i18next.t("trainerNames:marley"), i18next.t("trainerNames:mira"), i18next.t("trainerNames:riley") ]
.map(name => name.toLowerCase()).includes(scene.currentBattle.trainer!.config.name)).toBeTruthy();
expect(enemyField[0]).toBeDefined(); expect(enemyField[0]).toBeDefined();
}); });

View File

@ -16,6 +16,7 @@ import { Moves } from "#enums/moves";
import { CommandPhase } from "#app/phases/command-phase"; import { CommandPhase } from "#app/phases/command-phase";
import { MovePhase } from "#app/phases/move-phase"; import { MovePhase } from "#app/phases/move-phase";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import i18next from "i18next";
const namespace = "mysteryEncounters/absoluteAvarice"; const namespace = "mysteryEncounters/absoluteAvarice";
const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ]; const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ];
@ -146,7 +147,7 @@ describe("Absolute Avarice - Mystery Encounter", () => {
const pokemonId = partyPokemon.id; const pokemonId = partyPokemon.id;
const pokemonItems = scene.findModifiers(m => m instanceof PokemonHeldItemModifier const pokemonItems = scene.findModifiers(m => m instanceof PokemonHeldItemModifier
&& (m as PokemonHeldItemModifier).pokemonId === pokemonId, true) as PokemonHeldItemModifier[]; && (m as PokemonHeldItemModifier).pokemonId === pokemonId, true) as PokemonHeldItemModifier[];
const revSeed = pokemonItems.find(i => i.type.name === "modifierType:ModifierType.REVIVER_SEED.name"); const revSeed = pokemonItems.find(i => i.type.name === i18next.t("modifierType:ModifierType.REVIVER_SEED.name"));
expect(revSeed).toBeDefined; expect(revSeed).toBeDefined;
expect(revSeed?.stackCount).toBe(1); expect(revSeed?.stackCount).toBe(1);
} }

View File

@ -17,6 +17,7 @@ import { getPokemonSpecies } from "#app/data/pokemon-species";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { ShinyRateBoosterModifier } from "#app/modifier/modifier"; import { ShinyRateBoosterModifier } from "#app/modifier/modifier";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import i18next from "i18next";
const namespace = "mysteryEncounters/anOfferYouCantRefuse"; const namespace = "mysteryEncounters/anOfferYouCantRefuse";
/** Gyarados for Indimidate */ /** Gyarados for Indimidate */
@ -93,8 +94,8 @@ describe("An Offer You Can't Refuse - Mystery Encounter", () => {
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.strongestPokemon).toBeDefined(); expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.strongestPokemon).toBeDefined();
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.price).toBeDefined(); expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.price).toBeDefined();
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.option2PrimaryAbility).toBe("ability:intimidate.name"); expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.option2PrimaryAbility).toBe(i18next.t("ability:intimidate.name"));
expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.moveOrAbility).toBe("ability:intimidate.name"); expect(AnOfferYouCantRefuseEncounter.dialogueTokens?.moveOrAbility).toBe(i18next.t("ability:intimidate.name"));
expect(AnOfferYouCantRefuseEncounter.misc.pokemon instanceof PlayerPokemon).toBeTruthy(); expect(AnOfferYouCantRefuseEncounter.misc.pokemon instanceof PlayerPokemon).toBeTruthy();
expect(AnOfferYouCantRefuseEncounter.misc?.price?.toString()).toBe(AnOfferYouCantRefuseEncounter.dialogueTokens?.price); expect(AnOfferYouCantRefuseEncounter.misc?.price?.toString()).toBe(AnOfferYouCantRefuseEncounter.dialogueTokens?.price);
expect(onInitResult).toBe(true); expect(onInitResult).toBe(true);

View File

@ -103,11 +103,11 @@ describe("Field Trip - Mystery Encounter", () => {
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler; const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
expect(modifierSelectHandler.options.length).toEqual(5); expect(modifierSelectHandler.options.length).toEqual(5);
expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_attack"); expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_attack"));
expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_defense"); expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_defense"));
expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_speed"); expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_speed"));
expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe("modifierType:ModifierType.DIRE_HIT.name"); expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.DIRE_HIT.name"));
expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe("modifierType:ModifierType.RARER_CANDY.name"); expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.RARER_CANDY.name"));
}); });
it("should leave encounter without battle", async () => { it("should leave encounter without battle", async () => {
@ -150,11 +150,11 @@ describe("Field Trip - Mystery Encounter", () => {
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler; const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
expect(modifierSelectHandler.options.length).toEqual(5); expect(modifierSelectHandler.options.length).toEqual(5);
expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_sp_atk"); expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_sp_atk"));
expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_sp_def"); expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_sp_def"));
expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_speed"); expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_speed"));
expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe("modifierType:ModifierType.DIRE_HIT.name"); expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.DIRE_HIT.name"));
expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe("modifierType:ModifierType.RARER_CANDY.name"); expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.RARER_CANDY.name"));
}); });
it("should leave encounter without battle", async () => { it("should leave encounter without battle", async () => {
@ -198,12 +198,12 @@ describe("Field Trip - Mystery Encounter", () => {
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler; const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
expect(modifierSelectHandler.options.length).toEqual(5); expect(modifierSelectHandler.options.length).toEqual(5);
expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_accuracy"); expect(modifierSelectHandler.options[0].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_accuracy"));
expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe("modifierType:TempStatStageBoosterItem.x_speed"); expect(modifierSelectHandler.options[1].modifierTypeOption.type.name).toBe(i18next.t("modifierType:TempStatStageBoosterItem.x_speed"));
expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe("modifierType:ModifierType.AddPokeballModifierType.name"); expect(modifierSelectHandler.options[2].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.AddPokeballModifierType.name", { modifierCount: 5, pokeballName: i18next.t("pokeball:greatBall") }));
expect(i18next.t).toHaveBeenCalledWith("modifierType:ModifierType.AddPokeballModifierType.name", expect.objectContaining({ modifierCount: 5 })); expect(i18next.t).toHaveBeenCalledWith(("modifierType:ModifierType.AddPokeballModifierType.name"), expect.objectContaining({ modifierCount: 5 }));
expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe("modifierType:ModifierType.IV_SCANNER.name"); expect(modifierSelectHandler.options[3].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.IV_SCANNER.name"));
expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe("modifierType:ModifierType.RARER_CANDY.name"); expect(modifierSelectHandler.options[4].modifierTypeOption.type.name).toBe(i18next.t("modifierType:ModifierType.RARER_CANDY.name"));
}); });
it("should leave encounter without battle", async () => { it("should leave encounter without battle", async () => {

View File

@ -22,6 +22,7 @@ import { initSceneWithoutEncounterPhase } from "#test/utils/gameManagerUtils";
import { CommandPhase } from "#app/phases/command-phase"; import { CommandPhase } from "#app/phases/command-phase";
import { MovePhase } from "#app/phases/move-phase"; import { MovePhase } from "#app/phases/move-phase";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase"; import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import i18next from "i18next";
const namespace = "mysteryEncounters/fieryFallout"; const namespace = "mysteryEncounters/fieryFallout";
/** Arcanine and Ninetails for 2 Fire types. Lapras, Gengar, Abra for burnable mon. */ /** Arcanine and Ninetails for 2 Fire types. Lapras, Gengar, Abra for burnable mon. */
@ -205,7 +206,7 @@ describe("Fiery Fallout - Mystery Encounter", () => {
const burnablePokemon = party.filter((pkm) => pkm.isAllowedInBattle() && !pkm.getTypes().includes(Type.FIRE)); const burnablePokemon = party.filter((pkm) => pkm.isAllowedInBattle() && !pkm.getTypes().includes(Type.FIRE));
const notBurnablePokemon = party.filter((pkm) => !pkm.isAllowedInBattle() || pkm.getTypes().includes(Type.FIRE)); const notBurnablePokemon = party.filter((pkm) => !pkm.isAllowedInBattle() || pkm.getTypes().includes(Type.FIRE));
expect(scene.currentBattle.mysteryEncounter?.dialogueTokens["burnedPokemon"]).toBe("pokemon:gengar"); expect(scene.currentBattle.mysteryEncounter?.dialogueTokens["burnedPokemon"]).toBe(i18next.t("pokemon:gengar"));
burnablePokemon.forEach((pkm) => { burnablePokemon.forEach((pkm) => {
expect(pkm.hp, `${pkm.name} should have received 20% damage: ${pkm.hp} / ${pkm.getMaxHp()} HP`).toBe(pkm.getMaxHp() - Math.floor(pkm.getMaxHp() * 0.2)); expect(pkm.hp, `${pkm.name} should have received 20% damage: ${pkm.hp} / ${pkm.getMaxHp()} HP`).toBe(pkm.getMaxHp() - Math.floor(pkm.getMaxHp() * 0.2));
}); });

View File

@ -14,6 +14,7 @@ import { initSceneWithoutEncounterPhase } from "#test/utils/gameManagerUtils";
import BattleScene from "#app/battle-scene"; import BattleScene from "#app/battle-scene";
import { MysteryEncounterPhase } from "#app/phases/mystery-encounter-phases"; import { MysteryEncounterPhase } from "#app/phases/mystery-encounter-phases";
import { PartyExpPhase } from "#app/phases/party-exp-phase"; import { PartyExpPhase } from "#app/phases/party-exp-phase";
import i18next from "i18next";
const namespace = "mysteryEncounters/lostAtSea"; const namespace = "mysteryEncounters/lostAtSea";
@ -86,8 +87,8 @@ describe("Lost at Sea - Mystery Encounter", () => {
const onInitResult = onInit!(scene); const onInitResult = onInit!(scene);
expect(LostAtSeaEncounter.dialogueTokens?.damagePercentage).toBe("25"); expect(LostAtSeaEncounter.dialogueTokens?.damagePercentage).toBe("25");
expect(LostAtSeaEncounter.dialogueTokens?.option1RequiredMove).toBe("move:surf.name"); expect(LostAtSeaEncounter.dialogueTokens?.option1RequiredMove).toBe(i18next.t("move:surf.name"));
expect(LostAtSeaEncounter.dialogueTokens?.option2RequiredMove).toBe("move:fly.name"); expect(LostAtSeaEncounter.dialogueTokens?.option2RequiredMove).toBe(i18next.t("move:fly.name"));
expect(onInitResult).toBe(true); expect(onInitResult).toBe(true);
}); });

View File

@ -1,21 +1,22 @@
import * as MysteryEncounters from "#app/data/mystery-encounters/mystery-encounters";
import { Biome } from "#app/enums/biome";
import { MysteryEncounterType } from "#app/enums/mystery-encounter-type";
import { Species } from "#app/enums/species";
import GameManager from "#app/test/utils/gameManager";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { runMysteryEncounterToEnd, runSelectMysteryEncounterOption, skipBattleRunMysteryEncounterRewardsPhase } from "#test/mystery-encounter/encounter-test-utils";
import BattleScene from "#app/battle-scene"; import BattleScene from "#app/battle-scene";
import { TeleportingHijinksEncounter } from "#app/data/mystery-encounters/encounters/teleporting-hijinks-encounter";
import * as MysteryEncounters from "#app/data/mystery-encounters/mystery-encounters";
import { Abilities } from "#enums/abilities";
import { Biome } from "#enums/biome";
import { MysteryEncounterType } from "#enums/mystery-encounter-type";
import { Species } from "#enums/species";
import { CommandPhase } from "#app/phases/command-phase";
import { MysteryEncounterPhase } from "#app/phases/mystery-encounter-phases";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import GameManager from "#test/utils/gameManager";
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
import { Mode } from "#app/ui/ui";
import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode"; import { MysteryEncounterOptionMode } from "#enums/mystery-encounter-option-mode";
import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
import { runMysteryEncounterToEnd, runSelectMysteryEncounterOption, skipBattleRunMysteryEncounterRewardsPhase } from "#test/mystery-encounter/encounter-test-utils";
import { initSceneWithoutEncounterPhase } from "#test/utils/gameManagerUtils"; import { initSceneWithoutEncounterPhase } from "#test/utils/gameManagerUtils";
import { MysteryEncounterPhase } from "#app/phases/mystery-encounter-phases"; import i18next from "i18next";
import { CommandPhase } from "#app/phases/command-phase"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { TeleportingHijinksEncounter } from "#app/data/mystery-encounters/encounters/teleporting-hijinks-encounter";
import { SelectModifierPhase } from "#app/phases/select-modifier-phase";
import { Mode } from "#app/ui/ui";
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
import { Abilities } from "#app/enums/abilities";
const namespace = "mysteryEncounters/teleportingHijinks"; const namespace = "mysteryEncounters/teleportingHijinks";
const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ]; const defaultParty = [ Species.LAPRAS, Species.GENGAR, Species.ABRA ];
@ -300,8 +301,8 @@ describe("Teleporting Hijinks - Mystery Encounter", () => {
expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT); expect(scene.ui.getMode()).to.equal(Mode.MODIFIER_SELECT);
const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler; const modifierSelectHandler = scene.ui.handlers.find(h => h instanceof ModifierSelectUiHandler) as ModifierSelectUiHandler;
expect(modifierSelectHandler.options.some(opt => opt.modifierTypeOption.type.name === "modifierType:AttackTypeBoosterItem.metal_coat")).toBe(true); expect(modifierSelectHandler.options.some(opt => opt.modifierTypeOption.type.name === i18next.t("modifierType:AttackTypeBoosterItem.metal_coat"))).toBe(true);
expect(modifierSelectHandler.options.some(opt => opt.modifierTypeOption.type.name === "modifierType:AttackTypeBoosterItem.magnet")).toBe(true); expect(modifierSelectHandler.options.some(opt => opt.modifierTypeOption.type.name === i18next.t("modifierType:AttackTypeBoosterItem.magnet"))).toBe(true);
}); });
}); });
}); });

View File

@ -9,6 +9,7 @@ import MysteryEncounterUiHandler from "#app/ui/mystery-encounter-ui-handler";
import { MysteryEncounterType } from "#enums/mystery-encounter-type"; import { MysteryEncounterType } from "#enums/mystery-encounter-type";
import MessageUiHandler from "#app/ui/message-ui-handler"; import MessageUiHandler from "#app/ui/message-ui-handler";
import { MysteryEncounterTier } from "#enums/mystery-encounter-tier"; import { MysteryEncounterTier } from "#enums/mystery-encounter-tier";
import i18next from "i18next";
describe("Mystery Encounter Phases", () => { describe("Mystery Encounter Phases", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -78,9 +79,9 @@ describe("Mystery Encounter Phases", () => {
expect(ui.getMode()).toBe(Mode.MESSAGE); expect(ui.getMode()).toBe(Mode.MESSAGE);
expect(ui.showDialogue).toHaveBeenCalledTimes(1); expect(ui.showDialogue).toHaveBeenCalledTimes(1);
expect(ui.showText).toHaveBeenCalledTimes(2); expect(ui.showText).toHaveBeenCalledTimes(2);
expect(ui.showDialogue).toHaveBeenCalledWith("battle:mysteryEncounterAppeared", "???", null, expect.any(Function)); expect(ui.showDialogue).toHaveBeenCalledWith(i18next.t("battle:mysteryEncounterAppeared"), "???", null, expect.any(Function));
expect(ui.showText).toHaveBeenCalledWith("mysteryEncounters/mysteriousChallengers:intro", null, expect.any(Function), 750, true); expect(ui.showText).toHaveBeenCalledWith(i18next.t("mysteryEncounters/mysteriousChallengers:intro"), null, expect.any(Function), 750, true);
expect(ui.showText).toHaveBeenCalledWith("mysteryEncounters/mysteriousChallengers:option.selected", null, expect.any(Function), 300, true); expect(ui.showText).toHaveBeenCalledWith(i18next.t("mysteryEncounters/mysteriousChallengers:option.selected"), null, expect.any(Function), 300, true);
}); });
}); });

View File

@ -11,13 +11,15 @@ import * as account from "../../account";
const apiBase = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:8001"; const apiBase = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:8001";
export const server = setupServer(); /** We need a custom server. For some reasons I can't extend the listeners of {@linkcode global.i18nServer} with {@linkcode global.i18nServer.use} */
const server = setupServer();
describe("System - Game Data", () => { describe("System - Game Data", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
let game: GameManager; let game: GameManager;
beforeAll(() => { beforeAll(() => {
global.i18nServer.close();
server.listen(); server.listen();
phaserGame = new Phaser.Game({ phaserGame = new Phaser.Game({
type: Phaser.HEADLESS, type: Phaser.HEADLESS,
@ -26,6 +28,7 @@ describe("System - Game Data", () => {
afterAll(() => { afterAll(() => {
server.close(); server.close();
global.i18nServer.listen();
}); });
beforeEach(() => { beforeEach(() => {

View File

@ -14,6 +14,7 @@ import { Abilities } from "#enums/abilities";
import { Button } from "#enums/buttons"; import { Button } from "#enums/buttons";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import i18next from "i18next";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
@ -66,11 +67,11 @@ describe("UI - Starter select", () => {
resolve(); resolve();
}); });
}); });
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
expect(options.some(option => option.label === "menu:cancel")).toBe(true); expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
optionSelectUiHandler?.processInput(Button.ACTION); optionSelectUiHandler?.processInput(Button.ACTION);
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
@ -127,11 +128,11 @@ describe("UI - Starter select", () => {
resolve(); resolve();
}); });
}); });
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
expect(options.some(option => option.label === "menu:cancel")).toBe(true); expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
optionSelectUiHandler?.processInput(Button.ACTION); optionSelectUiHandler?.processInput(Button.ACTION);
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
@ -191,11 +192,11 @@ describe("UI - Starter select", () => {
resolve(); resolve();
}); });
}); });
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
expect(options.some(option => option.label === "menu:cancel")).toBe(true); expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
optionSelectUiHandler?.processInput(Button.ACTION); optionSelectUiHandler?.processInput(Button.ACTION);
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
@ -254,11 +255,11 @@ describe("UI - Starter select", () => {
resolve(); resolve();
}); });
}); });
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
expect(options.some(option => option.label === "menu:cancel")).toBe(true); expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
optionSelectUiHandler?.processInput(Button.ACTION); optionSelectUiHandler?.processInput(Button.ACTION);
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
@ -315,11 +316,11 @@ describe("UI - Starter select", () => {
resolve(); resolve();
}); });
}); });
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
expect(options.some(option => option.label === "menu:cancel")).toBe(true); expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
optionSelectUiHandler?.processInput(Button.ACTION); optionSelectUiHandler?.processInput(Button.ACTION);
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
@ -376,11 +377,11 @@ describe("UI - Starter select", () => {
resolve(); resolve();
}); });
}); });
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
expect(options.some(option => option.label === "menu:cancel")).toBe(true); expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
optionSelectUiHandler?.processInput(Button.ACTION); optionSelectUiHandler?.processInput(Button.ACTION);
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
@ -436,11 +437,11 @@ describe("UI - Starter select", () => {
resolve(); resolve();
}); });
}); });
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
expect(options.some(option => option.label === "menu:cancel")).toBe(true); expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
optionSelectUiHandler?.processInput(Button.ACTION); optionSelectUiHandler?.processInput(Button.ACTION);
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
@ -496,11 +497,11 @@ describe("UI - Starter select", () => {
resolve(); resolve();
}); });
}); });
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
expect(options.some(option => option.label === "menu:cancel")).toBe(true); expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
optionSelectUiHandler?.processInput(Button.ACTION); optionSelectUiHandler?.processInput(Button.ACTION);
let starterSelectUiHandler: StarterSelectUiHandler; let starterSelectUiHandler: StarterSelectUiHandler;
@ -561,11 +562,11 @@ describe("UI - Starter select", () => {
resolve(); resolve();
}); });
}); });
expect(options.some(option => option.label === "starterSelectUiHandler:addToParty")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:addToParty"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:toggleIVs")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:toggleIVs"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:manageMoves")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:manageMoves"))).toBe(true);
expect(options.some(option => option.label === "starterSelectUiHandler:useCandies")).toBe(true); expect(options.some(option => option.label === i18next.t("starterSelectUiHandler:useCandies"))).toBe(true);
expect(options.some(option => option.label === "menu:cancel")).toBe(true); expect(options.some(option => option.label === i18next.t("menu:cancel"))).toBe(true);
optionSelectUiHandler?.processInput(Button.ACTION); optionSelectUiHandler?.processInput(Button.ACTION);
let starterSelectUiHandler: StarterSelectUiHandler | undefined; let starterSelectUiHandler: StarterSelectUiHandler | undefined;

View File

@ -7,7 +7,8 @@ import { Mode } from "#app/ui/ui";
import GameManager from "#test/utils/gameManager"; import GameManager from "#test/utils/gameManager";
import Phaser from "phaser"; import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import MockText from "../utils/mocks/mocksContainer/mockText"; import MockText from "#test/utils/mocks/mocksContainer/mockText";
import i18next from "i18next";
describe("UI - Type Hints", () => { describe("UI - Type Hints", () => {
let phaserGame: Phaser.Game; let phaserGame: Phaser.Game;
@ -53,7 +54,7 @@ describe("UI - Type Hints", () => {
const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME); const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME);
const dragonClawText = movesContainer const dragonClawText = movesContainer
.getAll<Phaser.GameObjects.Text>() .getAll<Phaser.GameObjects.Text>()
.find((text) => text.text === "move:dragonClaw.name")! as unknown as MockText; .find((text) => text.text === i18next.t("move:dragonClaw.name"))! as unknown as MockText;
expect.soft(dragonClawText.color).toBe("#929292"); expect.soft(dragonClawText.color).toBe("#929292");
ui.getHandler().processInput(Button.ACTION); ui.getHandler().processInput(Button.ACTION);
@ -78,7 +79,7 @@ describe("UI - Type Hints", () => {
const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME); const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME);
const growlText = movesContainer const growlText = movesContainer
.getAll<Phaser.GameObjects.Text>() .getAll<Phaser.GameObjects.Text>()
.find((text) => text.text === "move:growl.name")! as unknown as MockText; .find((text) => text.text === i18next.t("move:growl.name"))! as unknown as MockText;
expect.soft(growlText.color).toBe(undefined); expect.soft(growlText.color).toBe(undefined);
ui.getHandler().processInput(Button.ACTION); ui.getHandler().processInput(Button.ACTION);

View File

@ -4,16 +4,17 @@ import { initLoggedInUser } from "#app/account";
import { initAbilities } from "#app/data/ability"; import { initAbilities } from "#app/data/ability";
import { initBiomes } from "#app/data/balance/biomes"; import { initBiomes } from "#app/data/balance/biomes";
import { initEggMoves } from "#app/data/balance/egg-moves"; import { initEggMoves } from "#app/data/balance/egg-moves";
import { initPokemonPrevolutions } from "#app/data/balance/pokemon-evolutions";
import { initMoves } from "#app/data/move"; import { initMoves } from "#app/data/move";
import { initMysteryEncounters } from "#app/data/mystery-encounters/mystery-encounters"; import { initMysteryEncounters } from "#app/data/mystery-encounters/mystery-encounters";
import { initPokemonPrevolutions } from "#app/data/balance/pokemon-evolutions";
import { initPokemonForms } from "#app/data/pokemon-forms"; import { initPokemonForms } from "#app/data/pokemon-forms";
import { initSpecies } from "#app/data/pokemon-species"; import { initSpecies } from "#app/data/pokemon-species";
import { initAchievements } from "#app/system/achv"; import { initAchievements } from "#app/system/achv";
import { initVouchers } from "#app/system/voucher"; import { initVouchers } from "#app/system/voucher";
import { initStatsKeys } from "#app/ui/game-stats-ui-handler"; import { initStatsKeys } from "#app/ui/game-stats-ui-handler";
import { beforeAll, vi } from "vitest"; import { afterAll, beforeAll, vi } from "vitest";
/** Set the timezone to UTC for tests. */
process.env.TZ = "UTC"; process.env.TZ = "UTC";
/** Mock the override import to always return default values, ignoring any custom overrides. */ /** Mock the override import to always return default values, ignoring any custom overrides. */
@ -26,26 +27,36 @@ vi.mock("#app/overrides", async (importOriginal) => {
} satisfies typeof import("#app/overrides"); } satisfies typeof import("#app/overrides");
}); });
vi.mock("i18next", () => ({ /**
default: { * This is a hacky way to mock the i18n backend requests (with the help of {@link https://mswjs.io/ | msw}).
use: () => {}, * The reason to put it inside of a mock is to elevate it.
t: (key: string) => key, * This is necessary because how our code is structured.
changeLanguage: () => Promise.resolve(), * Do NOT try to put any of this code into external functions, it won't work as it's elevated during runtime.
init: () => Promise.resolve(), */
resolvedLanguage: "en", vi.mock("i18next", async (importOriginal) => {
exists: () => true, console.log("Mocking i18next");
getDataByLanguage:() => ({ const { setupServer } = await import("msw/node");
en: { const { http, HttpResponse } = await import("msw");
keys: [ "foo" ]
}, global.i18nServer = setupServer(
}), http.get("/locales/en/*", async (req) => {
services: { const filename = req.params[0];
formatter: {
add: () => {}, try {
const json = await import(`../../public/locales/en/${req.params[0]}`);
console.log("Loaded locale", filename);
return HttpResponse.json(json);
} catch (err) {
console.log(`Failed to load locale ${filename}!`, err);
return HttpResponse.json({});
} }
}, })
}, );
})); global.i18nServer.listen({ onUnhandledRequest: "error" });
console.log("i18n MSW server listening!");
return await importOriginal();
});
initVouchers(); initVouchers();
initAchievements(); initAchievements();
@ -70,3 +81,8 @@ beforeAll(() => {
}, },
}); });
}); });
afterAll(() => {
global.i18nServer.close();
console.log("Closing i18n MSW server!");
});