import nrfdlModule, { Device, FWInfo, // eslint-disable-next-line @typescript-eslint/no-unused-vars Error, ModuleVersion, // @ts-ignore nrfdlModule Is not a module } from '../../../index'; import { validateSchema } from './common/helpers'; import { MIN_DEVICE_CONNECTED, MIN_MODULE_VERSIONS, PROGRAMMER_APP_FILTERS, RELEASE_DIR } from './common/config'; require('../../../jasmine_shared.js'); /** * Test cases: * - negative test case to check if error is provided as expected * - ... other test cases based on the app's code * * Test API: * - getDeviceCoreInfo() * * Test Schema: * - DeviceInfo * - Error * - FWInfo.ReadResult * Nested interfaces: * - FWInfo.BootloaderType * - FWInfo.Image * - FWInfo.ImageLocation * - FWInfo.ImageType * - FWInfo.SemanticVersion * - ModuleVersion * - Version */ describe('Fetch devices info: ', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; let context = 0; const jLinkDevices: Device[] = []; const allNordicDevices: Device[] = []; beforeAll(async () => { context = nrfdlModule.createContext({ plugins_dir: RELEASE_DIR }); const jlink: Device[] = await nrfdlModule.enumerate(context, { jlink: true, }); jLinkDevices.push(...jlink); const allDevices: Device[] = await nrfdlModule.enumerate(context, { ...PROGRAMMER_APP_FILTERS, serialPorts: false, }); allNordicDevices.push(...allDevices); }); // Used as: if (protectionStatus === 'NRFDL_PROTECTION_STATUS_NONE') getDeviceCoreInfo() it('Test getDeviceCoreInfo()', async () => { expect(jLinkDevices.length).toBeGreaterThan(0); const jLinkDevice: Device | null = jLinkDevices.length > 0 ? jLinkDevices[0] : null; const protectionStatus = await nrfdlModule.deviceControlGetProtectionStatus(context, jLinkDevice.id); if (protectionStatus.protection_status !== 'NRFDL_PROTECTION_STATUS_NONE') { await nrfdlModule.deviceControlRecover(context, jLinkDevice.id); } const deviceCoreInfo = await nrfdlModule.getDeviceCoreInfo(context, jLinkDevice.id); const schemaValid = await validateSchema('#/definitions/DeviceCoreInfo', deviceCoreInfo, true); expect(schemaValid).toBe(true); }); it('Test reading device info readFwInfo()', async () => { expect(allNordicDevices.length).toBeGreaterThanOrEqual(MIN_DEVICE_CONNECTED); let successfulReadCount = 0; await Promise.all( allNordicDevices.map(async dev => { try { const fwInfo: FWInfo.ReadResult = await nrfdlModule.readFwInfo(context, dev.id); const schemaIsValid = await validateSchema('#/definitions/FWInfo.ReadResult', fwInfo, true); expect(schemaIsValid).toBe(true); successfulReadCount += 1; } catch (err: Error & { error_code: string }) { expect(err.error_code).toBeGreaterThanOrEqual(0); expect(err.message).not.toBe(''); expect(err.origin).not.toBe(''); } }) ); // expect at least one successful read expect(successfulReadCount).toBeGreaterThanOrEqual(1); }); it('Read module versions', async () => { const versions = await nrfdlModule.getModuleVersions(context); expect(versions.length).toBeGreaterThanOrEqual(MIN_MODULE_VERSIONS); await Promise.all( versions.map(async (version: ModuleVersion) => { const schemaIsValid = await validateSchema('#/definitions/ModuleVersion', version, true); expect(schemaIsValid).toBe(true); }) ); }); });