pokerogue/test/vitest.setup.ts
Bertie690 c0da686ba0
[Dev] Migrated to Biome 2.2.3, added more rules (#6259)
* Added more biome rules

* Fixes

* Added a few more rules

* Added global phaser to biome

* Fix tpyo

* Updated biome to 2.1.4; improved docs on linting/localization; added vcs support

Also added `.build` to gitignore cuz reasons

* Fixed tpyo

* dd

* Applied linter fixes

* Partially fixed some private property issues

* Upgraded to Biome 2.2.0; added `operatorLinebreak` and a few new rules

* Moved operator linebreaks before lines

* Applied kev's suggestions

* Update biome.jsonc

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

* added like all the rules and then some

* modify biome.jsonc

* apply biome formatting

* Reverted changes to balance folder

* fixed stuff

* Fixed biome stripping trailing globstars from everything

* made `noInvertedElse` an error rule

* Add & apply fixes for `useExplicitLengthCheck`, `useAtIndex` and `noNonNullAssertedOptionalChain`

* Bumped biome to 2.2.3

* Fixed a few syntax errors

* Removed trailing globstars since biome actually fixed their shit

* Final clean up

* foobarbaz

* Fixed remaining issues

* Fixed a few errors in SSUI

* fixed rounding issue

* Fixed test to not round funky

* Fixed biome false positive for vitest hooks

* Apply biome:all

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
Co-authored-by: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com>
2025-09-08 10:35:18 -05:00

79 lines
2.7 KiB
TypeScript

import "vitest-canvas-mock";
import { MockConsole } from "#test/test-utils/mocks/mock-console/mock-console";
import { logTestEnd, logTestStart } from "#test/test-utils/setup/test-end-log";
import { initTests } from "#test/test-utils/test-file-initialization";
import chalk from "chalk";
import { afterAll, afterEach, beforeAll, beforeEach, vi } from "vitest";
//#region Mocking
// Mock the override import to always return default values, ignoring any custom overrides.
vi.mock(import("#app/overrides"), async importOriginal => {
const { defaultOverrides } = await importOriginal();
return {
default: defaultOverrides,
// Export `defaultOverrides` as a *copy*.
// This ensures we can easily reset `overrides` back to its default values after modifying it.
defaultOverrides: { ...defaultOverrides },
} 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(import("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 localeFiles = import.meta.glob("../public/locales/en/**/*.json", { eager: true });
const json = localeFiles[`../public/locales/en/${filename}`] || {};
if (import.meta.env.VITE_I18N_DEBUG === "1") {
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(() => {
initTests();
});
// biome-ignore-start lint/style/noDoneCallback: thinks this is jest done callback
beforeEach(context => {
logTestStart(context.task);
});
afterEach(context => {
logTestEnd(context.task);
});
// biome-ignore-end lint/style/noDoneCallback: thinks this is jest done callback
afterAll(() => {
global.server.close();
MockConsole.printPostTestWarnings();
console.log(chalk.hex("#dfb8d8")("Closing i18n MSW server!"));
});