npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

tessel-mocks

v1.1.1

Published

Mock your Tessel functionality while working locally

Downloads

11

Readme

#Tessel-Mocks

Allows local runtime for software designed for the Tessel 2.

Tessel 2 makes the require('tessel') package available once your code has been run on or pushed to the device. Unfortunately, the tessel package is not available locally, so when the script is run on your development machine the execution will halt with a missing package error.

This repo allows users to mock the functionality of the actual tessel device on a local machine.

Based loosely on https://github.com/samilamti/tessel-fakes

##Usage

In your main script, near the rest of the require statements, replace the var tessel = require("tessel") with the following:

try {
    var tessel = require("tessel");
} catch(e) {
    console.error("Tessel not found - running mocks instead");
    var Tessel = require('tessel-mocks');
    tessel = new Tessel();
}

From this point on when running locally, the Tessel commands will print statements in the console instead of performing actions on the device.

  • To run code on the Tessel: t2 run index.js
  • To run code locally: node index.js

###Example Comparison

When running on the Tessel, this code will flash LED3 (blue) every 2 seconds:

setInterval(function(){
  tessel.led[3].toggle();
}, 2000);

... but when running locally with node index.js, the console prints this:

Tessel not found - running mocks instead
TM | Toggled LED2 on
TM | Toggled LED2 off
TM | Toggled LED2 on

###Mocking Responses

Serial communication devices can be mocked by passing additional parameters in any method that supports a callback. These extra parameters do not affect Tessel runtime and will be ignored on the device, but while running locally they will return the values specified.

To do this, pass 2 extra parameters (as if they were the callback values) to the target functions. Take the I2C Transfer method:

i2c.transfer(txbuf, rxlen, callback);

... and this becomes:

i2c.transfer(txbuf, rxlen, callback, mockError, mockReturn);

Example: BME280 I2C

This code prints no error and returns the ID of the BME280 device (which is 60):

var slaveAddress = 0x77;
var readLength = 1;
var i2c = new tessel.port.A.I2C(slaveAddress)

i2c.transfer(new Buffer([0xD0]), readLength, function (err, rx) {
  console.log('error returned by I2C Slave: ', err)
  console.log('buffer returned by I2C slave ('+slaveAddress.toString(16)+'):', rx);
});

Output:

INFO Running index.js...
error returned by I2C Slave:  null
buffer returned by I2C slave (77): <Buffer 60>

If this script is run locally with node index.js, the callback will not contain data:

INFO Running index.js...
Tessel not found - running mocks instead
TM | I2C Transfer: �
error returned by I2C Slave:  [Error]
buffer returned by I2C slave (77): undefined

Instead, if mock responses are passed in:

var slaveAddress = 0x77;
var readLength = 1;
var i2c = new tessel.port.A.I2C(slaveAddress)

i2c.transfer(new Buffer([0xD0]), readLength, function (err, rx) {
  console.log('error returned by I2C Slave: ', err)
  console.log('buffer returned by I2C slave ('+slaveAddress.toString(16)+'):', rx);
}, 'Test Error', '99');

... then the mock data will be populated in console:

Tessel not found - running mocks instead
TM | I2C Transfer: �
error returned by I2C Slave:  [Error: Test Error]
buffer returned by I2C slave (77): 99

##Todo Mocks

  • [x] LEDs
  • [ ] Digital Pins
  • [ ] Analog Pins
  • [ ] Interrupt Pins
  • [ ] Ports
  • [ ] UART
  • [ ] SPI
  • [x] I2C
  • [ ] PWM
  • [ ] Button