UNPKG

@yhiot/logger

Version:

物联网日志队列读写系统,后端目前支持redis

68 lines (61 loc) 1.38 kB
import createLogger from '../src/logger'; const logger = createLogger({ type: 'redis', url: 'redis://localhost:6379/1', }); const testCases = [ { module: 'product', event: 'created', data: { id: '1', }, createdAt: new Date().getTime(), }, { module: 'device', event: 'created', data: { id: '1', }, createdAt: new Date().getTime(), }, { module: 'product', event: 'created', data: { id: '2', }, createdAt: new Date().getTime(), }, ]; describe('createLogger', () => { test('createLogger: other', async () => { expect( createLogger({ type: 'other', url: 'redis://localhost:6379/1' }), ).toBe(null); }); }); describe('send', () => { testCases.forEach(tc => { const { module, event, data, createdAt } = tc; test(`${module} - ${event} - ${createdAt}: ${data}`, async () => { expect( typeof (await logger.send(module, event, data, createdAt)), ).toEqual('number'); }); }); }); describe('receive', () => { testCases.forEach((tc, index) => { // const { module, event, data, createdAt } = tc; test(`${index}: ${tc}`, async () => { expect(typeof (await logger.receive())).toEqual('object'); }); }); }); describe('stop', () => { test('stop', async () => { expect(await logger.stop()).toEqual(true); }); });