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 🙏

© 2024 – Pkg Stats / Ryan Hefner

thing-it-test

v0.1.6

Published

Test and verification for all [thing-it-node] Plugins.

Downloads

5,654

Readme

thing-it-test

NPM NPM

Test and verification utility for [thing-it-node] Plugin development.

Device, Sensor and Actor Test

Setting up a Test

Install the package via

npm install thing-it-test

in the directory of your [thing-it-node] Plugin.

In your test program load the [thing-it] Test Driver

var testDriver = require("thing-it-test").createTestDriver({logLevel: "debug"});

Load your Device, Actor and Sensor Plugins, e.g.

testDriver.registerDevicePlugin(__dirname + "/dummyDevice");
testDriver.registerUnitPlugin(__dirname + "/dummyActor");
testDriver.registerUnitPlugin(__dirname + "/dummySensor");
  • note that you need to load Device Plugins before Unit Plugins - and create your configuration
var testConfiguration = {
    label: "Room 22",
    id: "room22",
    devices: [{
        id: "dummyDevice1",
        label: "Dummy Device 1",
        plugin: "dummy-device/dummyDevice",
        logLevel: "debug",
        configuration: {simulated: true, frequency: 5},
        actors: [{
            id: "dummyActor1",
            label: "Dummy Actor 1",
            type: "dummyActor",
            logLevel: "debug",
            configuration: {
            }
        }],
        sensors: [{
            id: "dummySensor1",
            label: "Dummy Sensor 1",
            type: "dummySensor",
            logLevel: "debug",
            configuration: {
                frequency: 5
            }
        }]
    }]
};

You can also load the configuration via require, e.g.

var testConfiguration = require("./dummyConfiguration")

Then run the test, e.g.

testDriver.start({
    configuration: testConfiguration,
    heartbeat: 10,
    simulated: true
}).then(function () {
    setTimeout(function () {
        testDriver.dummyDevice1.dummyActor1.on();
        testDriver.dummyDevice1.dummyActor1.off();
        testDriver.dummyDevice1.dummyActor1.toggle();

        testDriver.stop().then(function () {
        }).fail(function (error) {
            testDriver.logError("Could not stop Device: " + error);
        });
    }, 20000);
}).fail(function (error) {
    testDriver.logError("Could not start Device: " + error);
});

Find a full example here.

Using mocha

If you have installed mocha via

npm install mocha -g

you can define tests like

describe('[thing-it] Philips Hue Plugin', function () {
    var testDriver;

    before(function () {
        testDriver = require("thing-it-test").createTestDriver();

        testDriver.registerDevicePlugin(__dirname + "/../hueBridge");
        testDriver.registerUnitPlugin(__dirname + "/../default-units/lightBulb");
        testDriver.registerUnitPlugin(__dirname + "/../default-units/livingColorLamp");
    });
    describe('Start Configuration', function () {
        this.timeout(5000);

        it('should complete without error', function () {
            return testDriver.start({
                configuration: require("../examples/configuration.js"),
                heartbeat: 10,
                logLevel: "error"
            });
        });
    });
    describe('Service calls', function () {
        it('should complete without error', function (done) {
            testDriver.philipsHueBridge.lightBulbBedroom.setBrightnessPercent({brightnessPercent: 100});
            testDriver.philipsHueBridge.livingColorLampBar.setBrightnessPercent({brightnessPercent: 100});
            testDriver.philipsHueBridge.lightBulbBedroom.setBrightnessPercent({brightnessPercent: 0});
            testDriver.philipsHueBridge.livingColorLampBar.setRgbHex({rgbHex: "#FF0000"});

            done();
        });
    });
});

and run with mocha.

Using Listeners

Many test cases for [thing-it-node] Plugins require listening to the Device's and Actor's reactions to Service Calls or just listening to Sensor Events.

To cover this in test suites you can register event listeners with the test driver e.g. as in the following mocha code

describe('Brightness = 100', function () {
        this.timeout(5000);

        before(function () {
            testDriver.removeAllListeners();
        });
        it('should produce Actor State Change message', function (done) {
            testDriver.addListener({
                publishActorStateChange: function (device, actor, state) {
                    if (actor.id === "lightBulbBedroom" && device.id === "philipsHueBridge" && state.brightnessPercent === 100)
                    {
                        done();
                    }
                    else
                    {
                        done("Unexpected Actor State Change message.");
                    }
                }
            });

            testDriver.philipsHueBridge.lightBulbBedroom.setBrightnessPercent({brightnessPercent: 100});
        });
    });

Listeners are available for

  • publishMessage(message)
  • publishEvent(event)
  • publishDeviceStateChange(device, state)
  • publishDeviceOperationalStateChange(device, state)
  • publishDeviceStateChangeHistory(device, history)
  • publishActorStateChange(device, actor, state)
  • publishActorOperationalStateChange(device, actor, state)
  • publishActorStateChangeHistory(device, actor, history)
  • publishSensorStateChange(device, sensor, state)
  • publishSensorOperationalStateChange(device, sensor, state)
  • publishSensorStateChangeHistory(device, sensor, history)

Test Suite for Device UIs

descriptopn of ussage