mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-12 17:10:43 -05:00
Includes updates to Vitest dependencies, a small bug fix, and a configuration change. All three of which were throwing warnings when the test suite was ran. ### Dependency Updates: * [`project/package.json`](diffhunk://#diff-18e5b8a4dad7b1ed0da6b50ed507b3ab8116e07a8e44abd959a28261878d021fL69-R70): Updated `@vitest/coverage-istanbul` and `@vitest/ui` to version `^2.1.8` and added `vitest` dependency. [[1]](diffhunk://#diff-18e5b8a4dad7b1ed0da6b50ed507b3ab8116e07a8e44abd959a28261878d021fL69-R70) [[2]](diffhunk://#diff-18e5b8a4dad7b1ed0da6b50ed507b3ab8116e07a8e44abd959a28261878d021fL84-R85) ### Bug Fix: * [`project/src/controllers/RepeatableQuestController.ts`](diffhunk://#diff-92e6bd4234ed3c13309eb9bd27437f0933e58dedee51544e9b017b57c2a3c51cL581-R581): Fixed a bug in the charisma bonus calculation for the `cost.count` value. ### Configuration Changes: * [`project/tests/CustomEnvironment.ts`](diffhunk://#diff-79780538b7a90a5f7befb22838a460f65e3e0bce53d3685f36ed2b74894246a0L9-R9): Updated the import path for `Environment` from `vitest`. * [`project/vitest.config.mts`](diffhunk://#diff-18152746ad4df10b798ca21a09c321bc8ad4adc393ebc6a26016a524203e599cR5-L10): Added `cacheDir` configuration and renamed the file from `vitest.config.ts`.
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import "reflect-metadata";
|
|
|
|
import path from "node:path";
|
|
import { Container } from "@spt/di/Container";
|
|
import { IDatabaseTables } from "@spt/models/spt/server/IDatabaseTables";
|
|
import { DatabaseServer } from "@spt/servers/DatabaseServer";
|
|
import { ImporterUtil } from "@spt/utils/ImporterUtil";
|
|
import { DependencyContainer, Lifecycle, container } from "tsyringe";
|
|
import type { Environment } from "vitest/environments";
|
|
|
|
// Manually mock the logger.
|
|
import { WinstonLogger } from "@tests/__mocks__/WinstonLogger.mock";
|
|
|
|
export default (<Environment>{
|
|
name: "spt-server",
|
|
transformMode: "ssr",
|
|
async setup() {
|
|
// Register all of the dependencies in the container.
|
|
Container.registerTypes(container);
|
|
Container.registerListTypes(container);
|
|
|
|
// Override registration to the container.
|
|
container.register<WinstonLogger>("WinstonLogger", WinstonLogger, { lifecycle: Lifecycle.Singleton });
|
|
|
|
// Import the database.
|
|
await importDatabase(container);
|
|
|
|
return {
|
|
async teardown() { },
|
|
};
|
|
},
|
|
});
|
|
|
|
/**
|
|
* Reads the database JSON files and imports them into memory.
|
|
*
|
|
* @param container The dependency container.
|
|
* @returns A void promise.
|
|
*/
|
|
async function importDatabase(container: DependencyContainer): Promise<void> {
|
|
const importerUtil = container.resolve<ImporterUtil>("ImporterUtil");
|
|
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
|
|
|
// Read the data from the JSON files.
|
|
const databaseDir = path.resolve("./assets/database");
|
|
const dataToImport = await importerUtil.loadAsync<IDatabaseTables>(`${databaseDir}/`);
|
|
|
|
// Save the data to memory.
|
|
databaseServer.setTables(dataToImport);
|
|
}
|