Faux I2C
This module provides a mock i2c interface for unit testing. It allows intercepting and testing of device i/o.
It isn't blackmagic. It just lets you emulate I2C manually in tests, so you can confirm that the data being sent and received by your device library is working as expected.
FauxI2C is modeled after Raspi-I2C.
Installation
NPM:
npm install --save-dev faux-i2c
Yarn:
yarn add --dev faux-i2c
Usage
Replace the I2C interface in your device library with an instance of FauxI2C.
Then, you can set the onRead
and onWrite
handlers to intercept those processes.
For example:
"use strict"; /** * Example I2C-enabled device class that reads and writes something over I2C */ { thisi2c = optionsi2c; thisaddress = 0x42; } { const register = 0x01; const bytes = 2; thisi2c; } { const register = 0x01; const buffer = Buffer; thisi2c; } ;
Contributing
If you find a bug or have suggestions, please open a pull request. Contributions are greatly appreciated.
To maintain standards, please ensure that contributions pass unit tests and has complete code coverage.
To run the tests:
npm run report
This script will run the unit tests, code quality and show code coverage. If you are lacking coverage, please
see coverage/index.html
to narrow down where your coverage is lacking.
License
TL;DR? see: http://www.tldrlegal.com/license/mit-license
The MIT License (MIT)Copyright (c) 2018 Kevin M. Fitzgerald Permission is hereby granted, free of charge, to any person obtaining a copy ofthis software and associated documentation files (the "Software"), to deal inthe Software without restriction, including without limitation the rights touse, copy, modify, merge, publish, distribute, sublicense, and/or sell copiesof the Software, and to permit persons to whom the Software is furnished to doso, subject to the following conditions: The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.