mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-04-08 02:43:26 +01:00
* Reuse global scene between tests Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Add missing each method to mockContainer * Fix select-modifier-phase test * Sanitize overrides before tests Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Sanitize overrides before tests Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * [WIP] fix things * Fix tests not working with --no-isolate * Update npm tests to use no isolate * Update test-shard-template * Update package.json Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --------- Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
77 lines
2.7 KiB
TypeScript
77 lines
2.7 KiB
TypeScript
import "vitest-canvas-mock";
|
|
|
|
import { initLoggedInUser } from "#app/account";
|
|
import { initAbilities } from "#app/data/ability";
|
|
import { initBiomes } from "#app/data/balance/biomes";
|
|
import { initEggMoves } from "#app/data/balance/egg-moves";
|
|
import { initPokemonPrevolutions } from "#app/data/balance/pokemon-evolutions";
|
|
import { initMoves } from "#app/data/moves/move";
|
|
import { initMysteryEncounters } from "#app/data/mystery-encounters/mystery-encounters";
|
|
import { initPokemonForms } from "#app/data/pokemon-forms";
|
|
import { initSpecies } from "#app/data/pokemon-species";
|
|
import { initAchievements } from "#app/system/achv";
|
|
import { initVouchers } from "#app/system/voucher";
|
|
import { initStatsKeys } from "#app/ui/game-stats-ui-handler";
|
|
import { afterAll, beforeAll, vi } from "vitest";
|
|
|
|
import { initTestFile } from "./testUtils/testFileInitialization";
|
|
|
|
/** Set the timezone to UTC for tests. */
|
|
|
|
/** Mock the override import to always return default values, ignoring any custom overrides. */
|
|
vi.mock("#app/overrides", async importOriginal => {
|
|
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
const { defaultOverrides } = await importOriginal<typeof import("#app/overrides")>();
|
|
|
|
return {
|
|
default: defaultOverrides,
|
|
defaultOverrides,
|
|
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
} satisfies typeof import("#app/overrides");
|
|
});
|
|
|
|
/**
|
|
* This is a hacky way to mock the i18n backend requests (with the help of {@link https://mswjs.io/ | msw}).
|
|
* The reason to put it inside of a mock is to elevate it.
|
|
* This is necessary because how our code is structured.
|
|
* Do NOT try to put any of this code into external functions, it won't work as it's elevated during runtime.
|
|
*/
|
|
vi.mock("i18next", async importOriginal => {
|
|
console.log("Mocking i18next");
|
|
const { setupServer } = await import("msw/node");
|
|
const { http, HttpResponse } = await import("msw");
|
|
|
|
global.server = setupServer(
|
|
http.get("/locales/en/*", async req => {
|
|
const filename = req.params[0];
|
|
|
|
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({});
|
|
}
|
|
}),
|
|
http.get("https://fonts.googleapis.com/*", () => {
|
|
return HttpResponse.text("");
|
|
}),
|
|
);
|
|
global.server.listen({ onUnhandledRequest: "error" });
|
|
console.log("i18n MSW server listening!");
|
|
|
|
return await importOriginal();
|
|
});
|
|
|
|
global.testFailed = false;
|
|
|
|
beforeAll(() => {
|
|
initTestFile();
|
|
});
|
|
|
|
afterAll(() => {
|
|
global.server.close();
|
|
console.log("Closing i18n MSW server!");
|
|
});
|