Fix test runner error

This commit is contained in:
Sirz Benjie 2025-04-14 16:39:00 -05:00
parent 1df7a1dd72
commit 4988d6eb6d
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E
4 changed files with 15 additions and 7 deletions

View File

@ -14,6 +14,7 @@ import { DamageMoneyRewardModifier, ExtraModifierModifier, MoneyMultiplierModifi
import { SpeciesFormKey } from "#enums/species-form-key"; import { SpeciesFormKey } from "#enums/species-form-key";
import { speciesStarterCosts } from "./starters"; import { speciesStarterCosts } from "./starters";
import i18next from "i18next"; import i18next from "i18next";
import { initI18n } from "#app/plugins/i18n";
export enum SpeciesWildEvolutionDelay { export enum SpeciesWildEvolutionDelay {
@ -95,6 +96,9 @@ export class SpeciesFormEvolution {
public description = ""; public description = "";
constructor(speciesId: Species, preFormKey: string | null, evoFormKey: string | null, level: number, item: EvolutionItem | null, condition: SpeciesEvolutionCondition | null, wildDelay?: SpeciesWildEvolutionDelay) { constructor(speciesId: Species, preFormKey: string | null, evoFormKey: string | null, level: number, item: EvolutionItem | null, condition: SpeciesEvolutionCondition | null, wildDelay?: SpeciesWildEvolutionDelay) {
if (!i18next.isInitialized) {
initI18n();
}
this.speciesId = speciesId; this.speciesId = speciesId;
this.preFormKey = preFormKey; this.preFormKey = preFormKey;
this.evoFormKey = evoFormKey; this.evoFormKey = evoFormKey;

View File

@ -1,4 +1,4 @@
import * as battleScene from "#app/battle-scene"; import * as bypassLogin from "#app/global-vars/bypass-login";
import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
import { describe, expect, it, vi } from "vitest"; import { describe, expect, it, vi } from "vitest";
import { initLoggedInUser, loggedInUser, updateUserInfo } from "#app/account"; import { initLoggedInUser, loggedInUser, updateUserInfo } from "#app/account";
@ -15,7 +15,7 @@ describe("account", () => {
describe("updateUserInfo", () => { describe("updateUserInfo", () => {
it("should set loggedInUser! to Guest if bypassLogin is true", async () => { it("should set loggedInUser! to Guest if bypassLogin is true", async () => {
vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(true); vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(true);
const [success, status] = await updateUserInfo(); const [success, status] = await updateUserInfo();
@ -26,7 +26,7 @@ describe("account", () => {
}); });
it("should fetch user info from the API if bypassLogin is false", async () => { it("should fetch user info from the API if bypassLogin is false", async () => {
vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(false); vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(false);
vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([ vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([
{ {
username: "test", username: "test",
@ -47,7 +47,7 @@ describe("account", () => {
}); });
it("should handle resolved API errors", async () => { it("should handle resolved API errors", async () => {
vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(false); vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(false);
vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([null, 401]); vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([null, 401]);
const [success, status] = await updateUserInfo(); const [success, status] = await updateUserInfo();
@ -57,7 +57,7 @@ describe("account", () => {
}); });
it("should handle 500 API errors", async () => { it("should handle 500 API errors", async () => {
vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(false); vi.spyOn(bypassLogin, "bypassLogin", "get").mockReturnValue(false);
vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([null, 500]); vi.spyOn(pokerogueApi.account, "getInfo").mockResolvedValue([null, 500]);
const [success, status] = await updateUserInfo(); const [success, status] = await updateUserInfo();

View File

@ -1,5 +1,5 @@
// @ts-nocheck - TODO: remove this // @ts-nocheck - TODO: remove this
import BattleScene, * as battleScene from "#app/battle-scene"; import BattleScene from "#app/battle-scene";
import { MoveAnim } from "#app/data/battle-anims"; import { MoveAnim } from "#app/data/battle-anims";
import Pokemon from "#app/field/pokemon"; import Pokemon from "#app/field/pokemon";
import { sessionIdKey } from "#app/utils/common"; import { sessionIdKey } from "#app/utils/common";
@ -21,6 +21,8 @@ import KeyboardPlugin = Phaser.Input.Keyboard.KeyboardPlugin;
import GamepadPlugin = Phaser.Input.Gamepad.GamepadPlugin; import GamepadPlugin = Phaser.Input.Gamepad.GamepadPlugin;
import EventEmitter = Phaser.Events.EventEmitter; import EventEmitter = Phaser.Events.EventEmitter;
import UpdateList = Phaser.GameObjects.UpdateList; import UpdateList = Phaser.GameObjects.UpdateList;
// biome-ignore lint/style/noNamespaceImport: Necessary in order to mock the var
import * as bypassLoginModule from "#app/global-vars/bypass-login";
window.URL.createObjectURL = (blob: Blob) => { window.URL.createObjectURL = (blob: Blob) => {
blobToString(blob).then((data: string) => { blobToString(blob).then((data: string) => {
@ -44,7 +46,7 @@ export default class GameWrapper {
Phaser.Math.RND.sow(["test"]); Phaser.Math.RND.sow(["test"]);
// vi.spyOn(Utils, "apiFetch", "get").mockReturnValue(fetch); // vi.spyOn(Utils, "apiFetch", "get").mockReturnValue(fetch);
if (bypassLogin) { if (bypassLogin) {
vi.spyOn(battleScene, "bypassLogin", "get").mockReturnValue(true); vi.spyOn(bypassLoginModule, "bypassLogin", "get").mockReturnValue(true);
} }
this.game = phaserGame; this.game = phaserGame;
MoveAnim.prototype.getAnim = () => ({ MoveAnim.prototype.getAnim = () => ({

View File

@ -21,6 +21,7 @@ import Phaser from "phaser";
import InputText from "phaser3-rex-plugins/plugins/inputtext"; import InputText from "phaser3-rex-plugins/plugins/inputtext";
import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext"; import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext";
import { manageListeners } from "./listenersManager"; import { manageListeners } from "./listenersManager";
import { initI18n } from "#app/plugins/i18n";
let wasInitialized = false; let wasInitialized = false;
/** /**
@ -87,6 +88,7 @@ export function initTestFile() {
// initSpecies(); // initSpecies();
if (!wasInitialized) { if (!wasInitialized) {
wasInitialized = true; wasInitialized = true;
initI18n();
initVouchers(); initVouchers();
initAchievements(); initAchievements();
initStatsKeys(); initStatsKeys();