mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
* progress on better error handling * wiring onError callback through module loader and resolver * fix error callbacks not being stored * update onError to be record * type alias * wiring * seems to work * update error handling contract and wire more * add command error builder * fix merge * progress on error handling * naive onError handling, not tested * progres * proress * progress on abstracting away iti * seems to work * fix tests * better typings * add doc * abstracting iti * remove onerror for this pr * feat: better way to add dependencies * fix tests
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { beforeEach, describe, expect, vi, it } from 'vitest';
|
|
import { createResultResolver, eventDispatcher } from '../../src/handlers/_internal';
|
|
import { faker } from '@faker-js/faker';
|
|
import { Module } from '../../src/core/types/modules';
|
|
import { Processed } from '../../src/handlers/types';
|
|
import { CommandType } from '../../src/core';
|
|
import { EventEmitter } from 'events';
|
|
|
|
function createRandomModule(): Processed<Module> {
|
|
return {
|
|
type: faker.number.int({
|
|
min: CommandType.Text,
|
|
max: CommandType.ChannelSelect,
|
|
}),
|
|
description: faker.string.alpha(),
|
|
name: faker.string.alpha(),
|
|
onEvent: [],
|
|
plugins: [],
|
|
execute: vi.fn(),
|
|
};
|
|
}
|
|
|
|
describe('eventDispatcher standard', () => {
|
|
let m: Processed<Module>;
|
|
let ee: EventEmitter;
|
|
beforeEach(() => {
|
|
ee = new EventEmitter();
|
|
m = createRandomModule();
|
|
});
|
|
|
|
it('should throw', () => {
|
|
expect(() => eventDispatcher(m, 'not event emitter')).toThrowError();
|
|
});
|
|
it("Shouldn't throw", () => {
|
|
expect(() => eventDispatcher(m, ee)).not.toThrowError();
|
|
});
|
|
|
|
it('Should be called once', () => {
|
|
const s = eventDispatcher(m, ee);
|
|
s.subscribe();
|
|
ee.emit(m.name, faker.string.alpha());
|
|
|
|
expect(m.execute).toHaveBeenCalledOnce();
|
|
});
|
|
});
|