mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
This is a big one. 🔥
**Changes:**
- Targets next major release (v4.0.0)
- Switch runtimes from NodeJS to BunJS (bun.sh)
- Typescript library support moved to `ESNext`
- Typescript compile option `verbatimModuleSyntax` enabled
- Updated all interfaces to be imported explicitly as types
- Strict mode enabled
- Reduces the number of tsconfig files
- Pins all dep packages to specific patch versions
- Includes Bun lock file in repo (doesn't cause issues like the
package-lock did)
- Replaces Gulp with a new Typescript based build system
- Adds `core-js` as a workaround for Bun not playing nice with
`reflect-metadata`
- Removes `pkg` and `swc` (Yay Bun!)
- Updated package scripts and entry point system to be more intuitive
- Updated VSCode workspace configurations
- Updated `.gitignore` to align with updated project structure
- Updated Biome configuration to align with updated project structure
- `Program.ts` - Removes call to set encoding on the process
- `global.d.ts` - Added underscores to build globals to match other
global names
- `JsonUtil.ts` - Replaced old `fixJson` package with newer `jsonrepair`
package
- `HashUtil.ts` - Replaced old `buffer-crc32` package with built-in
`node:zlib` package
- `DatabaseImporter.ts` - Updates database validation object to be flat,
where the keys are the relative path to the file
- `BunTimer.ts` - Adds an easy to use timer class that's compatible with
nanoseconds.
**TODO:**
- Look into mod loading. I think we use a TS transpiler for mods and I
believe that can be removed now.
- Bun includes a number of APIs that can be used in place of Node's
packages (built-in or otherwise); HTTP server, WebSocket server, File
IO, Hashing, File Globing, Testing... Each of these should be utilized
where ever possible.
- Update in-repo documentation to reference BunJS instead of NodeJS.
145 lines
5.6 KiB
TypeScript
145 lines
5.6 KiB
TypeScript
import "reflect-metadata";
|
|
import type { ItemBaseClassService } from "@spt/services/ItemBaseClassService";
|
|
import { container } from "tsyringe";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
describe("ItemBaseClassService", () => {
|
|
let itemBaseClassService: any;
|
|
|
|
beforeEach(() => {
|
|
itemBaseClassService = container.resolve<ItemBaseClassService>("ItemBaseClassService");
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe("hydrateItemBaseClassCache", () => {
|
|
it("should hydrate itemBaseClassesCache dictionary property", () => {
|
|
itemBaseClassService.cacheGenerated = false;
|
|
itemBaseClassService.itemBaseClassesCache = {};
|
|
itemBaseClassService.hydrateItemBaseClassCache();
|
|
|
|
expect(Object.keys(itemBaseClassService.itemBaseClassesCache).length).greaterThan(100);
|
|
});
|
|
});
|
|
|
|
describe("itemHasBaseClass", () => {
|
|
it("should return false when undefined is passed in", () => {
|
|
const result = itemBaseClassService.itemHasBaseClass(undefined, []);
|
|
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("should return false when the base item type is passed in", () => {
|
|
// Remove item from base cache
|
|
const result = itemBaseClassService.itemHasBaseClass("54009119af1c881c07000029", []);
|
|
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("should return true when a med item is passed in with the meds base class", () => {
|
|
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
|
|
|
// Remove item from base cache
|
|
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];
|
|
const result = itemBaseClassService.itemHasBaseClass(salewaTpl, ["543be5664bdc2dd4348b4569"]);
|
|
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
it("should return true when an item and two matching base classes are passed in", () => {
|
|
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
|
|
|
// Remove item from base cache
|
|
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];
|
|
const result = itemBaseClassService.itemHasBaseClass(salewaTpl, [
|
|
"543be5664bdc2dd4348b4569",
|
|
"54009119af1c881c07000029",
|
|
]); // "Meds" and "Item" base classes
|
|
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
it("should return true when an item is passed in and cache has not been generated", () => {
|
|
// Set cache to false
|
|
itemBaseClassService.cacheGenerated = false;
|
|
|
|
const hydrateItemBaseClassCacheSpy = vi.spyOn(itemBaseClassService, "hydrateItemBaseClassCache");
|
|
|
|
// Remove item from base cache
|
|
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
|
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];
|
|
|
|
// Perform check
|
|
const result = itemBaseClassService.itemHasBaseClass(salewaTpl, ["543be5664bdc2dd4348b4569"]);
|
|
|
|
expect(result).toBe(true);
|
|
expect(hydrateItemBaseClassCacheSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should return false for any item template ID that does not exist", () => {
|
|
const result = itemBaseClassService.itemHasBaseClass("not-a-valid-template-id", [
|
|
"543be5664bdc2dd4348b4569",
|
|
]);
|
|
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("should return false for any item template ID without the Item type ", () => {
|
|
const result = itemBaseClassService.itemHasBaseClass("54009119af1c881c07000029", [
|
|
"543be5664bdc2dd4348b4569",
|
|
]);
|
|
|
|
expect(result).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("getItemBaseClasses", () => {
|
|
it("should return empty array when undefined is passed in", () => {
|
|
const result = itemBaseClassService.getItemBaseClasses(undefined);
|
|
|
|
expect(result).toStrictEqual([]);
|
|
});
|
|
|
|
it("should return empty array when the base item type is passed in", () => {
|
|
// Remove item from base cache
|
|
const result = itemBaseClassService.getItemBaseClasses("54009119af1c881c07000029");
|
|
|
|
expect(result).toStrictEqual([]);
|
|
});
|
|
|
|
it("should return array of 3 items when an item is passed in", () => {
|
|
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
|
|
|
const result = itemBaseClassService.getItemBaseClasses(salewaTpl);
|
|
|
|
expect(result.length).toBe(3);
|
|
});
|
|
|
|
it("should return array of 3 items when an item is passed in and cache has not been generated", () => {
|
|
itemBaseClassService.cacheGenerated = false;
|
|
const hydrateItemBaseClassCacheSpy = vi.spyOn(itemBaseClassService, "hydrateItemBaseClassCache");
|
|
|
|
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
|
const result = itemBaseClassService.getItemBaseClasses(salewaTpl);
|
|
|
|
expect(result.length).toBe(3);
|
|
expect(hydrateItemBaseClassCacheSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should return base item type when an item is passed in", () => {
|
|
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
|
const result = itemBaseClassService.getItemBaseClasses(salewaTpl);
|
|
|
|
expect(result).toContain("54009119af1c881c07000029");
|
|
expect(result).toContain("5448f39d4bdc2d0a728b4568");
|
|
});
|
|
|
|
it("should return empty array when an invalid item is passed in", () => {
|
|
const result = itemBaseClassService.getItemBaseClasses("fakeTpl");
|
|
expect(result).toStrictEqual([]);
|
|
});
|
|
});
|
|
});
|