Skip to content

Commit

Permalink
✂️ refactor: update all dependencies, adapt tests to new ava version
Browse files Browse the repository at this point in the history
  • Loading branch information
anoff committed May 16, 2020
1 parent 32fd3eb commit 37d4213
Show file tree
Hide file tree
Showing 7 changed files with 1,613 additions and 2,484 deletions.
14 changes: 7 additions & 7 deletions lib/connection-send.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventEmitter from 'events'
import test from 'ava'
import td from 'testdouble'
const EventEmitter = require('events').EventEmitter
const test = require('ava')
const td = require('testdouble')

class SpStub extends EventEmitter {
constructor (port, opts, cb) {
Expand All @@ -26,15 +26,15 @@ test('.send() should reject if connection is not open', async t => {
const M = mock()
const m = await new M()
await m.close()
return t.throwsAsync(() => m.send(), 'instance not in state OPEN')
return t.throwsAsync(() => m.send(), null, 'instance not in state OPEN')
})

test('.send() should reject if not used with string', async t => {
const M = mock()
const m = await new M()
await t.throwsAsync(() => m.send(), 'first argument must be a string')
await t.throwsAsync(() => m.send(12), 'first argument must be a string')
await t.throwsAsync(() => m.send({ text: 'this' }), 'first argument must be a string')
await t.throwsAsync(() => m.send(), null, 'first argument must be a string')
await t.throwsAsync(() => m.send(12), null, 'first argument must be a string')
await t.throwsAsync(() => m.send({ text: 'this' }), null, 'first argument must be a string')
})

test('.send() should fulfill', async t => {
Expand Down
14 changes: 7 additions & 7 deletions lib/connection.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventEmitter from 'events'
import test from 'ava'
import td from 'testdouble'
const EventEmitter = require('events').EventEmitter
const test = require('ava')
const td = require('testdouble')

class SpStub extends EventEmitter {
constructor (port, opts, cb) {
Expand Down Expand Up @@ -31,11 +31,11 @@ test('.state should be OPEN after .constructor() call', async t => {
test('.constructor() should reject on error', t => {
class SpStub {
constructor (port, opts, cb) {
cb('erroror') // eslint-disable-line standard/no-callback-literal
cb(new Error('erroror')) // eslint-disable-line standard/no-callback-literal
}
}
const M = mock(SpStub)
return t.throwsAsync(() => new M(), 'erroror')
return t.throwsAsync(() => new M(), null, 'erroror')
})

test('.close() should resolve', async t => {
Expand All @@ -51,13 +51,13 @@ test('.close() should reject on error', async t => {
}

close (cb) {
cb('errors') // eslint-disable-line standard/no-callback-literal
cb(new Error('errors')) // eslint-disable-line standard/no-callback-literal
}
}
const M = mock(SpStub)
const m = await new M()
return Promise.all([
t.throwsAsync(() => m.close(), 'errors'),
t.throwsAsync(() => m.close(), null, 'errors'),
t.is(m.getState(), M.states().ERROR)
])
})
Expand Down
11 changes: 2 additions & 9 deletions lib/serialio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ class SerialIo {
* https://github.com/EmergingTechnologyAdvisors/node-serialport#module_serialport--SerialPort.list
*/
static ports () {
return new Promise((resolve, reject) => {
serialport.list((err, ports) => {
if (err) {
reject(new Error(err))
} else {
resolve(ports)
}
})
})
return serialport.list()
}

/**
Expand All @@ -42,3 +34,4 @@ class SerialIo {
}

module.exports = SerialIo
module.exports.Connection = Connection
10 changes: 5 additions & 5 deletions lib/serialio.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava'
import td from 'testdouble'
const test = require('ava')
const td = require('testdouble')

function mock (sp = { list: cb => cb() }) {
td.replace('serialport', sp)
Expand All @@ -8,13 +8,13 @@ function mock (sp = { list: cb => cb() }) {
}

test('.ports() should resolve to list of ports', async t => {
const m = mock({ list: cb => cb(null, 'weeo') })
const m = mock({ list: () => Promise.resolve('weeo') })
t.is(await m.ports(), 'weeo')
})

test('.ports() should reject if erronous', t => {
const m = mock({ list: cb => cb('erroror', 'weeo') }) // eslint-disable-line standard/no-callback-literal
return t.throwsAsync(() => m.ports(), 'erroror')
const m = mock({ list: () => Promise.reject(new Error('erroror'), 'weeo') }) // eslint-disable-line standard/no-callback-literal
return t.throwsAsync(() => m.ports(), null, 'erroror')
})

test('.send() single command', t => {
Expand Down
Loading

0 comments on commit 37d4213

Please sign in to comment.