Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
thing-it-test
Advanced tools
Test and verification utility for [thing-it-node] Plugin development.
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");
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.
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.
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
FAQs
Test and verification for all [thing-it-node] Plugins.
The npm package thing-it-test receives a total of 766 weekly downloads. As such, thing-it-test popularity was classified as not popular.
We found that thing-it-test demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.