node-serialport-bindings-cpp/test/makeTestFeature.ts
Francis Gulotta 2a93f48ee6
feat: migrate to typescript (#3)
This change migrates to typescript. The tests have been modified to conform to typescript and to cleanup cases when they weren't actually working (only one or two cases).

I've defined the existing bindings interface for all platforms. There are changes I'd love to make but didn't here (update/set/get/getBaudRate etc are messy). This should in theory be a drop in for the existing bindings. If there are bugs I imagine they're type related not functionality.

I dropped abstract bindings as having it a separate package didn't make sense during the refactor. I'd like to iterate on the design a bit more before returning to that class. Mockbinding may also now be drifted slightly from this package. I'll clean those inconsistencies up when I upgrade the main repo.
2022-01-22 15:55:03 -05:00

43 lines
1.4 KiB
TypeScript

import testConfig from './config.json'
export const makeTestFeature = (envName: string, testPort?: string) => {
const config = { ...testConfig.all, ...(testConfig as any)[envName] }
const testFeature = (feature: string, description: string, callback: () => any) => {
if (config[feature] === false) {
return it(`Feature "${feature}" is disabled in "${envName}. "${description}"`)
}
it(description, callback)
}
const testHardware = (description: string, callback: () => any) => {
if (!testPort) {
return it(`${description} - Cannot be tested. Set the TEST_PORT env var with an available serialport for more testing.`)
}
it(description, callback)
}
const testHardwareFeature = (feature: string, description: string, callback: () => any) => {
if (!testPort) {
return it(`${description} - Cannot be tested. Set the TEST_PORT env var with an available serialport for more testing.`)
}
if (config[feature] === false) {
return it(`Feature "${feature}" is disabled in "${envName}. "${description}"`)
}
it(description, callback)
}
const describeHardware = (description: string, callback: () => any) => {
if (!testPort) {
return it(`${description} - Cannot be tested. Set the TEST_PORT env var with an available serialport for more testing.`)
}
describe(description, callback)
}
return {
testFeature,
testHardwareFeature,
testHardware,
describeHardware,
}
}