import 'reflect-metadata'; import { ContainerModule, interfaces, Container } from 'inversify'; import { Feature } from '@common-stack/server-core'; import { TaggedType } from '@common-stack/core'; import FilesModule from '../module'; import { logger } from '@cdm-logger/server'; import 'jest'; import WorkbenchModule from '@workbench-stack/module-server'; import { TYPES } from '@workbench-stack/core'; import { EnvironmentService, parseArgs, StorageService, InMemoryLocalStorage, IWorkspaceSettings, ICoreSettings, } from '@workbench-stack/platform-server'; // some how e need to set NODE_ENV='TEST' require('dotenv').config({ path: process.env.ENV_FILE }); const environmentService = new EnvironmentService(parseArgs([]), process.execPath); const storageService = new StorageService(new InMemoryLocalStorage(), null, ''); export const settings = { rootFilePath: process.env.FILE_ROOT_PATH, workspaceId: 'workspaceId', environmentService, storageService, logger, topic: 'test', pubsub: {}, }; const defaultModule = () => new ContainerModule((bind: interfaces.Bind) => { bind('Logger').toConstantValue(logger); bind('Settings').toConstantValue(settings).whenTargetTagged('default', true); bind('Settings').toConstantValue(settings).whenTargetTagged('microservice', true); bind('Environment').toConstantValue(process.env.NODE_ENV || 'development'); bind(CommonType.PUBSUB).toConstantValue({}); bind('Hemera').toConstantValue({}); bind(TYPES.IEnvironmentService).to(EnvironmentService); }); const DefaultFeature = new Feature({ createContainerFunc: [defaultModule], }); describe('FilesMicroservice test', () => { it('test container', async () => { expect(process.env.NODE_ENV).not.toEqual('development'); const modules = new Feature(DefaultFeature, FilesModule, WorkbenchModule); const serviceContext = modules.createServiceContext(settings); const context = await serviceContext(null, null); expect(context).toBeDefined(); }); });