mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
fix: reject on non-zero exit codes (#2046)
* fix: reject on non-zero exit codes * fix: use more descriptive error message
This commit is contained in:
parent
b8ada2b83e
commit
6ee5c8471f
3 changed files with 21 additions and 1 deletions
|
|
@ -42,6 +42,7 @@ function listLinux() {
|
|||
const ports = []
|
||||
const ude = childProcess.spawn('udevadm', ['info', '-e'])
|
||||
const lines = ude.stdout.pipe(new Readline())
|
||||
ude.on('close', code => code && reject(new Error(`Error listing ports udevadm exited with error code: ${code}`)))
|
||||
ude.on('error', reject)
|
||||
lines.on('error', reject)
|
||||
|
||||
|
|
|
|||
|
|
@ -113,4 +113,18 @@ describe('listLinux', () => {
|
|||
assert.containSubset(ports, portOutput)
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects on non-zero exit codes', () => {
|
||||
const list = listLinux()
|
||||
listLinux.emit('close', 1)
|
||||
|
||||
list.then(
|
||||
() => {
|
||||
assert.fail('should not resolve for non-zero exit codes')
|
||||
},
|
||||
error => {
|
||||
assert(error, new Error('Error listing ports udevadm exited with error code: 1'))
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@ const EventEmitter = require('events')
|
|||
const proxyquire = require('proxyquire')
|
||||
const Readable = require('stream').Readable
|
||||
let mockPorts
|
||||
let event
|
||||
|
||||
proxyquire.noPreserveCache()
|
||||
const listLinux = proxyquire('../linux-list', {
|
||||
child_process: {
|
||||
spawn() {
|
||||
const event = new EventEmitter()
|
||||
const stream = new Readable()
|
||||
event = new EventEmitter()
|
||||
event.stdout = stream
|
||||
stream.push(mockPorts)
|
||||
stream.push(null)
|
||||
|
|
@ -24,6 +25,10 @@ listLinux.setPorts = ports => {
|
|||
mockPorts = ports
|
||||
}
|
||||
|
||||
listLinux.emit = function() {
|
||||
event.emit.apply(event, arguments)
|
||||
}
|
||||
|
||||
listLinux.reset = () => {
|
||||
mockPorts = {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue