Skip to content

Commit

Permalink
test fixups including not testing windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Feb 14, 2024
1 parent 749bd52 commit 454096e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
12 changes: 11 additions & 1 deletion app-shell/src/system-info/__tests__/usb-devices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { usb } from 'usb'

import * as Fixtures from '@opentrons/app/src/redux/system-info/__fixtures__'
import { createUsbDeviceMonitor, getWindowsDriverVersion } from '../usb-devices'
import { isWindows } from '../../os'

jest.mock('execa')
jest.mock('usb')
Expand Down Expand Up @@ -76,7 +77,9 @@ const mockUSBDevice = {
close: usbDeviceClose,
}

describe('app-shell::system-info::usb-devices', () => {
const describeIfNotWindows = isWindows() ? describe.skip : describe

describeIfNotWindows('app-shell::system-info::usb-devices::detection', () => {
const { windowsDriverVersion: _, ...mockDevice } = Fixtures.mockUsbDevice
afterEach(() => {
jest.resetAllMocks()
Expand Down Expand Up @@ -194,6 +197,13 @@ describe('app-shell::system-info::usb-devices', () => {
reject(new Error('detachListener was not created'))
}
}))
})

describe('app-shell::system-info::usb-devices', () => {
const { windowsDriverVersion: _, ...mockDevice } = Fixtures.mockUsbDevice
afterEach(() => {
jest.resetAllMocks()
})

it('can get the Windows driver version of a device', () => {
execaCommand.mockResolvedValue({ stdout: '1.2.3' } as any)
Expand Down
25 changes: 15 additions & 10 deletions app-shell/src/system-info/usb-devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function upstreamDeviceFromUsbDeviceWinAPI(
// pid
return execa

Check warning on line 118 in app-shell/src/system-info/usb-devices.ts

View check run for this annotation

Codecov / codecov/patch

app-shell/src/system-info/usb-devices.ts#L118

Added line #L118 was not covered by tests
.command(
`Get-WmiObject Win32_PnpEntity -Filter "DeviceId like '%\\VID_${idVendor(
`Get-WmiObject Win32_PnpEntity -Filter "DeviceId like '%\\\\VID_${idVendor(
device
)}&PID_${idProduct(
device
Expand Down Expand Up @@ -228,15 +228,20 @@ function upstreamDeviceFromUsbDeviceLibUSB(
]
})
.finally(() => {
try {
device.close()
} catch (err) {
log.warn(
`Failed to close vid=${idVendor(device)}, pid=${idProduct(
device
)} in err handler: ${err}`
)
}
setImmediate(() => {
try {
device.close()
log.info(

Check warning on line 234 in app-shell/src/system-info/usb-devices.ts

View check run for this annotation

Codecov / codecov/patch

app-shell/src/system-info/usb-devices.ts#L232-L234

Added lines #L232 - L234 were not covered by tests
`closed vid=${idVendor(device)}, pid=${idProduct(device)} ok`
)
} catch (err) {
log.info(

Check warning on line 238 in app-shell/src/system-info/usb-devices.ts

View check run for this annotation

Codecov / codecov/patch

app-shell/src/system-info/usb-devices.ts#L238

Added line #L238 was not covered by tests
`failed to close vid=${idVendor(device)}, pid=${idProduct(
device
)}: ${err}`
)
}
})
})
}

Expand Down

0 comments on commit 454096e

Please sign in to comment.