import nrfdlModule, { Error, HotplugEvent, // @ts-ignore nrfdlModule Is not a module } from '../../../index'; import { validateSchema } from './common/helpers'; import { PROGRAMMER_APP_FILTERS } from './common/config'; require('../../../jasmine_shared.js'); /** * Test cases: * NOTE: for now require manual events trigger, so skipped * * Test API: * - startHotPlugEvents() * - stopHotPlugEvents() * * Test Schema: * - HotplugEvent * */ xdescribe('Hot plug events: ', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; let context = 0; let hotPlugTaskID = 0; let eventsCount = 0; beforeAll(async () => { context = nrfdlModule.createContext({ plugins_dir: './Release' }); hotPlugTaskID = nrfdlModule.startHotplugEvents( context, (err: Error) => { if (err) { console.warn('Listen to hot plug events stopped with an error'); } }, async (event: HotplugEvent) => { const schemaIsValid = await validateSchema('#/definitions/HotplugEvent', event); eventsCount += 1; // exit immediately after first error (or it will be hard to trace back error) if (!schemaIsValid) { nrfdlModule.stopHotplugEvents(hotPlugTaskID); } expect(schemaIsValid).toBe(true); } ); }); afterAll(async () => { nrfdlModule.stopHotplugEvents(hotPlugTaskID); }); it('Start listening', async () => { expect(hotPlugTaskID).toBeGreaterThan(0); // will trigger events to trace await nrfdlModule.enumerate(context, PROGRAMMER_APP_FILTERS); // note: here must be executed automated plug in / off to trigger the events await new Promise(r => setTimeout(r, 20000)); expect(eventsCount).toBeGreaterThan(0); }); });