Override WinstonLogger registration with a mock

This commit is contained in:
TheSparta 2023-11-02 15:58:16 +00:00
parent 946552199e
commit e327df7504
3 changed files with 39 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import "reflect-metadata";
import { container, DependencyContainer } from "tsyringe";
import { container, DependencyContainer, Lifecycle } from "tsyringe";
// For the Vitest Custom Environment.
import type { Environment } from "vitest";
@ -11,6 +11,9 @@ import { IDatabaseTables } from "@spt-aki/models/spt/server/IDatabaseTables";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
import { ImporterUtil } from "@spt-aki/utils/ImporterUtil";
//mocks
import { WinstonLogger } from "@tests/__mocks__/WinstonLogger.mock";
export default <Environment> {
name: "spt-aki-server",
transformMode: "ssr",
@ -20,6 +23,9 @@ export default <Environment> {
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);

View File

@ -0,0 +1,31 @@
import { Daum } from "@spt-aki/models/eft/itemEvent/IItemEventRouterRequest";
import { LogBackgroundColor } from "@spt-aki/models/spt/logging/LogBackgroundColor";
import { LogTextColor } from "@spt-aki/models/spt/logging/LogTextColor";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
export class WinstonLogger implements ILogger
{
writeToLogFile(data: string | Daum): void
{ }
log(data: string | Record<string, unknown> | Error, color: string, backgroundColor?: string): void
{ }
logWithColor(data: string | Record<string, unknown>, textColor: LogTextColor, backgroundColor?: LogBackgroundColor): void
{ }
error(data: string): void
{ }
warning(data: string): void
{ }
success(data: string): void
{ }
info(data: string): void
{ }
debug(data: string| Record<string, unknown>, onlyShowInConsole?: boolean): void
{ }
}

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import path from "path";
import path from "node:path";
import { defineConfig } from "vitest/config";
export default defineConfig({