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

iobroker-test-io

v0.1.0

Published

A framework to test ioBroker JavaScript scripts

Readme

TestIo - ioBroker JavaScript Test Framework

Actions Status

Logo

TestIo is small framework for testing ioBroker JavaScript scripts. It mocks the functions defined by the JavaScript engine with Sinon.js.

Installation

npm install iobroker-test-io

Usage

TestIo can be used with any JavaScript test execution framework and should be loaded with const testio = require("iobroker-test-io");.

After you loaded the module, the global function check(pahtToScirpt, testFunction) is available. The first parameter is the relative path (from where the test is located) to the script to test. The second one is the test function, which should contain your test code. Before the test function is called, the test script is loaded and after the test run it is unloaded again. This ensures no state remains between tests.

Every function defined by ioBroker has its own fake object and can be accessed via the testio object (if you required the module via const testio = require("iobroker-test-io");). For example, if you want to check if setState() was called, you can use the fake which is used in the background. It is accessible via testio.setState.fake. In combination with sinon.js an assert could look like this: sinon.assert.calledWith(testio.createState.fake, "switches.trigger");. This tests, if createState was called with switches.trigger. Example:

const chai = require("chai");
const sinon = require("sinon");
const testio = require("iobroker-test-io");

describe("Switch tests", () => {

    it("switches.trigger is created", () => {

        // The check function loads the ioBroker script for the test and unloads it again after the test
        check("../../path/to/ioBroker/script", () => {
            // check if switches.trigger was created as state
            sinon.assert.calledWith(testio.fakes.createState.fake, "switches.trigger");
        });
    });
});

Analog to this you can access the fake of any function defined by the ioBroker JavaScript engine. Additionally you can reset the call state of any function any time with the resetHistory() function. Example: testio.setState.resetHistory().

The function on is a little bit more advanced than the others. It provided additionally the function trigger(id, state), which enables to trigger the on function in a scirpt. id is the object id to trigger and state is the complete sate as it would be accessible in the real on function. Example:

const chai = require("chai");
const testio = require("iobroker-test-io");

const { expect } = chai;

describe("Switch tests", () => {

    // This test checks if Shelly_2 is switched on, when Shelly_1 is switched on.
    it("switches both shellies on", () => {

        // The check function loads the ioBroker script for the test and unloads it again after the test
        check("../../path/to/ioBroker/script", () => {

            // simulate that Shelly_1 is switched on
            testio.fakes.on.trigger("shelly.0.Shelly_1.Relay0.Switch", { 
                state: { 
                    ack: true,
                    val: true
                }
            });

            // check if Shelly_2 is also switched on
            expect(testio.fakes.setState.fake.calledWith("shelly.0.Shelly_2.Relay0.Switch", true)).to.be.true;
        });
    });
});