103 lines
2.5 KiB
JavaScript
103 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
var node_events = require('node:events');
|
|
var tap = require('tap');
|
|
var nodeOsc = require('node-osc');
|
|
|
|
tap.test('server: create and close', async (t) => {
|
|
t.plan(1);
|
|
const oscServer = new nodeOsc.Server(0, '127.0.0.1');
|
|
await node_events.once(oscServer, 'listening');
|
|
oscServer.close((err) => {
|
|
t.error(err);
|
|
});
|
|
});
|
|
|
|
tap.test('server: listen to message', async (t) => {
|
|
const oscServer = new nodeOsc.Server(0);
|
|
await node_events.once(oscServer, 'listening');
|
|
const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
|
|
|
|
t.plan(3);
|
|
|
|
t.teardown(() => {
|
|
oscServer.close();
|
|
client.close();
|
|
});
|
|
|
|
oscServer.on('message', (msg) => {
|
|
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
});
|
|
|
|
oscServer.on('/test', (msg) => {
|
|
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
});
|
|
|
|
client.send('/test', (err) => {
|
|
t.error(err, 'there should be no error');
|
|
});
|
|
});
|
|
|
|
tap.test('server: no defined host', async (t) => {
|
|
const oscServer = new nodeOsc.Server(0);
|
|
await node_events.once(oscServer, 'listening');
|
|
const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
|
|
|
|
t.plan(3);
|
|
|
|
t.teardown(() => {
|
|
oscServer.close();
|
|
client.close();
|
|
});
|
|
|
|
oscServer.on('message', (msg) => {
|
|
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
});
|
|
|
|
oscServer.on('/test', (msg) => {
|
|
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
});
|
|
|
|
client.send('/test', (err) => {
|
|
t.error(err, 'there should be no error');
|
|
});
|
|
});
|
|
|
|
tap.test('server: callback as second arg', async (t) => {
|
|
t.plan(4);
|
|
const oscServer = new nodeOsc.Server(0, () => {
|
|
t.ok('callback called');
|
|
});
|
|
await node_events.once(oscServer, 'listening');
|
|
const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
|
|
|
|
t.teardown(() => {
|
|
oscServer.close();
|
|
client.close();
|
|
});
|
|
|
|
oscServer.on('message', (msg) => {
|
|
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
});
|
|
|
|
oscServer.on('/test', (msg) => {
|
|
t.same(msg, ['/test'], 'We should receive expected payload');
|
|
});
|
|
|
|
client.send('/test', (err) => {
|
|
t.error(err, 'there should be no error');
|
|
});
|
|
});
|
|
|
|
tap.test('server: bad message', async (t) => {
|
|
t.plan(2);
|
|
const oscServer = new nodeOsc.Server(0, '127.0.0.1');
|
|
await node_events.once(oscServer, 'listening');
|
|
t.throws(() => {
|
|
oscServer._sock.emit('message', 'whoops');
|
|
}, /can't decode incoming message:/);
|
|
oscServer.close((err) => {
|
|
t.error(err);
|
|
});
|
|
});
|