Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reject on non-zero exit codes #2046

Merged
merged 2 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/bindings/lib/linux-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(`List exited with code: ${code}`)))
Swaagie marked this conversation as resolved.
Show resolved Hide resolved
ude.on('error', reject)
lines.on('error', reject)

Expand Down
14 changes: 14 additions & 0 deletions packages/bindings/lib/linux-list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('List exited with code: 1'))
}
)
})
})
7 changes: 6 additions & 1 deletion packages/bindings/lib/mocks/linux-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -24,6 +25,10 @@ listLinux.setPorts = ports => {
mockPorts = ports
}

listLinux.emit = function() {
event.emit.apply(event, arguments)
}

listLinux.reset = () => {
mockPorts = {}
}
Expand Down