From 68c5f09b46c8eb0bb3d72a9422baa3ad90385c74 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 28 Apr 2024 21:20:36 -0500 Subject: [PATCH] fix text compile --- src/core/module-loading.ts | 2 +- src/core/operators.ts | 15 ++++++--------- test/core/contracts.test.ts | 13 ++++--------- test/core/services.test.ts | 32 +++---------------------------- test/handlers/dispatchers.test.ts | 2 +- 5 files changed, 15 insertions(+), 49 deletions(-) diff --git a/src/core/module-loading.ts b/src/core/module-loading.ts index 978aa25..3f6ff9e 100644 --- a/src/core/module-loading.ts +++ b/src/core/module-loading.ts @@ -13,6 +13,7 @@ export const parseCallsite = (fpath: string) => { return { name: pathobj.name, absPath : path.posix.format(pathobj) } } + export const shouldHandle = (pth: string, filenam: string) => { const file_name = filenam+path.extname(pth); let newPath = path.join(path.dirname(pth), file_name) @@ -22,7 +23,6 @@ export const shouldHandle = (pth: string, filenam: string) => { } -export type ModuleResult = Promise>; /** * Import any module based on the absolute path. diff --git a/src/core/operators.ts b/src/core/operators.ts index 44fbf54..28f1c33 100644 --- a/src/core/operators.ts +++ b/src/core/operators.ts @@ -51,14 +51,13 @@ export const arrayifySource = map(src => (Array.isArray(src) ? (src as unknown[] /** * Checks if the stream of results is all ok. */ -export const everyPluginOk: OperatorFunction = pipe( - every(result => result.isOk()), - defaultIfEmpty(true), -); +export const everyPluginOk: OperatorFunction = + pipe(every(result => result.isOk()), + defaultIfEmpty(true)); + +export const sharedEventStream = (e: Emitter, eventName: string) => + (fromEvent(e, eventName) as Observable).pipe(share()); -export const sharedEventStream = (e: Emitter, eventName: string) => { - return (fromEvent(e, eventName) as Observable).pipe(share()); -}; export function handleError(crashHandler: ErrorHandling, emitter: Emitter, logging?: Logging) { return (pload: unknown, caught: Observable) => { @@ -80,5 +79,3 @@ export const filterTap = (onErr: (e: R) => void): OperatorFunction { it('should satisfy contracts', () => { - assertType(new DefaultContracts.DefaultLogging()); - assertType(new DefaultContracts.DefaultErrorHandling()); - assertType( - new DefaultContracts.DefaultModuleManager(new ModuleStore()), - ); - assertType(new ModuleStore()); + assertType(new __Services.DefaultLogging()); + assertType(new __Services.DefaultErrorHandling()); }); }); diff --git a/test/core/services.test.ts b/test/core/services.test.ts index cfd963a..148fdf6 100644 --- a/test/core/services.test.ts +++ b/test/core/services.test.ts @@ -1,10 +1,9 @@ import { SpyInstance, afterAll, beforeEach, describe, expect, it, vi } from 'vitest'; import { CoreContainer } from '../../src/core/ioc/container'; -import { DefaultLogging } from '../../src/core'; +import { __Services } from '../../src/core/structures/'; import { faker } from '@faker-js/faker'; import { commandModule, CommandType } from '../../src'; -import * as Id from '../../src/core/id'; -import { CommandMeta } from '../../src/types/core-modules'; + function createRandomCommandModules() { return commandModule({ type: CommandType.Slash, @@ -19,7 +18,7 @@ describe('services', () => { let consoleMock: SpyInstance; beforeEach(() => { container = new CoreContainer(); - container.add({ '@sern/logger': () => new DefaultLogging() }); + container.add({ '@sern/logger': () => new __Services.DefaultLogging() }); container.ready(); consoleMock = vi.spyOn(container.get('@sern/logger'), 'error').mockImplementation(() => {}); }); @@ -27,31 +26,6 @@ describe('services', () => { afterAll(() => { consoleMock.mockReset(); }); - it('module-store.ts', async () => { - const modules = faker.helpers.multiple(createRandomCommandModules, { - count: 40, - }); - - const paths = faker.helpers - .multiple(faker.system.directoryPath, { count: 40 }) - .map((path, i) => `${path}/${modules[i]}.js`); - - const metadata: CommandMeta[] = modules.map((cm, i) => ({ - id: Id.create(cm.name!, cm.type), - isClass: false, - fullPath: `${paths[i]}/${cm.name}.js`, - })); - const moduleManager = container.get('@sern/modules'); - let i = 0; - for (const m of modules) { - moduleManager.set(Id.create(m.name!, m.type), paths[i]); - moduleManager.setMetadata(m, metadata[i]); - i++; - } - for (const m of modules) { - expect(moduleManager.getMetadata(m), 'module references do not exist').toBeDefined(); - } - }); //todo add more it('error-handling', () => { diff --git a/test/handlers/dispatchers.test.ts b/test/handlers/dispatchers.test.ts index 0f100d2..a8c7721 100644 --- a/test/handlers/dispatchers.test.ts +++ b/test/handlers/dispatchers.test.ts @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, vi, it } from 'vitest'; -import { createResultResolver, eventDispatcher } from '../../src/handlers/_internal'; +import { eventDispatcher } from '../../src/handlers/dispatchers'; import { faker } from '@faker-js/faker'; import { Module } from '../../src/core/types/modules'; import { Processed } from '../../src/handlers/types';