import fs from 'fs/promises'; import nrfdlModule, { Device, Error, // @ts-ignore nrfdlModule Is not a module } from '../../../index'; import { SPECIAL_CHARACTERS } from './common/helpers'; require('../../../jasmine_shared.js'); /** * Test cases: * - utf8 various test cases * * Test API: * - firmwareProgram() * * Test Schema: * - */ describe('Program firmware but with special characters in path', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; // todo: extract paths to separate file const hex_path = './jlink_usb.hex'; const nrf91_modem_zip_path = './mfw_nrf9160_1.2.2.zip'; const sdfu_path = './dfu_pkg.zip'; let context = 0; const jLinkDevices: Device[] = []; const nordicDfuDevices: Device[] = []; beforeAll(async () => { context = nrfdlModule.createContext({ plugins_dir: './Release' }); const jlink: Device[] = await nrfdlModule.enumerate(context, { jlink: true, }); jLinkDevices.push(...jlink); const nordicDfu: Device[] = await nrfdlModule.enumerate(context, { nordicDfu: true, }); nordicDfuDevices.push(...nordicDfu); }); afterAll(() => { nrfdlModule.releaseContext(context); }); describe('', () => { const hex_path_spec_chars = `./jlink_usb_${SPECIAL_CHARACTERS}.hex`; const nrf91_modem_zip_path_spec_chars = `./mfw_nrf9160_1.2.2_NON_SPEC_${SPECIAL_CHARACTERS}.zip`; const sdfu_path_spec_chars = `./dfu_pkg_${SPECIAL_CHARACTERS}.zip`; beforeAll(async () => { await fs.copyFile(hex_path, hex_path_spec_chars); await fs.copyFile(nrf91_modem_zip_path, nrf91_modem_zip_path_spec_chars); await fs.copyFile(sdfu_path, sdfu_path_spec_chars); }); afterAll(async () => { // cleanup // todo: extract to helper try { await fs.access(hex_path_spec_chars); await fs.unlink(hex_path_spec_chars); } catch (e) { // nothing to do } try { await fs.access(nrf91_modem_zip_path_spec_chars); await fs.unlink(nrf91_modem_zip_path_spec_chars); } catch (e) { // nothing to do } try { await fs.access(sdfu_path_spec_chars); await fs.unlink(sdfu_path_spec_chars); } catch (e) { // nothing to do } }); it('Test firmwareProgram() nrf91 modem path with utf8 special characters', async () => { const devices = jLinkDevices.filter((el: Device) => { return el.jlink.boardVersion === 'PCA10090'; }); expect(devices.length).toBeGreaterThanOrEqual(1); await new Promise((resolve, reject) => nrfdlModule.firmwareProgram( context, devices[0].id, nrfdlModule.NRFDL_FW_FILE, nrfdlModule.NRFDL_FW_NRF91_MODEM, nrf91_modem_zip_path_spec_chars, (err?: Error) => { if (err) reject(err); resolve(); }, () => {} ) ); await new Promise(r => setTimeout(r, 5000)); }, 100000); it('Test firmwareProgram() hex path with utf8 special characters', async () => { const devices = jLinkDevices.filter((el: Device) => { return el.jlink.boardVersion === 'PCA10056'; }); expect(devices.length).toBeGreaterThanOrEqual(1); await nrfdlModule.deviceControlRecover(context, devices[0].id); await new Promise((resolve, reject) => nrfdlModule.firmwareProgram( context, devices[0].id, nrfdlModule.NRFDL_FW_FILE, nrfdlModule.NRFDL_FW_INTEL_HEX, hex_path_spec_chars, (err?: Error) => { if (err) reject(err); resolve(); }, () => {} ) ); await new Promise(r => setTimeout(r, 5000)); }, 50000); it('Test firmwareProgram() sdfu path with utf8 special characters', async () => { expect(nordicDfuDevices.length).toBeGreaterThanOrEqual(1); await new Promise((resolve, reject) => nrfdlModule.firmwareProgram( context, nordicDfuDevices[0].id, nrfdlModule.NRFDL_FW_FILE, nrfdlModule.NRFDL_FW_SDFU_ZIP, sdfu_path_spec_chars, (err: Error) => { if (err) { reject(err); } resolve(null); }, () => {} ) ); await new Promise(r => setTimeout(r, 5000)); }, 50000); }); });