Skip to content

Commit

Permalink
fix: update tests and cli to use new refactored ports
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfisher committed Dec 7, 2019
1 parent fb14978 commit 99ad915
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
19 changes: 17 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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')
Expand Down
18 changes: 14 additions & 4 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit 99ad915

Please sign in to comment.