Files
Exiled-Exchange-2/renderer/specs/vitest.setup.ts
Kvan7 e19356e97b v0.8.2 (#480)
* Price checking does not work when using a gamepad(Ctrl+D) #452

Uses parts from #454 to fix the issue.

Co-authored-by: lawrsp <7957003+lawrsp@users.noreply.github.com>

* Fix tests :(

* Fix magic rarity item name parse in "cmn-Hant" language (#460)

* Fix magic rarity item name parse in "cmn-Hant" language

* Add by translated when ref is null

---------

Co-authored-by: kvan7 <kvan.valve@gmail.com>

* chore: yarn to npm and add missing step (#461)

* fix: update game config path for linux to poe2

* fix tests

* fix: MacOS crash on startup (#428)

* fix: MacOS crash on startup

* update for windows/linux

* move main app startup into function
Mac calls that in async, other platforms proceed in sync.

* [PoE2] - Relics broken again #444

* test prettier and add npm script

* add format/lint support to main

* Fix defineProps macro

* Run speed v0.8.0 - Russian. #447

* fix negative gold

* Merge branch 'Kvan7:master' into master

* fix: app-ready fixing before we're ready

* Merge branch 'dev' into pr/larssn/428

* should work?

* Merge commit 'ab1c8bfa3a31b06da9cf18db0273f6a92e407bc5' into pr/larssn/428

* fix being lazy on the merge

* fix: add executable bit to compilation script (#465)

* Item Images (#472)

* image data stuff

* ignore lookup file

* update testing

* sort items

* change sort ot be by refname

* more code

* working pulling

* Fixes #456
Create script to request item's images from trade site #456

* Fixes #457
Update ImageFix to use new saved images before poe1 ones #457

* add images to items

* Add Spear as item category

* Add Flail as category

* Add "goodness" from upstream

* Fix #474
Tier # missing from some defense stats #474

* minor oops

* remove error for waystones

* Add a bunch of images to the docs

* Extra widgets docs

* Update chat commands links docs

* add stash search docs

* Item info docs page

* more docs

* Update bug-report.yml

* Version bump

* extra version bump

---------

Co-authored-by: lawrsp <7957003+lawrsp@users.noreply.github.com>
Co-authored-by: Seth Falco <seth@falco.fun>
Co-authored-by: Amir Zarrinkafsh <nightah@me.com>
Co-authored-by: Lars <890725+larssn@users.noreply.github.com>
2025-03-27 09:50:27 -05:00

120 lines
3.4 KiB
TypeScript

import { vi } from "vitest";
import fs from "fs";
import path from "path";
import { Headers } from "node-fetch"; // Assuming you are using node-fetch
import { Config, TipsFrequency } from "@/web/Config";
vi.mock("@/web/Config", async (original) => {
return {
AppConfig: vi.fn(() => mockConfig),
TipsFrequency: {
Always: 1,
},
};
});
let mockConfig: Config;
// Mock client-string-loader
export const setupClientStringLoaderMock = () => {
vi.mock("@/assets/client-string-loader", () => ({
loadClientStrings: vi.fn(async (lang) => {
const basePath = path.resolve(__dirname, "../public/data/");
const filePath = path.join(basePath, `${lang}/client_strings.js`);
try {
return (await import(/* @vite-ignore */ `${filePath}`)).default;
} catch (error: any) {
throw new Error(
`Error loading client_strings.js for ${lang}: ${error.message}`,
);
}
}),
}));
};
// Mock fetch
export const setupFetchMock = () => {
// @ts-expect-error - fetch is not defined in vitest
global.fetch = vi.fn(async (url) => {
const basePath = path.resolve(__dirname, "../public/");
const filePath = path.join(
basePath,
url.replace(import.meta.env.BASE_URL, ""),
);
const createResponse = (body: any, status = 200) => ({
ok: status >= 200 && status < 300,
status,
statusText: status === 200 ? "OK" : "Not Found",
headers: new Headers(),
redirected: false,
type: "default" as ResponseType,
url: filePath,
clone: () => createResponse(body, status),
body: null,
bodyUsed: false,
json: async () => JSON.parse(body),
text: async () => body,
arrayBuffer: async () => Buffer.from(body).buffer,
blob: async () => new Blob([body]),
formData: async () => {
throw new Error("formData not implemented");
},
});
try {
if (filePath.endsWith(".ndjson")) {
const data = fs.readFileSync(filePath, "utf8");
return createResponse(data, 200);
}
if (filePath.endsWith(".bin")) {
const data = fs.readFileSync(filePath);
return createResponse(data, 200);
}
if (filePath.endsWith(".json")) {
const data = fs.readFileSync(filePath, "utf8");
return createResponse(data, 200);
}
} catch (error) {
return createResponse(`File not found: ${filePath}`, 404);
}
throw new Error(`Unhandled fetch request: ${url}`);
});
};
export const defaultConfigMock = (overrides: Partial<Config> = {}) => {
const defaultConfig: Config = {
configVersion: 99999999,
overlayKey: "default",
overlayBackground: "",
overlayBackgroundClose: false,
restoreClipboard: false,
commands: [],
clientLog: null,
gameConfig: null,
windowTitle: "Test Window",
logKeys: false,
accountName: "TestAccount",
stashScroll: false,
language: "en", // Default language
preferredTradeSite: "default",
realm: "pc-ggg",
widgets: [],
fontSize: 12,
showAttachNotification: true,
overlayAlwaysClose: false,
enableAlphas: false,
alphas: [],
tipsFrequency: TipsFrequency.Always,
};
mockConfig = { ...defaultConfig, ...overrides };
};
// Consolidate setup
export const setupTests = (configOverrides: Partial<Config> = {}) => {
defaultConfigMock(configOverrides); // Pass overrides here
setupClientStringLoaderMock();
setupFetchMock();
};