Migrated from Jest to Vitest
Basically the same, except it plays nicer with Typescript and ESM. I have it mostly working, except for a type error: `TypeError: Int32Array is not a constructor` But I'm too damn tired it debug it at the moment.
This commit is contained in:
parent
00ac9e190a
commit
ad5e0815b6
9
project/.vscode/settings.json
vendored
9
project/.vscode/settings.json
vendored
@ -9,5 +9,12 @@
|
|||||||
"editor.detectIndentation": false,
|
"editor.detectIndentation": false,
|
||||||
"editor.tabSize": 4,
|
"editor.tabSize": 4,
|
||||||
"editor.insertSpaces": true
|
"editor.insertSpaces": true
|
||||||
}
|
},
|
||||||
|
"cSpell.words": [
|
||||||
|
"Baseclass",
|
||||||
|
"IIIA",
|
||||||
|
"medkit",
|
||||||
|
"Superfors",
|
||||||
|
"ULACH"
|
||||||
|
]
|
||||||
}
|
}
|
@ -1,15 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
|
||||||
import type { Config } from "jest";
|
|
||||||
import fs from "fs";
|
|
||||||
|
|
||||||
const config: Config = {
|
|
||||||
testEnvironment: "./tests/CustomEnvironment.ts",
|
|
||||||
roots: [
|
|
||||||
"./tests/"
|
|
||||||
],
|
|
||||||
transform: {
|
|
||||||
"^.+\\.ts$": [ "@swc/jest", JSON.parse(fs.readFileSync(`${__dirname}/.swcrc`, "utf-8")) ]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default config;
|
|
@ -14,8 +14,9 @@
|
|||||||
"check:circular": "madge --circular --extensions ts ./src/",
|
"check:circular": "madge --circular --extensions ts ./src/",
|
||||||
"lint": "rome ci src --formatter-enabled=false --max-diagnostics=200",
|
"lint": "rome ci src --formatter-enabled=false --max-diagnostics=200",
|
||||||
"lint:fix": "eslint --fix --ext .ts src/**",
|
"lint:fix": "eslint --fix --ext .ts src/**",
|
||||||
"test": "jest --colors --runInBand",
|
"test": "vitest run",
|
||||||
"test:coverage": "jest --coverage --maxWorkers=1 --no-cache",
|
"test:watch": "vitest",
|
||||||
|
"test:coverage": "vitest run --coverage",
|
||||||
"build:release": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:release",
|
"build:release": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:release",
|
||||||
"build:debug": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:debug",
|
"build:debug": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:debug",
|
||||||
"build:bleeding": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:bleeding",
|
"build:bleeding": "cross-env PKG_CACHE_PATH=\"./.pkg-cache\" gulp build:bleeding",
|
||||||
@ -44,27 +45,22 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-env": "7.23.2",
|
"@babel/preset-env": "7.23.2",
|
||||||
"@babel/preset-typescript": "7.23.2",
|
"@babel/preset-typescript": "7.23.2",
|
||||||
"@jest/environment": "^29.7.0",
|
|
||||||
"@jest/globals": "29.7.0",
|
|
||||||
"@pnpm/exe": "8.9.0",
|
"@pnpm/exe": "8.9.0",
|
||||||
"@swc/cli": "0.1.62",
|
"@swc/cli": "0.1.62",
|
||||||
"@swc/core": "1.3.92",
|
"@swc/core": "1.3.92",
|
||||||
"@swc/jest": "0.2.29",
|
|
||||||
"@types/i18n": "0.13.7",
|
"@types/i18n": "0.13.7",
|
||||||
"@types/jest": "29.5.5",
|
|
||||||
"@types/node": "18.18.4",
|
"@types/node": "18.18.4",
|
||||||
"@types/proper-lockfile": "4.1.2",
|
"@types/proper-lockfile": "4.1.2",
|
||||||
"@types/semver": "7.5.3",
|
"@types/semver": "7.5.3",
|
||||||
"@types/ws": "8.5.7",
|
"@types/ws": "8.5.7",
|
||||||
"@typescript-eslint/eslint-plugin": "6.7.5",
|
"@typescript-eslint/eslint-plugin": "6.7.5",
|
||||||
"@typescript-eslint/parser": "6.7.5",
|
"@typescript-eslint/parser": "6.7.5",
|
||||||
|
"c8": "^8.0.1",
|
||||||
"cross-env": "7.0.3",
|
"cross-env": "7.0.3",
|
||||||
"eslint": "8.51.0",
|
"eslint": "8.51.0",
|
||||||
"gulp": "4.0.2",
|
"gulp": "4.0.2",
|
||||||
"gulp-execa": "5.0.1",
|
"gulp-execa": "5.0.1",
|
||||||
"gulp-rename": "2.0.0",
|
"gulp-rename": "2.0.0",
|
||||||
"jest": "29.7.0",
|
|
||||||
"jest-environment-node": "^29.7.0",
|
|
||||||
"madge": "6.1.0",
|
"madge": "6.1.0",
|
||||||
"pkg": "5.8.1",
|
"pkg": "5.8.1",
|
||||||
"pkg-fetch": "3.5.2",
|
"pkg-fetch": "3.5.2",
|
||||||
@ -73,7 +69,8 @@
|
|||||||
"ts-node-dev": "2.0.0",
|
"ts-node-dev": "2.0.0",
|
||||||
"tsconfig-paths": "4.2.0",
|
"tsconfig-paths": "4.2.0",
|
||||||
"typedoc": "0.25.2",
|
"typedoc": "0.25.2",
|
||||||
"typemoq": "2.1.0"
|
"typemoq": "2.1.0",
|
||||||
|
"vitest": "1.0.0-beta.3"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"pkg": {
|
"pkg": {
|
||||||
|
@ -248,71 +248,64 @@ import { Watermark, WatermarkLocale } from "@spt-aki/utils/Watermark";
|
|||||||
import { WinstonMainLogger } from "@spt-aki/utils/logging/WinstonMainLogger";
|
import { WinstonMainLogger } from "@spt-aki/utils/logging/WinstonMainLogger";
|
||||||
import { WinstonRequestLogger } from "@spt-aki/utils/logging/WinstonRequestLogger";
|
import { WinstonRequestLogger } from "@spt-aki/utils/logging/WinstonRequestLogger";
|
||||||
|
|
||||||
// For the Jest Custom Environment.
|
// For the Vitest Custom Environment.
|
||||||
import NodeEnvironment from "jest-environment-node";
|
import type { Environment } from "vitest";
|
||||||
import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
|
import { populateGlobal } from "vitest/environments";
|
||||||
|
|
||||||
// Used for importing the database.
|
// Used for importing the database.
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { IDatabaseTables } from "@spt-aki/models/spt/server/IDatabaseTables";
|
import { IDatabaseTables } from "@spt-aki/models/spt/server/IDatabaseTables";
|
||||||
|
|
||||||
export default class CustomEnvironment extends NodeEnvironment
|
export default <Environment> {
|
||||||
{
|
name: "spt-aki-server",
|
||||||
private container: DependencyContainer;
|
transformMode: "ssr",
|
||||||
|
async setup()
|
||||||
// For importing the database.
|
|
||||||
private importerUtil: ImporterUtil;
|
|
||||||
private databaseServer: DatabaseServer;
|
|
||||||
|
|
||||||
constructor(config: JestEnvironmentConfig, context: EnvironmentContext)
|
|
||||||
{
|
{
|
||||||
super(config, context);
|
// Register all of the things!
|
||||||
|
register(container);
|
||||||
this.container = this.register(container);
|
|
||||||
}
|
|
||||||
|
|
||||||
async setup(): Promise<void>
|
|
||||||
{
|
|
||||||
await super.setup();
|
|
||||||
|
|
||||||
// Import the database.
|
// Import the database.
|
||||||
await this.importDatabase();
|
await importDatabase(container);
|
||||||
|
|
||||||
// Make the container accessible to the tests.
|
// Populate the global scope with all of the things!
|
||||||
this.global.container = this.container;
|
populateGlobal(global, { container }, { bindFunctions: true });
|
||||||
|
|
||||||
// TODO: Create test account/profile
|
// TODO: Create test account/profile
|
||||||
}
|
|
||||||
|
|
||||||
async teardown(): Promise<void>
|
return {
|
||||||
|
teardown()
|
||||||
{
|
{
|
||||||
|
// Not sure this is required, but it's here just in case.
|
||||||
|
delete global.container;
|
||||||
|
|
||||||
// TODO: Delete test account/profile
|
// TODO: Delete test account/profile
|
||||||
|
|
||||||
await super.teardown();
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Register all of the things!
|
// Register all of the things!
|
||||||
private register(container: DependencyContainer): DependencyContainer
|
function register(container: DependencyContainer): DependencyContainer
|
||||||
{
|
{
|
||||||
container.register("ApplicationContext", ApplicationContext, { lifecycle: Lifecycle.Singleton });
|
container.register("ApplicationContext", ApplicationContext, { lifecycle: Lifecycle.Singleton });
|
||||||
|
|
||||||
this.registerUtils(container);
|
registerUtils(container);
|
||||||
this.registerRouters(container);
|
registerRouters(container);
|
||||||
this.registerGenerators(container);
|
registerGenerators(container);
|
||||||
this.registerHelpers(container);
|
registerHelpers(container);
|
||||||
this.registerLoaders(container);
|
registerLoaders(container);
|
||||||
this.registerCallbacks(container);
|
registerCallbacks(container);
|
||||||
this.registerServers(container);
|
registerServers(container);
|
||||||
this.registerServices(container);
|
registerServices(container);
|
||||||
this.registerControllers(container);
|
registerControllers(container);
|
||||||
|
|
||||||
this.registerListTypes(container);
|
registerListTypes(container);
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerUtils(container: DependencyContainer): void
|
function registerUtils(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
// Utils
|
// Utils
|
||||||
container.register<App>("App", App, { lifecycle: Lifecycle.Singleton });
|
container.register<App>("App", App, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<DatabaseImporter>("DatabaseImporter", DatabaseImporter, { lifecycle: Lifecycle.Singleton });
|
container.register<DatabaseImporter>("DatabaseImporter", DatabaseImporter, { lifecycle: Lifecycle.Singleton });
|
||||||
@ -328,17 +321,20 @@ export default class CustomEnvironment extends NodeEnvironment
|
|||||||
container.register<RandomUtil>("RandomUtil", RandomUtil, { lifecycle: Lifecycle.Singleton });
|
container.register<RandomUtil>("RandomUtil", RandomUtil, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<TimeUtil>("TimeUtil", TimeUtil, { lifecycle: Lifecycle.Singleton });
|
container.register<TimeUtil>("TimeUtil", TimeUtil, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<VFS>("VFS", VFS, { lifecycle: Lifecycle.Singleton });
|
container.register<VFS>("VFS", VFS, { lifecycle: Lifecycle.Singleton });
|
||||||
|
|
||||||
|
// These two trouble-makers are manually mocked, as the original implementation hijacks our test console.
|
||||||
container.register<WatermarkLocale>("WatermarkLocale", WatermarkLocale, { lifecycle: Lifecycle.Singleton });
|
container.register<WatermarkLocale>("WatermarkLocale", WatermarkLocale, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<Watermark>("Watermark", Watermark, { lifecycle: Lifecycle.Singleton });
|
container.register<Watermark>("Watermark", Watermark, { lifecycle: Lifecycle.Singleton });
|
||||||
|
|
||||||
container.register<IAsyncQueue>("AsyncQueue", AsyncQueue, { lifecycle: Lifecycle.Singleton });
|
container.register<IAsyncQueue>("AsyncQueue", AsyncQueue, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<IUUidGenerator>("UUidGenerator", UUidGenerator, { lifecycle: Lifecycle.Singleton });
|
container.register<IUUidGenerator>("UUidGenerator", UUidGenerator, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<HttpFileUtil>("HttpFileUtil", HttpFileUtil, { lifecycle: Lifecycle.Singleton });
|
container.register<HttpFileUtil>("HttpFileUtil", HttpFileUtil, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<ModLoadOrder>("ModLoadOrder", ModLoadOrder, { lifecycle: Lifecycle.Singleton });
|
container.register<ModLoadOrder>("ModLoadOrder", ModLoadOrder, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<ModTypeCheck>("ModTypeCheck", ModTypeCheck, { lifecycle: Lifecycle.Singleton });
|
container.register<ModTypeCheck>("ModTypeCheck", ModTypeCheck, { lifecycle: Lifecycle.Singleton });
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerRouters(container: DependencyContainer): void
|
function registerRouters(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
// Routers
|
// Routers
|
||||||
container.register<HttpRouter>("HttpRouter", HttpRouter, { lifecycle: Lifecycle.Singleton });
|
container.register<HttpRouter>("HttpRouter", HttpRouter, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<ImageRouter>("ImageRouter", ImageRouter);
|
container.register<ImageRouter>("ImageRouter", ImageRouter);
|
||||||
@ -403,10 +399,10 @@ export default class CustomEnvironment extends NodeEnvironment
|
|||||||
container.register<RagfairStaticRouter>("RagfairStaticRouter", { useClass: RagfairStaticRouter });
|
container.register<RagfairStaticRouter>("RagfairStaticRouter", { useClass: RagfairStaticRouter });
|
||||||
container.register<TraderStaticRouter>("TraderStaticRouter", { useClass: TraderStaticRouter });
|
container.register<TraderStaticRouter>("TraderStaticRouter", { useClass: TraderStaticRouter });
|
||||||
container.register<WeatherStaticRouter>("WeatherStaticRouter", { useClass: WeatherStaticRouter });
|
container.register<WeatherStaticRouter>("WeatherStaticRouter", { useClass: WeatherStaticRouter });
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerGenerators(container: DependencyContainer): void
|
function registerGenerators(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
// Generators
|
// Generators
|
||||||
container.register<BotGenerator>("BotGenerator", BotGenerator);
|
container.register<BotGenerator>("BotGenerator", BotGenerator);
|
||||||
container.register<BotWeaponGenerator>("BotWeaponGenerator", BotWeaponGenerator);
|
container.register<BotWeaponGenerator>("BotWeaponGenerator", BotWeaponGenerator);
|
||||||
@ -433,10 +429,10 @@ export default class CustomEnvironment extends NodeEnvironment
|
|||||||
container.registerType("InventoryMagGen", "ExternalInventoryMagGen");
|
container.registerType("InventoryMagGen", "ExternalInventoryMagGen");
|
||||||
container.registerType("InventoryMagGen", "InternalMagazineInventoryMagGen");
|
container.registerType("InventoryMagGen", "InternalMagazineInventoryMagGen");
|
||||||
container.registerType("InventoryMagGen", "UbglExternalMagGen");
|
container.registerType("InventoryMagGen", "UbglExternalMagGen");
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerHelpers(container: DependencyContainer): void
|
function registerHelpers(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
// Helpers
|
// Helpers
|
||||||
container.register<AssortHelper>("AssortHelper", { useClass: AssortHelper });
|
container.register<AssortHelper>("AssortHelper", { useClass: AssortHelper });
|
||||||
container.register<BotHelper>("BotHelper", { useClass: BotHelper });
|
container.register<BotHelper>("BotHelper", { useClass: BotHelper });
|
||||||
@ -475,18 +471,18 @@ export default class CustomEnvironment extends NodeEnvironment
|
|||||||
container.register<BotWeaponGeneratorHelper>("BotWeaponGeneratorHelper", { useClass: BotWeaponGeneratorHelper });
|
container.register<BotWeaponGeneratorHelper>("BotWeaponGeneratorHelper", { useClass: BotWeaponGeneratorHelper });
|
||||||
container.register<BotDifficultyHelper>("BotDifficultyHelper", { useClass: BotDifficultyHelper });
|
container.register<BotDifficultyHelper>("BotDifficultyHelper", { useClass: BotDifficultyHelper });
|
||||||
container.register<RepeatableQuestHelper>("RepeatableQuestHelper", { useClass: RepeatableQuestHelper });
|
container.register<RepeatableQuestHelper>("RepeatableQuestHelper", { useClass: RepeatableQuestHelper });
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerLoaders(container: DependencyContainer): void
|
function registerLoaders(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
// Loaders
|
// Loaders
|
||||||
container.register<BundleLoader>("BundleLoader", BundleLoader, { lifecycle: Lifecycle.Singleton });
|
container.register<BundleLoader>("BundleLoader", BundleLoader, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<PreAkiModLoader>("PreAkiModLoader", PreAkiModLoader, { lifecycle: Lifecycle.Singleton });
|
container.register<PreAkiModLoader>("PreAkiModLoader", PreAkiModLoader, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<PostAkiModLoader>("PostAkiModLoader", PostAkiModLoader, { lifecycle: Lifecycle.Singleton });
|
container.register<PostAkiModLoader>("PostAkiModLoader", PostAkiModLoader, { lifecycle: Lifecycle.Singleton });
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerCallbacks(container: DependencyContainer): void
|
function registerCallbacks(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
// Callbacks
|
// Callbacks
|
||||||
container.register<BotCallbacks>("BotCallbacks", { useClass: BotCallbacks });
|
container.register<BotCallbacks>("BotCallbacks", { useClass: BotCallbacks });
|
||||||
container.register<BundleCallbacks>("BundleCallbacks", { useClass: BundleCallbacks });
|
container.register<BundleCallbacks>("BundleCallbacks", { useClass: BundleCallbacks });
|
||||||
@ -521,10 +517,10 @@ export default class CustomEnvironment extends NodeEnvironment
|
|||||||
container.register<TraderCallbacks>("TraderCallbacks", { useClass: TraderCallbacks });
|
container.register<TraderCallbacks>("TraderCallbacks", { useClass: TraderCallbacks });
|
||||||
container.register<WeatherCallbacks>("WeatherCallbacks", { useClass: WeatherCallbacks });
|
container.register<WeatherCallbacks>("WeatherCallbacks", { useClass: WeatherCallbacks });
|
||||||
container.register<WishlistCallbacks>("WishlistCallbacks", { useClass: WishlistCallbacks });
|
container.register<WishlistCallbacks>("WishlistCallbacks", { useClass: WishlistCallbacks });
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerServices(container: DependencyContainer): void
|
function registerServices(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
// Services
|
// Services
|
||||||
container.register<ImageRouteService>("ImageRouteService", ImageRouteService, { lifecycle: Lifecycle.Singleton });
|
container.register<ImageRouteService>("ImageRouteService", ImageRouteService, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<FenceService>("FenceService", FenceService, { lifecycle: Lifecycle.Singleton });
|
container.register<FenceService>("FenceService", FenceService, { lifecycle: Lifecycle.Singleton });
|
||||||
@ -563,10 +559,10 @@ export default class CustomEnvironment extends NodeEnvironment
|
|||||||
container.register<PmcChatResponseService>("PmcChatResponseService", PmcChatResponseService);
|
container.register<PmcChatResponseService>("PmcChatResponseService", PmcChatResponseService);
|
||||||
container.register<GiftService>("GiftService", GiftService);
|
container.register<GiftService>("GiftService", GiftService);
|
||||||
container.register<MailSendService>("MailSendService", MailSendService);
|
container.register<MailSendService>("MailSendService", MailSendService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerServers(container: DependencyContainer): void
|
function registerServers(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
// Servers
|
// Servers
|
||||||
container.register<DatabaseServer>("DatabaseServer", DatabaseServer, { lifecycle: Lifecycle.Singleton });
|
container.register<DatabaseServer>("DatabaseServer", DatabaseServer, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<HttpServer>("HttpServer", HttpServer, { lifecycle: Lifecycle.Singleton });
|
container.register<HttpServer>("HttpServer", HttpServer, { lifecycle: Lifecycle.Singleton });
|
||||||
@ -575,10 +571,10 @@ export default class CustomEnvironment extends NodeEnvironment
|
|||||||
container.register<SaveServer>("SaveServer", SaveServer, { lifecycle: Lifecycle.Singleton });
|
container.register<SaveServer>("SaveServer", SaveServer, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<ConfigServer>("ConfigServer", ConfigServer, { lifecycle: Lifecycle.Singleton });
|
container.register<ConfigServer>("ConfigServer", ConfigServer, { lifecycle: Lifecycle.Singleton });
|
||||||
container.register<HttpBufferHandler>("HttpBufferHandler", HttpBufferHandler, {lifecycle: Lifecycle.Singleton});
|
container.register<HttpBufferHandler>("HttpBufferHandler", HttpBufferHandler, {lifecycle: Lifecycle.Singleton});
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerControllers(container: DependencyContainer): void
|
function registerControllers(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
// Controllers
|
// Controllers
|
||||||
container.register<BotController>("BotController", { useClass: BotController });
|
container.register<BotController>("BotController", { useClass: BotController });
|
||||||
container.register<ClientLogController>("ClientLogController", { useClass: ClientLogController });
|
container.register<ClientLogController>("ClientLogController", { useClass: ClientLogController });
|
||||||
@ -607,10 +603,10 @@ export default class CustomEnvironment extends NodeEnvironment
|
|||||||
container.register<TraderController>("TraderController", { useClass: TraderController });
|
container.register<TraderController>("TraderController", { useClass: TraderController });
|
||||||
container.register<WeatherController>("WeatherController", { useClass: WeatherController });
|
container.register<WeatherController>("WeatherController", { useClass: WeatherController });
|
||||||
container.register<WishlistController>("WishlistController", WishlistController);
|
container.register<WishlistController>("WishlistController", WishlistController);
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerListTypes(container: DependencyContainer): void
|
function registerListTypes(container: DependencyContainer): void
|
||||||
{
|
{
|
||||||
container.register("OnLoadModService", { useValue: new OnLoadModService(container) });
|
container.register("OnLoadModService", { useValue: new OnLoadModService(container) });
|
||||||
container.register("HttpListenerModService", { useValue: new HttpListenerModService(container) });
|
container.register("HttpListenerModService", { useValue: new HttpListenerModService(container) });
|
||||||
container.register("OnUpdateModService", { useValue: new OnUpdateModService(container) });
|
container.register("OnUpdateModService", { useValue: new OnUpdateModService(container) });
|
||||||
@ -685,23 +681,21 @@ export default class CustomEnvironment extends NodeEnvironment
|
|||||||
container.registerType("Serializer", "BundleSerializer");
|
container.registerType("Serializer", "BundleSerializer");
|
||||||
container.registerType("Serializer", "NotifySerializer");
|
container.registerType("Serializer", "NotifySerializer");
|
||||||
|
|
||||||
// Registering these starts the server...?
|
|
||||||
container.registerType("SaveLoadRouter", "HealthSaveLoadRouter");
|
container.registerType("SaveLoadRouter", "HealthSaveLoadRouter");
|
||||||
container.registerType("SaveLoadRouter", "InraidSaveLoadRouter");
|
container.registerType("SaveLoadRouter", "InraidSaveLoadRouter");
|
||||||
container.registerType("SaveLoadRouter", "InsuranceSaveLoadRouter");
|
container.registerType("SaveLoadRouter", "InsuranceSaveLoadRouter");
|
||||||
container.registerType("SaveLoadRouter", "ProfileSaveLoadRouter");
|
container.registerType("SaveLoadRouter", "ProfileSaveLoadRouter");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async importDatabase(): Promise<void>
|
async function importDatabase(container: DependencyContainer): Promise<void>
|
||||||
{
|
{
|
||||||
this.importerUtil = this.container.resolve<ImporterUtil>("ImporterUtil");
|
const importerUtil = container.resolve<ImporterUtil>("ImporterUtil");
|
||||||
this.databaseServer = this.container.resolve<DatabaseServer>("DatabaseServer");
|
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
||||||
|
|
||||||
// Read the data from the JSON files.
|
// Read the data from the JSON files.
|
||||||
const databaseDir = path.resolve("./assets/database");
|
const databaseDir = path.resolve("./assets/database");
|
||||||
const dataToImport = await this.importerUtil.loadAsync<IDatabaseTables>(`${databaseDir}/`);
|
const dataToImport = await importerUtil.loadAsync<IDatabaseTables>(`${databaseDir}/`);
|
||||||
|
|
||||||
// Save the data to memory.
|
// Save the data to memory.
|
||||||
this.databaseServer.setTables(dataToImport);
|
databaseServer.setTables(dataToImport);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
|
|
||||||
|
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
||||||
import { DependencyContainer } from "tsyringe";
|
import { DependencyContainer } from "tsyringe";
|
||||||
import { Item, Repairable } from "@spt-aki/models/eft/common/tables/IItem";
|
import { Item, Repairable } from "@spt-aki/models/eft/common/tables/IItem";
|
||||||
@ -11,22 +13,15 @@ describe("ItemHelper", () =>
|
|||||||
let container: DependencyContainer;
|
let container: DependencyContainer;
|
||||||
let itemHelper: ItemHelper;
|
let itemHelper: ItemHelper;
|
||||||
|
|
||||||
// Spies
|
|
||||||
let handbookHelperGetTemplatePriceSpy: jest.SpyInstance;
|
|
||||||
let loggerWarningSpy: jest.SpyInstance;
|
|
||||||
let loggerErrorSpy: jest.SpyInstance;
|
|
||||||
let databaseServerGetTablesSpy: jest.SpyInstance;
|
|
||||||
let jsonUtilCloneSpy: jest.SpyInstance;
|
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeAll(() =>
|
||||||
{
|
{
|
||||||
container = globalThis.container;
|
container = global.container;
|
||||||
itemHelper = container.resolve<ItemHelper>("ItemHelper");
|
itemHelper = container.resolve<ItemHelper>("ItemHelper");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() =>
|
afterEach(() =>
|
||||||
{
|
{
|
||||||
jest.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("isValidItem", () =>
|
describe("isValidItem", () =>
|
||||||
@ -52,7 +47,7 @@ describe("ItemHelper", () =>
|
|||||||
it("should return false when item's price is zero", () =>
|
it("should return false when item's price is zero", () =>
|
||||||
{
|
{
|
||||||
// Unsure if any item has price of "0", so mock the getItemPrice method to return 0.
|
// Unsure if any item has price of "0", so mock the getItemPrice method to return 0.
|
||||||
jest.spyOn(itemHelper, "getItemPrice").mockReturnValue(0);
|
vi.spyOn(itemHelper, "getItemPrice").mockReturnValue(0);
|
||||||
|
|
||||||
const result = itemHelper.isValidItem("5fc64ea372b0dd78d51159dc");
|
const result = itemHelper.isValidItem("5fc64ea372b0dd78d51159dc");
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(false);
|
||||||
@ -112,7 +107,7 @@ describe("ItemHelper", () =>
|
|||||||
const staticPrice = 1;
|
const staticPrice = 1;
|
||||||
const tpl = "590c657e86f77412b013051d";
|
const tpl = "590c657e86f77412b013051d";
|
||||||
|
|
||||||
jest.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(staticPrice);
|
vi.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(staticPrice);
|
||||||
|
|
||||||
const result = itemHelper.getItemPrice(tpl);
|
const result = itemHelper.getItemPrice(tpl);
|
||||||
|
|
||||||
@ -125,8 +120,8 @@ describe("ItemHelper", () =>
|
|||||||
const dynamicPrice = 42069;
|
const dynamicPrice = 42069;
|
||||||
const tpl = "590c657e86f77412b013051d";
|
const tpl = "590c657e86f77412b013051d";
|
||||||
|
|
||||||
jest.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(staticPrice);
|
vi.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(staticPrice);
|
||||||
jest.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(dynamicPrice);
|
vi.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(dynamicPrice);
|
||||||
|
|
||||||
const result = itemHelper.getItemPrice(tpl);
|
const result = itemHelper.getItemPrice(tpl);
|
||||||
|
|
||||||
@ -138,8 +133,8 @@ describe("ItemHelper", () =>
|
|||||||
{
|
{
|
||||||
const tpl = "590c657e86f77412b013051d";
|
const tpl = "590c657e86f77412b013051d";
|
||||||
|
|
||||||
jest.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(0);
|
vi.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(0);
|
||||||
jest.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(0);
|
vi.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(0);
|
||||||
|
|
||||||
const result = itemHelper.getItemPrice(tpl);
|
const result = itemHelper.getItemPrice(tpl);
|
||||||
|
|
||||||
@ -156,8 +151,8 @@ describe("ItemHelper", () =>
|
|||||||
const dynamicPrice = 69;
|
const dynamicPrice = 69;
|
||||||
const tpl = "590c657e86f77412b013051d";
|
const tpl = "590c657e86f77412b013051d";
|
||||||
|
|
||||||
jest.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(staticPrice);
|
vi.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(staticPrice);
|
||||||
jest.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(dynamicPrice);
|
vi.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(dynamicPrice);
|
||||||
|
|
||||||
const result = itemHelper.getItemMaxPrice(tpl);
|
const result = itemHelper.getItemMaxPrice(tpl);
|
||||||
|
|
||||||
@ -170,8 +165,8 @@ describe("ItemHelper", () =>
|
|||||||
const dynamicPrice = 420;
|
const dynamicPrice = 420;
|
||||||
const tpl = "590c657e86f77412b013051d";
|
const tpl = "590c657e86f77412b013051d";
|
||||||
|
|
||||||
jest.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(staticPrice);
|
vi.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(staticPrice);
|
||||||
jest.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(dynamicPrice);
|
vi.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(dynamicPrice);
|
||||||
|
|
||||||
const result = itemHelper.getItemMaxPrice(tpl);
|
const result = itemHelper.getItemMaxPrice(tpl);
|
||||||
|
|
||||||
@ -183,8 +178,8 @@ describe("ItemHelper", () =>
|
|||||||
const price = 42069;
|
const price = 42069;
|
||||||
const tpl = "590c657e86f77412b013051d";
|
const tpl = "590c657e86f77412b013051d";
|
||||||
|
|
||||||
jest.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(price);
|
vi.spyOn(itemHelper, "getStaticItemPrice").mockReturnValue(price);
|
||||||
jest.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(price);
|
vi.spyOn(itemHelper, "getDynamicItemPrice").mockReturnValue(price);
|
||||||
|
|
||||||
const result = itemHelper.getItemMaxPrice(tpl);
|
const result = itemHelper.getItemMaxPrice(tpl);
|
||||||
|
|
||||||
@ -209,7 +204,7 @@ describe("ItemHelper", () =>
|
|||||||
const price = 42069;
|
const price = 42069;
|
||||||
const tpl = "590c657e86f77412b013051d";
|
const tpl = "590c657e86f77412b013051d";
|
||||||
|
|
||||||
handbookHelperGetTemplatePriceSpy = jest.spyOn((itemHelper as any).handbookHelper, "getTemplatePrice");
|
const handbookHelperGetTemplatePriceSpy = vi.spyOn((itemHelper as any).handbookHelper, "getTemplatePrice");
|
||||||
handbookHelperGetTemplatePriceSpy.mockReturnValue(price);
|
handbookHelperGetTemplatePriceSpy.mockReturnValue(price);
|
||||||
|
|
||||||
const result = itemHelper.getStaticItemPrice(tpl);
|
const result = itemHelper.getStaticItemPrice(tpl);
|
||||||
@ -222,7 +217,7 @@ describe("ItemHelper", () =>
|
|||||||
const price = 0;
|
const price = 0;
|
||||||
const tpl = "590c657e86f77412b013051d"; // "Grizzly medical kit"
|
const tpl = "590c657e86f77412b013051d"; // "Grizzly medical kit"
|
||||||
|
|
||||||
handbookHelperGetTemplatePriceSpy = jest.spyOn((itemHelper as any).handbookHelper, "getTemplatePrice");
|
const handbookHelperGetTemplatePriceSpy = vi.spyOn((itemHelper as any).handbookHelper, "getTemplatePrice");
|
||||||
handbookHelperGetTemplatePriceSpy.mockReturnValue(price);
|
handbookHelperGetTemplatePriceSpy.mockReturnValue(price);
|
||||||
|
|
||||||
const result = itemHelper.getStaticItemPrice(tpl);
|
const result = itemHelper.getStaticItemPrice(tpl);
|
||||||
@ -320,7 +315,7 @@ describe("ItemHelper", () =>
|
|||||||
|
|
||||||
const parentId = container.resolve<HashUtil>("HashUtil").generate();
|
const parentId = container.resolve<HashUtil>("HashUtil").generate();
|
||||||
|
|
||||||
loggerWarningSpy = jest.spyOn((itemHelper as any).logger, "warning");
|
const loggerWarningSpy = vi.spyOn((itemHelper as any).logger, "warning");
|
||||||
|
|
||||||
itemHelper.generateItemsFromStackSlot(ammoBox[1], parentId);
|
itemHelper.generateItemsFromStackSlot(ammoBox[1], parentId);
|
||||||
|
|
||||||
@ -332,8 +327,8 @@ describe("ItemHelper", () =>
|
|||||||
{
|
{
|
||||||
it("should call databaseServer.getTables() and jsonUtil.clone() methods", () =>
|
it("should call databaseServer.getTables() and jsonUtil.clone() methods", () =>
|
||||||
{
|
{
|
||||||
databaseServerGetTablesSpy = jest.spyOn((itemHelper as any).databaseServer, "getTables");
|
const databaseServerGetTablesSpy = vi.spyOn((itemHelper as any).databaseServer, "getTables");
|
||||||
jsonUtilCloneSpy = jest.spyOn((itemHelper as any).jsonUtil, "clone");
|
const jsonUtilCloneSpy = vi.spyOn((itemHelper as any).jsonUtil, "clone");
|
||||||
|
|
||||||
itemHelper.getItems();
|
itemHelper.getItems();
|
||||||
|
|
||||||
@ -404,7 +399,7 @@ describe("ItemHelper", () =>
|
|||||||
|
|
||||||
it("should call getItem with the provided tpl", () =>
|
it("should call getItem with the provided tpl", () =>
|
||||||
{
|
{
|
||||||
const itemHelperSpy = jest.spyOn(itemHelper, "getItem");
|
const itemHelperSpy = vi.spyOn(itemHelper, "getItem");
|
||||||
|
|
||||||
const tpl = "590c657e86f77412b013051d"; // "Grizzly medical kit"
|
const tpl = "590c657e86f77412b013051d"; // "Grizzly medical kit"
|
||||||
|
|
||||||
@ -717,7 +712,7 @@ describe("ItemHelper", () =>
|
|||||||
_tpl: ""
|
_tpl: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
loggerErrorSpy = jest.spyOn((itemHelper as any).logger, "error");
|
const loggerErrorSpy = vi.spyOn((itemHelper as any).logger, "error");
|
||||||
|
|
||||||
// Cast the method to any to allow access to private/protected method.
|
// Cast the method to any to allow access to private/protected method.
|
||||||
(itemHelper as any).getRepairableItemQualityValue(weapon, repairable, item);
|
(itemHelper as any).getRepairableItemQualityValue(weapon, repairable, item);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { DependencyContainer } from "tsyringe";
|
|
||||||
|
|
||||||
|
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { DependencyContainer } from "tsyringe";
|
||||||
import { PaymentService } from "@spt-aki/services/PaymentService";
|
import { PaymentService } from "@spt-aki/services/PaymentService";
|
||||||
|
|
||||||
describe("PaymentService", () =>
|
describe("PaymentService", () =>
|
||||||
@ -10,13 +12,13 @@ describe("PaymentService", () =>
|
|||||||
|
|
||||||
beforeAll(() =>
|
beforeAll(() =>
|
||||||
{
|
{
|
||||||
container = globalThis.container;
|
container = global.container;
|
||||||
paymentService = container.resolve<PaymentService>("PaymentService");
|
paymentService = container.resolve<PaymentService>("PaymentService");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() =>
|
afterEach(() =>
|
||||||
{
|
{
|
||||||
jest.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("should be registered", () =>
|
describe("should be registered", () =>
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"@spt-aki/*": [
|
"@spt-aki/*": [
|
||||||
"src/*"
|
"src/*"
|
||||||
|
],
|
||||||
|
"@tests/*": [
|
||||||
|
"tests/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
"outDir": "obj",
|
"outDir": "obj",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"noImplicitAny": false
|
"noImplicitAny": false,
|
||||||
|
"types": ["vitest/globals"],
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./types/**/*",
|
"./types/**/*",
|
||||||
|
16
project/vitest.config.ts
Normal file
16
project/vitest.config.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
|
import path from "path";
|
||||||
|
import { defineConfig } from "vitest/config";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
name: "spt-server",
|
||||||
|
root: "./tests",
|
||||||
|
environment: "./CustomEnvironment.ts",
|
||||||
|
globals: true,
|
||||||
|
alias: {
|
||||||
|
"@spt-aki": path.resolve(__dirname, "src"),
|
||||||
|
"@tests": path.resolve(__dirname, "tests")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user