From 99ad9150589858e9958a96fa3d0d9b6abda9ab8e Mon Sep 17 00:00:00 2001 From: ajfisher Date: Sat, 7 Dec 2019 14:23:51 +1100 Subject: [PATCH] fix: update tests and cli to use new refactored ports --- bin/cli.js | 19 +++++++++++++++++-- test/client.test.js | 18 ++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index f241163..a54d3c1 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -16,7 +16,7 @@ program.command('list') .action(() => { const list = interchange.list_devices(); let outstr = '\nFirmwares available for backpacks. (f) denotes a firmata version is available\n\n'; - list.firmwares.forEach((fw) => { + list.forEach((fw) => { outstr += ` ${fw.name} ${fw.firmata ? '(f)' : ''}: ${fw.description}\n`; }); console.info(outstr); @@ -26,7 +26,22 @@ program.command('ports') .description('Lists all of the attached boards and their ports') .alias('p') .option('-v, --verbose', 'List with additional information') - .action(interchange.list_ports.bind(interchange)); + .action((opts) => { + // get the ports and then list them out. + interchange.get_ports() + .then((ports) => { + if (opts.verbose) { + console.info(ports); + } else { + ports.forEach((port) => { + console.info(port.path.cyan); + }); + } + }) + .catch(err => { + console.log(err); + }); + }); program.command('read') .description('Read firmware info from port') diff --git a/test/client.test.js b/test/client.test.js index 1c424a1..e4f3b4e 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -16,15 +16,25 @@ const interchange_shape = () => describe('1.Shape of the interchange object is c test('1.1 Can we list the firmwares', () => { // console.log(interchange); expect(interchange.list_devices()).toBeDefined(); - expect(interchange.list_devices().firmwares).toBeDefined(); - const f = interchange.list_devices().firmwares[0]; + const f = interchange.list_devices()[0]; expect(f.name).toBeDefined(); expect(f.firmata).toBeDefined(); expect(f.description).toBeDefined(); }); - test('1.2 can we list the ports', () => { - expect(interchange.list_ports()).toBeDefined(); + test('1.2 can we get the ports', () => { + // do this as a promise and then execute + return interchange.get_ports().then(ports => { + expect(ports).toBeDefined(); + }); + }); + + test('1.3 Does list ports return the same as get ports', async() => { + const list = await interchange.list_ports(); + const get = await interchange.get_ports(); + expect(list).toBeDefined(); + expect(get).toBeDefined(); + expect(get).toEqual(list); }); });