Initial commit of my folder
This commit is contained in:
19
backend/node_modules/node-osc/test/fixtures/types/test-cjs-types.ts
generated
vendored
Normal file
19
backend/node_modules/node-osc/test/fixtures/types/test-cjs-types.ts
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// Test CJS-style TypeScript imports
|
||||
import type { Client, Server, Message, Bundle } from 'node-osc';
|
||||
const osc = require('node-osc');
|
||||
|
||||
// Create server first (typical usage pattern)
|
||||
const server: Server = new osc.Server(3333, '0.0.0.0');
|
||||
|
||||
// Create client after server
|
||||
const client: Client = new osc.Client('127.0.0.1', 3333);
|
||||
|
||||
// Test Message type
|
||||
const message: Message = new osc.Message('/test', 1, 2, 3);
|
||||
|
||||
// Test Bundle type
|
||||
const bundle: Bundle = new osc.Bundle(['/one', 1]);
|
||||
|
||||
// Test encode/decode with consistent type annotations
|
||||
const encoded: Buffer = osc.encode(message);
|
||||
const decoded: Object = osc.decode(encoded);
|
||||
35
backend/node_modules/node-osc/test/fixtures/types/test-esm-types.ts
generated
vendored
Normal file
35
backend/node_modules/node-osc/test/fixtures/types/test-esm-types.ts
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
// Test ESM TypeScript imports with Top-Level Await
|
||||
import { once } from 'node:events';
|
||||
import { Client, Server, Message, Bundle, encode, decode } from 'node-osc';
|
||||
|
||||
// Create server first (typical usage pattern)
|
||||
const server: Server = new Server(3333, '0.0.0.0');
|
||||
|
||||
// Wait for server to be ready (pattern from examples)
|
||||
await once(server, 'listening');
|
||||
|
||||
server.on('message', (msg) => {
|
||||
console.log('Received message:', msg);
|
||||
});
|
||||
|
||||
// Create client after server
|
||||
const client: Client = new Client('127.0.0.1', 3333);
|
||||
|
||||
// Test async usage with Top-Level Await (ESM feature)
|
||||
await client.send('/test', 1, 2, 3);
|
||||
await client.close();
|
||||
await server.close();
|
||||
|
||||
// Test Message type
|
||||
const message: Message = new Message('/oscillator/frequency', 440);
|
||||
message.append(3.14);
|
||||
message.append('hello');
|
||||
message.append(true);
|
||||
|
||||
// Test Bundle type
|
||||
const bundle: Bundle = new Bundle(['/one', 1], ['/two', 2]);
|
||||
bundle.append(['/three', 3]);
|
||||
|
||||
// Test encode/decode with consistent type annotations
|
||||
const encoded: Buffer = encode(message);
|
||||
const decoded: Object = decode(encoded);
|
||||
17
backend/node_modules/node-osc/test/fixtures/types/tsconfig-cjs.test.json
generated
vendored
Normal file
17
backend/node_modules/node-osc/test/fixtures/types/tsconfig-cjs.test.json
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"target": "ES2022",
|
||||
"moduleResolution": "node",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"node-osc": ["../../../types/index.d.mts"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"test-cjs-types.ts"
|
||||
]
|
||||
}
|
||||
17
backend/node_modules/node-osc/test/fixtures/types/tsconfig-esm.test.json
generated
vendored
Normal file
17
backend/node_modules/node-osc/test/fixtures/types/tsconfig-esm.test.json
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "ES2022",
|
||||
"target": "ES2022",
|
||||
"moduleResolution": "node",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"node-osc": ["../../../types/index.d.mts"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"test-esm-types.ts"
|
||||
]
|
||||
}
|
||||
89
backend/node_modules/node-osc/test/test-bundle.mjs
generated
vendored
Normal file
89
backend/node_modules/node-osc/test/test-bundle.mjs
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
import { once } from 'node:events';
|
||||
import { test } from 'tap';
|
||||
|
||||
import { Client, Server, Bundle } from 'node-osc';
|
||||
|
||||
test('bundle: verbose bundle', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
t.teardown(() => {
|
||||
server.close();
|
||||
client.close();
|
||||
});
|
||||
|
||||
server.on('bundle', (bundle) => {
|
||||
t.same(bundle.elements[0], ['/one', 1]);
|
||||
t.same(bundle.elements[1], ['/two', 2]);
|
||||
});
|
||||
|
||||
client.send(new Bundle(1, {
|
||||
address: '/one',
|
||||
args: [
|
||||
1
|
||||
]
|
||||
}, {
|
||||
address: '/two',
|
||||
args: [
|
||||
2
|
||||
]
|
||||
}));
|
||||
});
|
||||
|
||||
test('bundle: array syntax', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
t.teardown(() => {
|
||||
server.close();
|
||||
client.close();
|
||||
});
|
||||
|
||||
server.on('bundle', (bundle) => {
|
||||
t.same(bundle.elements[0], ['/one', 1]);
|
||||
t.same(bundle.elements[1], ['/two', 2]);
|
||||
});
|
||||
|
||||
client.send(new Bundle(
|
||||
['/one', 1],
|
||||
['/two', 2]
|
||||
));
|
||||
});
|
||||
|
||||
test('bundle: nested bundle', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(4);
|
||||
|
||||
t.teardown(() => {
|
||||
server.close();
|
||||
client.close();
|
||||
});
|
||||
|
||||
const payload = new Bundle(
|
||||
['/one', 1],
|
||||
['/two', 2],
|
||||
['/three', 3]
|
||||
);
|
||||
|
||||
payload.append(new Bundle(10,
|
||||
['/four', 4]
|
||||
));
|
||||
|
||||
server.on('bundle', (bundle) => {
|
||||
t.same(bundle.elements[0], ['/one', 1]);
|
||||
t.same(bundle.elements[1], ['/two', 2]);
|
||||
t.same(bundle.elements[2], ['/three', 3]);
|
||||
t.same(bundle.elements[3].elements[0], ['/four', 4]);
|
||||
});
|
||||
|
||||
client.send(payload);
|
||||
});
|
||||
291
backend/node_modules/node-osc/test/test-client.mjs
generated
vendored
Normal file
291
backend/node_modules/node-osc/test/test-client.mjs
generated
vendored
Normal file
@ -0,0 +1,291 @@
|
||||
import { once } from 'node:events';
|
||||
import { test } from 'tap';
|
||||
|
||||
import { Server, Client } from 'node-osc';
|
||||
|
||||
test('client: with array', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.same(msg, ['/test', 0, 1, 'testing', true], 'We should receive expected payload');
|
||||
});
|
||||
|
||||
client.send(['/test', 0, 1, 'testing', true], (err) => {
|
||||
t.error(err, 'there should be no error');
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
|
||||
test('client: array is not mutated when sent', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(3);
|
||||
|
||||
const originalArray = ['/test', 0, 1, 'testing', true];
|
||||
const expectedArray = ['/test', 0, 1, 'testing', true];
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.same(msg, ['/test', 0, 1, 'testing', true], 'We should receive expected payload');
|
||||
// Verify the original array was not mutated
|
||||
t.same(originalArray, expectedArray, 'Original array should not be mutated');
|
||||
});
|
||||
|
||||
client.send(originalArray, (err) => {
|
||||
t.error(err, 'there should be no error');
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
|
||||
test('client: with string', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.same(msg, ['/test'], `We should receive expected payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send('/test', (err) => {
|
||||
t.error(err, 'there should be no error');
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
|
||||
test('client: with Message object', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.same(msg, ['/test', 1, 2, 3, 'lol', false], `we received the payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send({
|
||||
address: '/test',
|
||||
args: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
'lol',
|
||||
false
|
||||
]
|
||||
}, (err) => {
|
||||
t.error(err, 'there should be no error');
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
|
||||
test('client: with Bundle object', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.same(msg, ['/test', 1, 2, 3, 'lol', false], `we received the payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send({
|
||||
address: '/test',
|
||||
args: [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
'lol',
|
||||
false
|
||||
]
|
||||
}, (err) => {
|
||||
t.error(err, 'there should be no error');
|
||||
client.close();
|
||||
});
|
||||
});
|
||||
|
||||
test('client: failure', async (t) => {
|
||||
const client = new Client('127.0.0.1', 9999);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
t.throws(() => {
|
||||
client.send(123, (err) => {
|
||||
t.error(err, 'there should be no error');
|
||||
});
|
||||
});
|
||||
client.close();
|
||||
client.send('/boom', (err) => {
|
||||
t.equal(err.code, 'ERR_SOCKET_DGRAM_NOT_RUNNING');
|
||||
});
|
||||
});
|
||||
|
||||
test('client: close with callback', async (t) => {
|
||||
const client = new Client('127.0.0.1', 9999);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
client.close((err) => {
|
||||
t.error(err, 'close should not error');
|
||||
});
|
||||
});
|
||||
|
||||
test('client: send bundle with non-numeric timetag', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('bundle', (bundle) => {
|
||||
oscServer.close();
|
||||
t.equal(bundle.timetag, 0, 'should receive immediate execution timetag as 0');
|
||||
t.ok(bundle.elements.length > 0, 'should have elements');
|
||||
client.close();
|
||||
});
|
||||
|
||||
// Send bundle with non-numeric timetag (will be encoded as immediate execution)
|
||||
const bundle = {
|
||||
oscType: 'bundle',
|
||||
timetag: 'immediate', // Non-numeric, will trigger the else branch in writeTimeTag
|
||||
elements: [
|
||||
{
|
||||
oscType: 'message',
|
||||
address: '/test1',
|
||||
args: [{ type: 'i', value: 42 }]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
client.send(bundle);
|
||||
});
|
||||
|
||||
test('client: send bundle with null timetag', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('bundle', (bundle) => {
|
||||
oscServer.close();
|
||||
t.equal(bundle.timetag, 0, 'should receive immediate execution timetag as 0');
|
||||
t.ok(bundle.elements.length > 0, 'should have elements');
|
||||
client.close();
|
||||
});
|
||||
|
||||
// Send bundle with null timetag (will be encoded as immediate execution)
|
||||
const bundle = {
|
||||
oscType: 'bundle',
|
||||
timetag: null, // Null, will trigger the else branch in writeTimeTag
|
||||
elements: [
|
||||
{
|
||||
oscType: 'message',
|
||||
address: '/test2',
|
||||
args: [{ type: 's', value: 'hello' }]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
client.send(bundle);
|
||||
});
|
||||
|
||||
test('client: send message with float type arg', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.equal(msg[0], '/float-test', 'should receive address');
|
||||
t.ok(Math.abs(msg[1] - 9.876) < 0.001, 'should receive float value');
|
||||
client.close();
|
||||
});
|
||||
|
||||
// Send raw message with 'float' type to hit that case label
|
||||
client.send({
|
||||
oscType: 'message',
|
||||
address: '/float-test',
|
||||
args: [{ type: 'float', value: 9.876 }]
|
||||
});
|
||||
});
|
||||
|
||||
test('client: send message with blob type arg', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.equal(msg[0], '/blob-test', 'should receive address');
|
||||
t.ok(Buffer.isBuffer(msg[1]), 'should receive blob as buffer');
|
||||
client.close();
|
||||
});
|
||||
|
||||
// Send raw message with 'blob' type to hit that case label
|
||||
client.send({
|
||||
oscType: 'message',
|
||||
address: '/blob-test',
|
||||
args: [{ type: 'blob', value: Buffer.from([0xAA, 0xBB]) }]
|
||||
});
|
||||
});
|
||||
|
||||
test('client: send message with double type arg', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.equal(msg[0], '/double-test', 'should receive address');
|
||||
t.ok(Math.abs(msg[1] - 1.23456789) < 0.001, 'should receive double value as float');
|
||||
client.close();
|
||||
});
|
||||
|
||||
// Send raw message with 'double' type to hit that case label
|
||||
client.send({
|
||||
oscType: 'message',
|
||||
address: '/double-test',
|
||||
args: [{ type: 'double', value: 1.23456789 }]
|
||||
});
|
||||
});
|
||||
|
||||
test('client: send message with midi type arg', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.equal(msg[0], '/midi-test', 'should receive address');
|
||||
t.ok(Buffer.isBuffer(msg[1]), 'should receive MIDI as buffer');
|
||||
client.close();
|
||||
});
|
||||
|
||||
// Send raw message with 'midi' type to hit that case label
|
||||
client.send({
|
||||
oscType: 'message',
|
||||
address: '/midi-test',
|
||||
args: [{ type: 'midi', value: Buffer.from([0x00, 0x90, 0x40, 0x60]) }]
|
||||
});
|
||||
});
|
||||
143
backend/node_modules/node-osc/test/test-decode.mjs
generated
vendored
Normal file
143
backend/node_modules/node-osc/test/test-decode.mjs
generated
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
import { test } from 'tap';
|
||||
|
||||
import decode from '#decode';
|
||||
|
||||
test('decode: valid', (t) => {
|
||||
const buf = Buffer.from('/test\0\0\0,s\0,testing\0');
|
||||
t.same(decode(buf), ['/test', 'testing'], 'should be empty array');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('decode: valid', (t) => {
|
||||
const buf = Buffer.from('/test\0\0\0,s\0,testing\0');
|
||||
t.same(decode(buf), ['/test', 'testing'], 'should be empty array');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('decode: malformed packet', (t) => {
|
||||
t.throws(() => {
|
||||
const buf = Buffer.from('/test\0\0');
|
||||
decode(buf);
|
||||
}, /Malformed Packet/);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('decode: invalid typetags', (t) => {
|
||||
t.throws(() => {
|
||||
const buf = Buffer.from('/test\0\0\0,R\0');
|
||||
decode(buf);
|
||||
}, /I don't understand the argument code R/);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('decode: malformed OSC structure', (t) => {
|
||||
// Try to create a scenario that might trigger the "else" case in decode
|
||||
// This tests an edge case where the buffer might be parsed but not create a valid OSC structure
|
||||
t.throws(() => {
|
||||
// Create a buffer that's too short to be valid
|
||||
const buf = Buffer.from('\0\0\0\0');
|
||||
decode(buf);
|
||||
}, /Malformed Packet/);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('decode: corrupted buffer', (t) => {
|
||||
// Test with a buffer that could potentially cause fromBuffer to return unexpected results
|
||||
t.throws(() => {
|
||||
// Create a malformed buffer that might not parse correctly
|
||||
const buf = Buffer.from('invalid');
|
||||
decode(buf);
|
||||
}, /(Malformed Packet|Cannot read|out of range)/);
|
||||
t.end();
|
||||
});
|
||||
|
||||
// This test attempts to exercise edge cases in the decode function
|
||||
test('decode: edge case with manually crafted invalid structure', (t) => {
|
||||
// Since the decode function has a defensive else clause, let's try to trigger it
|
||||
// by creating a buffer that might result in an unexpected object structure
|
||||
|
||||
// Try with an empty buffer
|
||||
t.throws(() => {
|
||||
const buf = Buffer.alloc(0);
|
||||
decode(buf);
|
||||
}, /(Malformed Packet|Cannot read|out of range)/);
|
||||
|
||||
// Try with a buffer containing only null bytes
|
||||
t.throws(() => {
|
||||
const buf = Buffer.alloc(16, 0);
|
||||
decode(buf);
|
||||
}, /(Malformed Packet|Cannot read|out of range)/);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('decode: malformed structure with unexpected oscType', async (t) => {
|
||||
// Test the defensive else clause by providing a custom fromBuffer function
|
||||
// that returns an object with an invalid oscType
|
||||
|
||||
const mockFromBuffer = () => ({
|
||||
oscType: 'invalid',
|
||||
data: 'test'
|
||||
});
|
||||
|
||||
t.throws(() => {
|
||||
decode(Buffer.from('test'), mockFromBuffer);
|
||||
}, /Malformed Packet/, 'should throw for invalid oscType');
|
||||
|
||||
// Test with undefined oscType
|
||||
const mockFromBufferUndefined = () => ({
|
||||
data: 'test'
|
||||
// missing oscType property
|
||||
});
|
||||
|
||||
t.throws(() => {
|
||||
decode(Buffer.from('test'), mockFromBufferUndefined);
|
||||
}, /Malformed Packet/, 'should throw for undefined oscType');
|
||||
|
||||
// Test with null oscType
|
||||
const mockFromBufferNull = () => ({
|
||||
oscType: null,
|
||||
data: 'test'
|
||||
});
|
||||
|
||||
t.throws(() => {
|
||||
decode(Buffer.from('test'), mockFromBufferNull);
|
||||
}, /Malformed Packet/, 'should throw for null oscType');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('decode: message without args defaults to empty array', (t) => {
|
||||
const mockFromBuffer = () => ({
|
||||
oscType: 'message',
|
||||
address: '/test'
|
||||
});
|
||||
|
||||
t.same(
|
||||
decode(Buffer.from('test'), mockFromBuffer),
|
||||
['/test'],
|
||||
'should default args to empty array'
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('decode: bundle element must be message or bundle', (t) => {
|
||||
const mockFromBuffer = () => ({
|
||||
oscType: 'bundle',
|
||||
elements: [
|
||||
{
|
||||
oscType: 'message',
|
||||
address: '/ok',
|
||||
args: []
|
||||
},
|
||||
{
|
||||
oscType: 'nope'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
t.throws(() => {
|
||||
decode(Buffer.from('test'), mockFromBuffer);
|
||||
}, /Malformed Packet/, 'should throw for invalid bundle element');
|
||||
t.end();
|
||||
});
|
||||
57
backend/node_modules/node-osc/test/test-e2e.mjs
generated
vendored
Normal file
57
backend/node_modules/node-osc/test/test-e2e.mjs
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
import { once } from 'node:events';
|
||||
import { test } from 'tap';
|
||||
|
||||
import { Server, Client } from 'node-osc';
|
||||
|
||||
function flaky() {
|
||||
return process.release.lts === 'Dubnium' && process.platform === 'win32';
|
||||
}
|
||||
|
||||
function skip(t) {
|
||||
t.skip(`flaky ~ ${t.name}`);
|
||||
t.end();
|
||||
}
|
||||
|
||||
test('osc: argument message no callback', async (t) => {
|
||||
if (flaky()) return skip(t);
|
||||
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
t.teardown(() => {
|
||||
oscServer.close();
|
||||
client.close();
|
||||
});
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
t.same(msg, ['/test', 1, 2, 'testing'], 'We should receive expected payload');
|
||||
});
|
||||
|
||||
client.send('/test', 1, 2, 'testing');
|
||||
});
|
||||
|
||||
test('osc: client with callback and message as arguments', async (t) => {
|
||||
if (flaky()) return skip(t);
|
||||
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
t.teardown(() => {
|
||||
oscServer.close();
|
||||
client.close();
|
||||
});
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
t.same(msg, ['/test', 1, 2, 'testing'], 'We should receive expected payload');
|
||||
});
|
||||
|
||||
client.send('/test', 1, 2, 'testing', (err) => {
|
||||
t.error(err, 'there should be no error');
|
||||
});
|
||||
});
|
||||
1302
backend/node_modules/node-osc/test/test-encode-decode.mjs
generated
vendored
Normal file
1302
backend/node_modules/node-osc/test/test-encode-decode.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
116
backend/node_modules/node-osc/test/test-error-handling.mjs
generated
vendored
Normal file
116
backend/node_modules/node-osc/test/test-error-handling.mjs
generated
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
import { once } from 'node:events';
|
||||
import { test } from 'tap';
|
||||
|
||||
import { Server, Client } from 'node-osc';
|
||||
|
||||
test('server: socket error event is emitted', async (t) => {
|
||||
t.plan(1);
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
|
||||
oscServer.on('error', (err) => {
|
||||
t.ok(err, 'error event should be emitted');
|
||||
oscServer.close();
|
||||
});
|
||||
|
||||
// Simulate a socket error
|
||||
oscServer._sock.emit('error', new Error('test socket error'));
|
||||
});
|
||||
|
||||
test('server: error listener can be added before listening', async (t) => {
|
||||
t.plan(2);
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
|
||||
oscServer.on('error', (err) => {
|
||||
t.ok(err, 'error event should be emitted');
|
||||
t.equal(err.message, 'socket test error', 'error message should match');
|
||||
});
|
||||
|
||||
t.teardown(() => {
|
||||
oscServer.close();
|
||||
});
|
||||
|
||||
// Simulate a socket error
|
||||
oscServer._sock.emit('error', new Error('socket test error'));
|
||||
});
|
||||
|
||||
test('client: socket error event is emitted', (t) => {
|
||||
t.plan(1);
|
||||
const client = new Client('127.0.0.1', 9999);
|
||||
|
||||
client.on('error', (err) => {
|
||||
t.ok(err, 'error event should be emitted');
|
||||
client.close();
|
||||
});
|
||||
|
||||
// Simulate a socket error
|
||||
client._sock.emit('error', new Error('test client error'));
|
||||
});
|
||||
|
||||
test('client: error listener can be added at construction', (t) => {
|
||||
t.plan(2);
|
||||
const client = new Client('127.0.0.1', 9999);
|
||||
|
||||
client.on('error', (err) => {
|
||||
t.ok(err, 'error event should be emitted');
|
||||
t.equal(err.message, 'client socket error', 'error message should match');
|
||||
});
|
||||
|
||||
t.teardown(() => {
|
||||
client.close();
|
||||
});
|
||||
|
||||
// Simulate a socket error
|
||||
client._sock.emit('error', new Error('client socket error'));
|
||||
});
|
||||
|
||||
test('client: is an EventEmitter instance', (t) => {
|
||||
t.plan(1);
|
||||
const client = new Client('127.0.0.1', 9999);
|
||||
|
||||
t.ok(typeof client.on === 'function', 'client should have EventEmitter methods');
|
||||
|
||||
client.close();
|
||||
});
|
||||
|
||||
test('server: multiple error listeners can be attached', async (t) => {
|
||||
t.plan(2);
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
|
||||
oscServer.on('error', (err) => {
|
||||
t.ok(err, 'first listener should receive error');
|
||||
});
|
||||
|
||||
oscServer.on('error', (err) => {
|
||||
t.ok(err, 'second listener should receive error');
|
||||
});
|
||||
|
||||
t.teardown(() => {
|
||||
oscServer.close();
|
||||
});
|
||||
|
||||
// Simulate a socket error
|
||||
oscServer._sock.emit('error', new Error('multi listener test'));
|
||||
});
|
||||
|
||||
test('client: multiple error listeners can be attached', (t) => {
|
||||
t.plan(2);
|
||||
const client = new Client('127.0.0.1', 9999);
|
||||
|
||||
client.on('error', (err) => {
|
||||
t.ok(err, 'first listener should receive error');
|
||||
});
|
||||
|
||||
client.on('error', (err) => {
|
||||
t.ok(err, 'second listener should receive error');
|
||||
});
|
||||
|
||||
t.teardown(() => {
|
||||
client.close();
|
||||
});
|
||||
|
||||
// Simulate a socket error
|
||||
client._sock.emit('error', new Error('multi listener test'));
|
||||
});
|
||||
401
backend/node_modules/node-osc/test/test-message.mjs
generated
vendored
Normal file
401
backend/node_modules/node-osc/test/test-message.mjs
generated
vendored
Normal file
@ -0,0 +1,401 @@
|
||||
import { once } from 'node:events';
|
||||
import { test } from 'tap';
|
||||
import { Server, Client, Message } from 'node-osc';
|
||||
|
||||
function round(num) {
|
||||
return Math.round(num * 100) / 100;
|
||||
}
|
||||
|
||||
test('message: basic usage', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(1);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
m.append('testing');
|
||||
m.append(123);
|
||||
m.append([456, 789]);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = ['/address', 'testing', 123, 456, 789];
|
||||
t.same(msg, expected, `We reveived the payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: multiple args', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(1);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address', 'testing', 123, true);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = ['/address', 'testing', 123, true];
|
||||
t.same(msg, expected, `We reveived the payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: object', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(1);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
m.append({
|
||||
type: 'string',
|
||||
value: 'test'
|
||||
});
|
||||
m.append({
|
||||
type: 'double',
|
||||
value: 100
|
||||
});
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = ['/address', 'test', 100];
|
||||
t.same(msg, expected, `We reveived the payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: float', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(2);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
m.append(3.14);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = [
|
||||
'/address',
|
||||
3.14
|
||||
];
|
||||
t.equal(msg[0], expected[0], `We reveived the payload: ${msg}`);
|
||||
t.equal(round(msg[1]), expected[1], 'pie please');
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: alias messages', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(5);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
m.append({
|
||||
type: 'i',
|
||||
value: 123
|
||||
});
|
||||
m.append({
|
||||
type: 'f',
|
||||
value: 3.14
|
||||
});
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = [
|
||||
'/address',
|
||||
123,
|
||||
3.14
|
||||
];
|
||||
t.equal(msg[0], expected[0], `We reveived the payload: ${msg}`);
|
||||
t.equal(msg[1], expected[1], 'easy as abc');
|
||||
t.ok(Number.isInteger(msg[1]), 'the first value is an int');
|
||||
t.equal(round(msg[2]), expected[2], 'pie please');
|
||||
t.ok(msg[2] % 1 !== 0, 'the second value is a float');
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: boolean', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
|
||||
t.plan(1);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
const m = new Message('/address');
|
||||
m.append(true);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = [
|
||||
'/address',
|
||||
true
|
||||
];
|
||||
t.same(msg, expected, `We reveived the payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: blob', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(1);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
const buf = Buffer.from('test');
|
||||
m.append({
|
||||
type: 'blob',
|
||||
value: buf
|
||||
});
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = [
|
||||
'/address',
|
||||
buf
|
||||
];
|
||||
t.same(msg, expected, `We reveived the payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: Buffer as blob', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(1);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
const buf = Buffer.from('test buffer data');
|
||||
// Directly append Buffer without wrapping in object
|
||||
m.append(buf);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = [
|
||||
'/address',
|
||||
buf
|
||||
];
|
||||
t.same(msg, expected, `We received the buffer payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
// test('message: timetag', (t) => {
|
||||
// const oscServer = new osc.Server(3333, '127.0.0.1');
|
||||
// const client = new osc.Client('127.0.0.1', 3333);
|
||||
// const m = new osc.Message('/address');
|
||||
//
|
||||
// oscServer.on('message', (msg) => {
|
||||
// const expected = [
|
||||
// '/address'
|
||||
// ];
|
||||
// t.same(msg, expected, `We reveived the payload: ${msg}`);
|
||||
// oscServer.close();
|
||||
// t.end();
|
||||
// });
|
||||
//
|
||||
// client.send(m, () => {
|
||||
// client.close();
|
||||
// });
|
||||
// });
|
||||
|
||||
test('message: Buffer with multiple arguments', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(6);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
const buf1 = Buffer.from('first');
|
||||
const buf2 = Buffer.from('second');
|
||||
|
||||
m.append('string');
|
||||
m.append(42);
|
||||
m.append(buf1);
|
||||
m.append(3.14);
|
||||
m.append(buf2);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
t.equal(msg[0], '/address', 'Address matches');
|
||||
t.equal(msg[1], 'string', 'String matches');
|
||||
t.equal(msg[2], 42, 'Integer matches');
|
||||
t.same(msg[3], buf1, 'First buffer matches');
|
||||
t.equal(round(msg[4]), 3.14, 'Float matches');
|
||||
t.same(msg[5], buf2, 'Second buffer matches')
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: Buffer in constructor', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(1);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const buf = Buffer.from('constructor buffer');
|
||||
const m = new Message('/address', 'test', buf, 123);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = [
|
||||
'/address',
|
||||
'test',
|
||||
buf,
|
||||
123
|
||||
];
|
||||
t.same(msg, expected, `We received the constructor buffer payload: ${msg}`);
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: Buffer in array', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(1);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
const buf1 = Buffer.from('array1');
|
||||
const buf2 = Buffer.from('array2');
|
||||
|
||||
m.append([buf1, 'string', buf2, 456]);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = [
|
||||
'/address',
|
||||
buf1,
|
||||
'string',
|
||||
buf2,
|
||||
456
|
||||
];
|
||||
t.same(msg, expected, `We received the array with buffers: ${msg}`);
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: empty Buffer', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(1);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
const buf = Buffer.from('');
|
||||
|
||||
m.append(buf);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
const expected = [
|
||||
'/address',
|
||||
buf
|
||||
];
|
||||
t.same(msg, expected, `We received the empty buffer: ${msg}`);
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: large Buffer', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(4);
|
||||
t.teardown(async () => {
|
||||
await server.close();
|
||||
await client.close();
|
||||
});
|
||||
|
||||
const m = new Message('/address');
|
||||
const buf = Buffer.alloc(1024, 'x');
|
||||
|
||||
m.append(buf);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
t.equal(msg[0], '/address', 'Address matches');
|
||||
t.ok(Buffer.isBuffer(msg[1]), 'Second element is a Buffer');
|
||||
t.equal(msg[1].length, 1024, 'Buffer size matches');
|
||||
t.same(msg[1], buf, 'Buffer content matches');
|
||||
});
|
||||
|
||||
client.send(m);
|
||||
});
|
||||
|
||||
test('message: error', (t) => {
|
||||
const m = new Message('/address');
|
||||
t.plan(2);
|
||||
t.throws(() => {
|
||||
m.append({
|
||||
lol: 'it broken'
|
||||
});
|
||||
}, /don't know how to encode object/);
|
||||
t.throws(() => {
|
||||
m.append(undefined);
|
||||
}, /don't know how to encode/);
|
||||
});
|
||||
1005
backend/node_modules/node-osc/test/test-osc-internal.mjs
generated
vendored
Normal file
1005
backend/node_modules/node-osc/test/test-osc-internal.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
313
backend/node_modules/node-osc/test/test-promises.mjs
generated
vendored
Normal file
313
backend/node_modules/node-osc/test/test-promises.mjs
generated
vendored
Normal file
@ -0,0 +1,313 @@
|
||||
import { once } from 'node:events';
|
||||
import { test } from 'tap';
|
||||
|
||||
import { Server, Client } from 'node-osc';
|
||||
|
||||
test('client: send with promise - array', async (t) => {
|
||||
const server = new Server(0, '127.0.0.1');
|
||||
await once(server, 'listening');
|
||||
const client = new Client('127.0.0.1', server.port);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
server.on('message', (msg) => {
|
||||
server.close();
|
||||
t.same(msg, ['/test', 0, 1, 'testing', true], 'We should receive expected payload');
|
||||
});
|
||||
|
||||
await client.send(['/test', 0, 1, 'testing', true]);
|
||||
await client.close();
|
||||
});
|
||||
|
||||
test('client: array is not mutated when sent with promise', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(2);
|
||||
|
||||
const originalArray = ['/test', 0, 1, 'testing', true];
|
||||
const expectedArray = ['/test', 0, 1, 'testing', true];
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.same(msg, ['/test', 0, 1, 'testing', true], 'We should receive expected payload');
|
||||
});
|
||||
|
||||
await client.send(originalArray);
|
||||
|
||||
// Verify the original array was not mutated
|
||||
t.same(originalArray, expectedArray, 'Original array should not be mutated');
|
||||
|
||||
await client.close();
|
||||
});
|
||||
|
||||
test('client: send with promise - string', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.same(msg, ['/test'], 'We should receive expected payload');
|
||||
});
|
||||
|
||||
await client.send('/test');
|
||||
await client.close();
|
||||
});
|
||||
|
||||
test('client: send with promise - message object', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.same(msg, ['/test', 1, 2, 3, 'lol', false], 'we received the payload');
|
||||
});
|
||||
|
||||
await client.send({
|
||||
address: '/test',
|
||||
args: [1, 2, 3, 'lol', false]
|
||||
});
|
||||
await client.close();
|
||||
});
|
||||
|
||||
test('client: send with promise - multiple args', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
oscServer.on('message', (msg) => {
|
||||
oscServer.close();
|
||||
t.same(msg, ['/test', 1, 2, 'testing'], 'We should receive expected payload');
|
||||
});
|
||||
|
||||
await client.send('/test', 1, 2, 'testing');
|
||||
await client.close();
|
||||
});
|
||||
|
||||
test('client: send promise rejection on closed socket', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
await client.close();
|
||||
await oscServer.close();
|
||||
|
||||
try {
|
||||
await client.send('/boom');
|
||||
t.fail('Should have thrown an error');
|
||||
} catch (err) {
|
||||
t.equal(err.code, 'ERR_SOCKET_DGRAM_NOT_RUNNING', 'Should reject with correct error code');
|
||||
}
|
||||
});
|
||||
|
||||
test('client: async/await usage', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
const messagePromise = once(oscServer, 'message');
|
||||
|
||||
await client.send('/async-test', 42, 'hello');
|
||||
const [receivedMessage] = await messagePromise;
|
||||
|
||||
t.same(receivedMessage, ['/async-test', 42, 'hello'], 'Message received via async/await');
|
||||
|
||||
await client.close();
|
||||
await oscServer.close();
|
||||
});
|
||||
|
||||
test('server: close with promise', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
|
||||
t.plan(1);
|
||||
|
||||
await once(oscServer, 'listening');
|
||||
|
||||
await oscServer.close();
|
||||
t.pass('Server closed successfully with promise');
|
||||
});
|
||||
|
||||
test('server: no callback still emits listening event', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
|
||||
t.plan(1);
|
||||
|
||||
await once(oscServer, 'listening');
|
||||
t.pass('listening event emitted');
|
||||
|
||||
await oscServer.close();
|
||||
});
|
||||
|
||||
test('client and server: full async/await workflow', async (t) => {
|
||||
t.plan(3);
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
|
||||
// Wait for server to be ready
|
||||
await once(oscServer, 'listening');
|
||||
t.pass('Server started');
|
||||
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
t.pass('Client created');
|
||||
|
||||
// Set up message handler
|
||||
const messageReceived = once(oscServer, 'message');
|
||||
|
||||
// Send message and wait for it to be received
|
||||
await client.send('/workflow', 'test', 123);
|
||||
const [msg] = await messageReceived;
|
||||
t.same(msg, ['/workflow', 'test', 123], 'Message received correctly');
|
||||
|
||||
// Clean up
|
||||
await client.close();
|
||||
await oscServer.close();
|
||||
});
|
||||
|
||||
test('client: multiple sends with promises', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
t.plan(3);
|
||||
|
||||
const messages = [];
|
||||
oscServer.on('message', (msg) => {
|
||||
messages.push(msg);
|
||||
});
|
||||
|
||||
await client.send('/msg1', 1);
|
||||
await client.send('/msg2', 2);
|
||||
await client.send('/msg3', 3);
|
||||
|
||||
// Give a little time for all messages to be received
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
t.equal(messages.length, 3, 'Received all three messages');
|
||||
t.same(messages[0], ['/msg1', 1], 'First message correct');
|
||||
t.same(messages[2], ['/msg3', 3], 'Last message correct');
|
||||
|
||||
await client.close();
|
||||
await oscServer.close();
|
||||
});
|
||||
|
||||
test('client: close promise rejection on error', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', t.context.port);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
// Mock the socket's close method to simulate an error
|
||||
const originalClose = client._sock.close.bind(client._sock);
|
||||
|
||||
// Set up teardown to ensure socket is properly closed
|
||||
t.teardown(() => {
|
||||
// Restore original close method first
|
||||
client._sock.close = originalClose;
|
||||
// Then close the socket
|
||||
try {
|
||||
client._sock.close(() => {});
|
||||
} catch {
|
||||
// Socket might already be closed, that's ok
|
||||
}
|
||||
});
|
||||
|
||||
client._sock.close = function(cb) {
|
||||
// Simulate an error being passed to callback
|
||||
if (cb) {
|
||||
const err = new Error('Mock close error');
|
||||
err.code = 'MOCK_ERROR';
|
||||
setImmediate(() => cb(err));
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
await oscServer.close();
|
||||
await client.close();
|
||||
t.fail('Should have thrown an error');
|
||||
} catch (err) {
|
||||
t.equal(err.code, 'MOCK_ERROR', 'Should reject with mock error');
|
||||
}
|
||||
});
|
||||
|
||||
test('server: close promise rejection on error', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
|
||||
t.plan(1);
|
||||
|
||||
await once(oscServer, 'listening');
|
||||
|
||||
// Mock the socket's close method to simulate an error
|
||||
const originalClose = oscServer._sock.close.bind(oscServer._sock);
|
||||
|
||||
// Set up teardown to ensure socket is properly closed
|
||||
t.teardown(() => {
|
||||
// Restore original close method first
|
||||
oscServer._sock.close = originalClose;
|
||||
// Then close the socket
|
||||
try {
|
||||
oscServer._sock.close(() => {});
|
||||
} catch {
|
||||
// Socket might already be closed, that's ok
|
||||
}
|
||||
});
|
||||
|
||||
oscServer._sock.close = function(cb) {
|
||||
// Simulate an error being passed to callback
|
||||
if (cb) {
|
||||
const err = new Error('Mock close error');
|
||||
err.code = 'MOCK_ERROR';
|
||||
setImmediate(() => cb(err));
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
await oscServer.close();
|
||||
t.fail('Should have thrown an error');
|
||||
} catch (err) {
|
||||
t.equal(err.code, 'MOCK_ERROR', 'Should reject with mock error');
|
||||
}
|
||||
});
|
||||
|
||||
test('client: send promise rejection on send error', async (t) => {
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
const client = new Client('127.0.0.1', oscServer.port);
|
||||
|
||||
t.plan(1);
|
||||
|
||||
// Mock the socket's send method to simulate an error
|
||||
const originalSend = client._sock.send;
|
||||
client._sock.send = function(msg, offset, length, port, address, callback) {
|
||||
// Simulate an error being passed to callback
|
||||
const err = new Error('Mock send error');
|
||||
err.code = 'MOCK_SEND_ERROR';
|
||||
if (callback) {
|
||||
setImmediate(() => callback(err));
|
||||
}
|
||||
};
|
||||
|
||||
t.teardown(async () => {
|
||||
client._sock.send = originalSend;
|
||||
await client.close();
|
||||
await oscServer.close();
|
||||
});
|
||||
|
||||
try {
|
||||
await client.send('/test', 'data');
|
||||
t.fail('Should have thrown an error');
|
||||
} catch (err) {
|
||||
t.equal(err.code, 'MOCK_SEND_ERROR', 'Should reject with mock send error');
|
||||
}
|
||||
});
|
||||
101
backend/node_modules/node-osc/test/test-server.mjs
generated
vendored
Normal file
101
backend/node_modules/node-osc/test/test-server.mjs
generated
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
import { once } from 'node:events';
|
||||
import { test } from 'tap';
|
||||
|
||||
import { Server, Client } from 'node-osc';
|
||||
|
||||
test('server: create and close', async (t) => {
|
||||
t.plan(1);
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
oscServer.close((err) => {
|
||||
t.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('server: listen to message', async (t) => {
|
||||
const oscServer = new Server(0);
|
||||
await once(oscServer, 'listening');
|
||||
const client = new 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');
|
||||
});
|
||||
});
|
||||
|
||||
test('server: no defined host', async (t) => {
|
||||
const oscServer = new Server(0);
|
||||
await once(oscServer, 'listening');
|
||||
const client = new 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');
|
||||
});
|
||||
});
|
||||
|
||||
test('server: callback as second arg', async (t) => {
|
||||
t.plan(4);
|
||||
const oscServer = new Server(0, () => {
|
||||
t.ok('callback called');
|
||||
});
|
||||
await once(oscServer, 'listening');
|
||||
const client = new 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');
|
||||
});
|
||||
});
|
||||
|
||||
test('server: bad message', async (t) => {
|
||||
t.plan(2);
|
||||
const oscServer = new Server(0, '127.0.0.1');
|
||||
await once(oscServer, 'listening');
|
||||
t.throws(() => {
|
||||
oscServer._sock.emit('message', 'whoops');
|
||||
}, /can't decode incoming message:/);
|
||||
oscServer.close((err) => {
|
||||
t.error(err);
|
||||
});
|
||||
});
|
||||
39
backend/node_modules/node-osc/test/test-types.mjs
generated
vendored
Normal file
39
backend/node_modules/node-osc/test/test-types.mjs
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
import { test } from 'tap';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
|
||||
// Only run in ESM mode (not when transpiled to CJS in dist/)
|
||||
// Normalize path separators for cross-platform compatibility
|
||||
const normalizedPath = __dirname.replace(/\\/g, '/');
|
||||
const isESM = !normalizedPath.includes('/dist/');
|
||||
|
||||
test('types: TypeScript compilation', (t) => {
|
||||
let tsconfigPath;
|
||||
const testRoot = resolve(__dirname, isESM ? '.': '../../test');
|
||||
if (isESM) {
|
||||
tsconfigPath = join(testRoot, 'fixtures', 'types', 'tsconfig-esm.test.json');
|
||||
}
|
||||
else {
|
||||
tsconfigPath = join(testRoot, 'fixtures', 'types', 'tsconfig-cjs.test.json');
|
||||
}
|
||||
|
||||
try {
|
||||
// Run TypeScript compiler
|
||||
const cmd = 'npx tsc --project "' + tsconfigPath + '"';
|
||||
execSync(cmd, {
|
||||
encoding: 'utf-8',
|
||||
stdio: 'pipe',
|
||||
cwd: join(testRoot, 'fixtures', 'types')
|
||||
});
|
||||
t.pass('TypeScript types compile successfully');
|
||||
} catch (error) {
|
||||
t.fail('TypeScript compilation failed: ' + error.message);
|
||||
if (error.stdout) console.log('STDOUT:', error.stdout);
|
||||
if (error.stderr) console.log('STDERR:', error.stderr);
|
||||
}
|
||||
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user