Server/project/tests/CustomEnvironment.ts

34 lines
894 B
TypeScript
Raw Normal View History

import "reflect-metadata";
2023-10-26 22:01:38 +02:00
import { container } from "tsyringe";
import NodeEnvironment from "jest-environment-node";
2023-10-26 22:01:38 +02:00
import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
import { Container } from "@spt-aki/di/Container";
import { DatabaseImporter } from "@spt-aki/utils/DatabaseImporter";
2023-10-26 22:01:38 +02:00
export default class CustomEnvironment extends NodeEnvironment
{
constructor(config: JestEnvironmentConfig, context: EnvironmentContext)
{
super(config, context);
}
async setup(): Promise<void>
{
await super.setup();
await Container.registerTypes(container);
const databaseImporter = container.resolve<DatabaseImporter>("DatabaseImporter");
await databaseImporter.onLoad();
this.global.container = container;
}
async teardown(): Promise<void>
{
await super.teardown();
}
}