2023-10-26 20:12:19 +02:00
|
|
|
import "reflect-metadata";
|
2023-10-28 21:39:17 +02:00
|
|
|
import { container, DependencyContainer } from "tsyringe";
|
|
|
|
import path from "node:path";
|
2023-10-27 23:48:24 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
// For the Vitest Custom Environment.
|
|
|
|
import type { Environment } from "vitest";
|
2023-10-26 20:12:19 +02:00
|
|
|
|
2023-10-28 21:39:17 +02:00
|
|
|
// Import everything we intend to test so we can register it in the Jest custom environment.
|
|
|
|
import { Container } from "@spt-aki/di/Container";
|
2023-10-27 23:48:24 +02:00
|
|
|
import { IDatabaseTables } from "@spt-aki/models/spt/server/IDatabaseTables";
|
2023-10-28 21:39:17 +02:00
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { ImporterUtil } from "@spt-aki/utils/ImporterUtil";
|
2023-10-26 20:12:19 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
export default <Environment> {
|
|
|
|
name: "spt-aki-server",
|
|
|
|
transformMode: "ssr",
|
|
|
|
async setup()
|
2023-10-26 20:12:19 +02:00
|
|
|
{
|
2023-10-28 21:39:17 +02:00
|
|
|
Container.registerTypes(container);
|
|
|
|
Container.registerListTypes(container);
|
2023-10-26 20:12:19 +02:00
|
|
|
|
2023-10-27 23:48:24 +02:00
|
|
|
// Import the database.
|
2023-10-28 05:55:34 +02:00
|
|
|
await importDatabase(container);
|
2023-10-26 23:19:16 +02:00
|
|
|
|
2023-10-27 23:48:24 +02:00
|
|
|
// TODO: Create test account/profile
|
2023-10-26 20:12:19 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
return {
|
|
|
|
teardown()
|
|
|
|
{
|
|
|
|
// TODO: Delete test account/profile
|
|
|
|
}
|
|
|
|
};
|
2023-10-26 20:12:19 +02:00
|
|
|
}
|
2023-10-28 05:55:34 +02:00
|
|
|
};
|
2023-10-27 23:48:24 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
async function importDatabase(container: DependencyContainer): Promise<void>
|
|
|
|
{
|
|
|
|
const importerUtil = container.resolve<ImporterUtil>("ImporterUtil");
|
|
|
|
const databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
2023-10-27 23:48:24 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
// Read the data from the JSON files.
|
|
|
|
const databaseDir = path.resolve("./assets/database");
|
|
|
|
const dataToImport = await importerUtil.loadAsync<IDatabaseTables>(`${databaseDir}/`);
|
2023-10-27 23:48:24 +02:00
|
|
|
|
2023-10-28 05:55:34 +02:00
|
|
|
// Save the data to memory.
|
|
|
|
databaseServer.setTables(dataToImport);
|
2023-10-26 20:12:19 +02:00
|
|
|
}
|