node-osc 11.2.0 → 11.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.github/workflows/bump-version.yml +3 -3
  2. package/.github/workflows/create-release.yml +4 -4
  3. package/.github/workflows/nodejs.yml +4 -4
  4. package/README.md +3 -2
  5. package/agent.md +330 -0
  6. package/dist/lib/Client.js +1 -1
  7. package/dist/lib/Message.js +3 -1
  8. package/dist/lib/Server.js +7 -12
  9. package/dist/lib/internal/decode.js +3 -1
  10. package/dist/lib/osc.js +32 -3
  11. package/dist/test/lib/osc.js +32 -3
  12. package/dist/test/test-bundle.js +13 -12
  13. package/dist/test/test-client.js +68 -37
  14. package/dist/test/test-decode.js +35 -0
  15. package/dist/test/test-e2e.js +9 -9
  16. package/dist/test/test-encode-decode.js +455 -0
  17. package/dist/test/test-error-handling.js +14 -13
  18. package/dist/test/test-message.js +261 -64
  19. package/dist/test/test-osc-internal.js +151 -0
  20. package/dist/test/test-promises.js +90 -26
  21. package/dist/test/test-server.js +19 -16
  22. package/docs/README.md +81 -0
  23. package/examples/README.md +3 -1
  24. package/lib/Client.mjs +1 -1
  25. package/lib/Message.mjs +3 -1
  26. package/lib/Server.mjs +7 -12
  27. package/lib/internal/decode.mjs +3 -1
  28. package/lib/osc.mjs +32 -3
  29. package/package.json +2 -2
  30. package/rollup.config.mjs +1 -0
  31. package/test/test-bundle.mjs +14 -13
  32. package/test/test-client.mjs +69 -38
  33. package/test/test-decode.mjs +35 -0
  34. package/test/test-e2e.mjs +10 -10
  35. package/test/test-encode-decode.mjs +455 -0
  36. package/test/test-error-handling.mjs +15 -14
  37. package/test/test-message.mjs +262 -66
  38. package/test/test-osc-internal.mjs +151 -0
  39. package/test/test-promises.mjs +91 -27
  40. package/test/test-server.mjs +20 -17
  41. package/types/Message.d.mts.map +1 -1
  42. package/types/Server.d.mts.map +1 -1
  43. package/types/internal/decode.d.mts.map +1 -1
  44. package/types/osc.d.mts.map +1 -1
  45. package/dist/test/test-getPort.js +0 -20
  46. package/dist/test/util.js +0 -34
  47. package/test/test-getPort.mjs +0 -18
  48. package/test/util.mjs +0 -34
@@ -295,6 +295,102 @@ tap.test('decode: error on malformed type tags (no leading comma)', (t) => {
295
295
  t.end();
296
296
  });
297
297
 
298
+ tap.test('decode: error on truncated blob data', (t) => {
299
+ const addressBuf = Buffer.from('/b\0\0', 'ascii');
300
+ const typeTagsBuf = Buffer.from(',b\0\0', 'ascii');
301
+ const lengthBuf = Buffer.alloc(4);
302
+ lengthBuf.writeInt32BE(4, 0);
303
+ const dataBuf = Buffer.from([0x01, 0x02]);
304
+ const buffer = Buffer.concat([addressBuf, typeTagsBuf, lengthBuf, dataBuf]);
305
+
306
+ t.throws(() => {
307
+ nodeOsc.decode(buffer);
308
+ }, /Malformed Packet: Not enough bytes for blob/, 'should throw when blob data is truncated');
309
+
310
+ t.end();
311
+ });
312
+
313
+ tap.test('decode: error on missing blob padding', (t) => {
314
+ const addressBuf = Buffer.from('/b\0\0', 'ascii');
315
+ const typeTagsBuf = Buffer.from(',b\0\0', 'ascii');
316
+ const lengthBuf = Buffer.alloc(4);
317
+ lengthBuf.writeInt32BE(3, 0);
318
+ const dataBuf = Buffer.from([0x01, 0x02, 0x03]);
319
+ const buffer = Buffer.concat([addressBuf, typeTagsBuf, lengthBuf, dataBuf]);
320
+
321
+ t.throws(() => {
322
+ nodeOsc.decode(buffer);
323
+ }, /Malformed Packet: Not enough bytes for blob padding/, 'should throw when blob padding is missing');
324
+
325
+ t.end();
326
+ });
327
+
328
+ tap.test('decode: error on truncated float32', (t) => {
329
+ const addressBuf = Buffer.from('/f\0\0', 'ascii');
330
+ const typeTagsBuf = Buffer.from(',f\0\0', 'ascii');
331
+ const dataBuf = Buffer.from([0x3f, 0x80, 0x00]);
332
+ const buffer = Buffer.concat([addressBuf, typeTagsBuf, dataBuf]);
333
+
334
+ t.throws(() => {
335
+ nodeOsc.decode(buffer);
336
+ }, /Malformed Packet: Not enough bytes for float32/, 'should throw when float32 data is truncated');
337
+
338
+ t.end();
339
+ });
340
+
341
+ tap.test('decode: error on truncated int32', (t) => {
342
+ const addressBuf = Buffer.from('/i\0\0', 'ascii');
343
+ const typeTagsBuf = Buffer.from(',i\0\0', 'ascii');
344
+ const dataBuf = Buffer.from([0x00, 0x01]);
345
+ const buffer = Buffer.concat([addressBuf, typeTagsBuf, dataBuf]);
346
+
347
+ t.throws(() => {
348
+ nodeOsc.decode(buffer);
349
+ }, /Malformed Packet: Not enough bytes for int32/, 'should throw when int32 data is truncated');
350
+
351
+ t.end();
352
+ });
353
+
354
+ tap.test('decode: error on negative blob length', (t) => {
355
+ const addressBuf = Buffer.from('/b\0\0', 'ascii');
356
+ const typeTagsBuf = Buffer.from(',b\0\0', 'ascii');
357
+ const lengthBuf = Buffer.alloc(4);
358
+ lengthBuf.writeInt32BE(-1, 0);
359
+ const buffer = Buffer.concat([addressBuf, typeTagsBuf, lengthBuf]);
360
+
361
+ t.throws(() => {
362
+ nodeOsc.decode(buffer);
363
+ }, /Malformed Packet: Invalid blob length/, 'should throw when blob length is negative');
364
+
365
+ t.end();
366
+ });
367
+
368
+ tap.test('decode: error on bundle element size overflow', (t) => {
369
+ const bundleHeader = Buffer.from('#bundle\0', 'ascii');
370
+ const timetag = Buffer.alloc(8);
371
+ const sizeBuf = Buffer.alloc(4);
372
+ sizeBuf.writeInt32BE(0, 0);
373
+ const buffer = Buffer.concat([bundleHeader, timetag, sizeBuf]);
374
+
375
+ t.throws(() => {
376
+ nodeOsc.decode(buffer);
377
+ }, /Malformed Packet/, 'should throw when bundle element size is invalid');
378
+
379
+ t.end();
380
+ });
381
+
382
+ tap.test('decode: error on truncated bundle timetag', (t) => {
383
+ const bundleHeader = Buffer.from('#bundle\0', 'ascii');
384
+ const timetag = Buffer.alloc(4);
385
+ const buffer = Buffer.concat([bundleHeader, timetag]);
386
+
387
+ t.throws(() => {
388
+ nodeOsc.decode(buffer);
389
+ }, /Malformed Packet: Not enough bytes for timetag/, 'should throw when timetag is truncated');
390
+
391
+ t.end();
392
+ });
393
+
298
394
  tap.test('encode and decode: nested bundle with message and bundle elements', (t) => {
299
395
  // Test the else branch in encodeBundleToBuffer for message elements
300
396
  const innerBundle = new nodeOsc.Bundle(['/inner/message', 123]);
@@ -847,3 +943,362 @@ tap.test('encode and decode: type "boolean" with false value', (t) => {
847
943
  t.equal(decoded.args[0].value, false);
848
944
  t.end();
849
945
  });
946
+
947
+ // Tests for UTF-8 string padding to 4-byte boundaries
948
+ // The padString function ensures OSC strings are padded based on byte length
949
+ // (not character count) to handle multi-byte UTF-8 correctly
950
+
951
+ tap.test('encode and decode: UTF-8 string padding - ASCII 1 char', (t) => {
952
+ // 1 byte + 1 null terminator = 2 bytes, needs 2 padding bytes to reach 4-byte boundary
953
+ const message = {
954
+ oscType: 'message',
955
+ address: '/test',
956
+ args: [{ type: 'string', value: 'a' }]
957
+ };
958
+
959
+ const buffer = nodeOsc.encode(message);
960
+ const decoded = nodeOsc.decode(buffer);
961
+
962
+ t.equal(decoded.args[0].value, 'a', 'should correctly encode and decode single ASCII character');
963
+
964
+ // Verify the string is properly padded in the buffer
965
+ // Address "/test" is 5 bytes + 1 null = 6 bytes, padded to 8 bytes
966
+ // Type tag ",s" is 2 bytes + 1 null = 3 bytes, padded to 4 bytes
967
+ // String "a" is 1 byte + 1 null = 2 bytes, padded to 4 bytes
968
+ const expectedMinLength = 8 + 4 + 4; // 16 bytes minimum
969
+ t.ok(buffer.length >= expectedMinLength, 'buffer should contain properly padded string');
970
+
971
+ t.end();
972
+ });
973
+
974
+ tap.test('encode and decode: UTF-8 string padding - ASCII 2 chars', (t) => {
975
+ // 2 bytes + 1 null = 3 bytes, needs 1 padding byte to reach 4-byte boundary
976
+ const message = {
977
+ oscType: 'message',
978
+ address: '/test',
979
+ args: [{ type: 'string', value: 'ab' }]
980
+ };
981
+
982
+ const buffer = nodeOsc.encode(message);
983
+ const decoded = nodeOsc.decode(buffer);
984
+
985
+ t.equal(decoded.args[0].value, 'ab', 'should correctly encode and decode 2-byte string');
986
+ t.end();
987
+ });
988
+
989
+ tap.test('encode and decode: UTF-8 string padding - ASCII 3 chars', (t) => {
990
+ // 3 bytes + 1 null terminator = 4 bytes, needs 0 padding (already aligned)
991
+ const message = {
992
+ oscType: 'message',
993
+ address: '/test',
994
+ args: [{ type: 'string', value: 'abc' }]
995
+ };
996
+
997
+ const buffer = nodeOsc.encode(message);
998
+ const decoded = nodeOsc.decode(buffer);
999
+
1000
+ t.equal(decoded.args[0].value, 'abc', 'should correctly encode and decode 3-char ASCII string');
1001
+ t.end();
1002
+ });
1003
+
1004
+ tap.test('encode and decode: UTF-8 string padding - ASCII 5 chars', (t) => {
1005
+ // 5 bytes + 1 null terminator = 6 bytes, needs 2 padding bytes to reach 8-byte boundary
1006
+ const message = {
1007
+ oscType: 'message',
1008
+ address: '/test',
1009
+ args: [{ type: 'string', value: 'hello' }]
1010
+ };
1011
+
1012
+ const buffer = nodeOsc.encode(message);
1013
+ const decoded = nodeOsc.decode(buffer);
1014
+
1015
+ t.equal(decoded.args[0].value, 'hello', 'should correctly encode and decode 5-char ASCII string');
1016
+ t.end();
1017
+ });
1018
+
1019
+ tap.test('encode and decode: UTF-8 string padding - ASCII 6 chars', (t) => {
1020
+ // 6 bytes + 1 null = 7 bytes, needs 1 padding byte to reach 8-byte boundary
1021
+ const message = {
1022
+ oscType: 'message',
1023
+ address: '/test',
1024
+ args: [{ type: 'string', value: 'abcdef' }]
1025
+ };
1026
+
1027
+ const buffer = nodeOsc.encode(message);
1028
+ const decoded = nodeOsc.decode(buffer);
1029
+
1030
+ t.equal(decoded.args[0].value, 'abcdef', 'should correctly encode and decode 6-byte string');
1031
+ t.end();
1032
+ });
1033
+
1034
+ tap.test('encode and decode: UTF-8 string padding - ASCII 7 chars', (t) => {
1035
+ // 7 bytes + 1 null terminator = 8 bytes, needs 0 padding (already aligned)
1036
+ const message = {
1037
+ oscType: 'message',
1038
+ address: '/test',
1039
+ args: [{ type: 'string', value: 'testing' }]
1040
+ };
1041
+
1042
+ const buffer = nodeOsc.encode(message);
1043
+ const decoded = nodeOsc.decode(buffer);
1044
+
1045
+ t.equal(decoded.args[0].value, 'testing', 'should correctly encode and decode 7-char ASCII string');
1046
+ t.end();
1047
+ });
1048
+
1049
+ tap.test('encode and decode: UTF-8 string padding - empty string', (t) => {
1050
+ // 0 bytes + 1 null terminator = 1 byte, needs 3 padding bytes to reach 4-byte boundary
1051
+ const message = {
1052
+ oscType: 'message',
1053
+ address: '/test',
1054
+ args: [{ type: 'string', value: '' }]
1055
+ };
1056
+
1057
+ const buffer = nodeOsc.encode(message);
1058
+ const decoded = nodeOsc.decode(buffer);
1059
+
1060
+ t.equal(decoded.args[0].value, '', 'should correctly encode and decode empty string');
1061
+ t.end();
1062
+ });
1063
+
1064
+ tap.test('encode and decode: UTF-8 string padding - emoji character', (t) => {
1065
+ // Emoji '😀' is 4 bytes in UTF-8 + 1 null = 5 bytes, needs 3 padding to reach 8-byte boundary
1066
+ const message = {
1067
+ oscType: 'message',
1068
+ address: '/test',
1069
+ args: [{ type: 'string', value: '😀' }]
1070
+ };
1071
+
1072
+ const buffer = nodeOsc.encode(message);
1073
+ const decoded = nodeOsc.decode(buffer);
1074
+
1075
+ t.equal(decoded.args[0].value, '😀', 'should correctly encode and decode emoji character');
1076
+
1077
+ // Verify byte length calculation is correct
1078
+ const emojiByteLength = Buffer.byteLength('😀');
1079
+ t.equal(emojiByteLength, 4, 'emoji should be 4 bytes in UTF-8');
1080
+
1081
+ t.end();
1082
+ });
1083
+
1084
+ tap.test('encode and decode: UTF-8 string padding - Japanese character', (t) => {
1085
+ // Japanese 'あ' is 3 bytes in UTF-8 + 1 null = 4 bytes, needs 0 padding (already aligned)
1086
+ const message = {
1087
+ oscType: 'message',
1088
+ address: '/test',
1089
+ args: [{ type: 'string', value: 'あ' }]
1090
+ };
1091
+
1092
+ const buffer = nodeOsc.encode(message);
1093
+ const decoded = nodeOsc.decode(buffer);
1094
+
1095
+ t.equal(decoded.args[0].value, 'あ', 'should correctly encode and decode Japanese character');
1096
+
1097
+ const japaneseByteLength = Buffer.byteLength('あ');
1098
+ t.equal(japaneseByteLength, 3, 'Japanese character should be 3 bytes in UTF-8');
1099
+
1100
+ t.end();
1101
+ });
1102
+
1103
+ tap.test('encode and decode: UTF-8 string padding - Chinese character', (t) => {
1104
+ // Chinese '中' is 3 bytes in UTF-8 + 1 null = 4 bytes, needs 0 padding (already aligned)
1105
+ const message = {
1106
+ oscType: 'message',
1107
+ address: '/test',
1108
+ args: [{ type: 'string', value: '中' }]
1109
+ };
1110
+
1111
+ const buffer = nodeOsc.encode(message);
1112
+ const decoded = nodeOsc.decode(buffer);
1113
+
1114
+ t.equal(decoded.args[0].value, '中', 'should correctly encode and decode Chinese character');
1115
+ t.end();
1116
+ });
1117
+
1118
+ tap.test('encode and decode: UTF-8 string padding - mixed ASCII and emoji', (t) => {
1119
+ // 'a' (1 byte) + '😀' (4 bytes) + 'b' (1 byte) = 6 bytes + 1 null = 7 bytes
1120
+ // needs 1 padding byte to reach 8-byte boundary
1121
+ const message = {
1122
+ oscType: 'message',
1123
+ address: '/test',
1124
+ args: [{ type: 'string', value: 'a😀b' }]
1125
+ };
1126
+
1127
+ const buffer = nodeOsc.encode(message);
1128
+ const decoded = nodeOsc.decode(buffer);
1129
+
1130
+ t.equal(decoded.args[0].value, 'a😀b', 'should correctly encode and decode mixed ASCII and emoji');
1131
+
1132
+ const mixedByteLength = Buffer.byteLength('a😀b');
1133
+ t.equal(mixedByteLength, 6, 'mixed string should be 6 bytes in UTF-8');
1134
+
1135
+ t.end();
1136
+ });
1137
+
1138
+ tap.test('encode and decode: UTF-8 string padding - Japanese string', (t) => {
1139
+ // 'こんにちは' (Hello in Japanese) - 5 characters, each 3 bytes = 15 bytes
1140
+ // 15 bytes + 1 null = 16 bytes, needs 0 padding (already aligned)
1141
+ const message = {
1142
+ oscType: 'message',
1143
+ address: '/test',
1144
+ args: [{ type: 'string', value: 'こんにちは' }]
1145
+ };
1146
+
1147
+ const buffer = nodeOsc.encode(message);
1148
+ const decoded = nodeOsc.decode(buffer);
1149
+
1150
+ t.equal(decoded.args[0].value, 'こんにちは', 'should correctly encode and decode Japanese string');
1151
+
1152
+ const japaneseStringByteLength = Buffer.byteLength('こんにちは');
1153
+ t.equal(japaneseStringByteLength, 15, 'Japanese string should be 15 bytes in UTF-8');
1154
+
1155
+ t.end();
1156
+ });
1157
+
1158
+ tap.test('encode and decode: UTF-8 string padding - accented characters', (t) => {
1159
+ // 'café' - 4 characters but 'é' is 2 bytes in UTF-8
1160
+ // 'c' (1) + 'a' (1) + 'f' (1) + 'é' (2) = 5 bytes + 1 null = 6 bytes
1161
+ // needs 2 padding bytes to reach 8-byte boundary
1162
+ const message = {
1163
+ oscType: 'message',
1164
+ address: '/test',
1165
+ args: [{ type: 'string', value: 'café' }]
1166
+ };
1167
+
1168
+ const buffer = nodeOsc.encode(message);
1169
+ const decoded = nodeOsc.decode(buffer);
1170
+
1171
+ t.equal(decoded.args[0].value, 'café', 'should correctly encode and decode accented string');
1172
+
1173
+ const accentedByteLength = Buffer.byteLength('café');
1174
+ t.equal(accentedByteLength, 5, 'café should be 5 bytes in UTF-8');
1175
+
1176
+ t.end();
1177
+ });
1178
+
1179
+ tap.test('encode and decode: UTF-8 string padding - multiple strings', (t) => {
1180
+ // Test multiple strings with different byte lengths in one message
1181
+ const message = {
1182
+ oscType: 'message',
1183
+ address: '/multi',
1184
+ args: [
1185
+ { type: 'string', value: 'a' }, // 1 byte + null
1186
+ { type: 'string', value: '😀' }, // 4 bytes + null
1187
+ { type: 'string', value: 'abc' }, // 3 bytes + null
1188
+ { type: 'string', value: '' } // 0 bytes + null
1189
+ ]
1190
+ };
1191
+
1192
+ const buffer = nodeOsc.encode(message);
1193
+ const decoded = nodeOsc.decode(buffer);
1194
+
1195
+ t.equal(decoded.args.length, 4, 'should have 4 arguments');
1196
+ t.equal(decoded.args[0].value, 'a', 'first string should be correct');
1197
+ t.equal(decoded.args[1].value, '😀', 'second string should be correct');
1198
+ t.equal(decoded.args[2].value, 'abc', 'third string should be correct');
1199
+ t.equal(decoded.args[3].value, '', 'fourth string should be correct');
1200
+
1201
+ t.end();
1202
+ });
1203
+
1204
+ tap.test('encode and decode: UTF-8 string padding - address with emoji', (t) => {
1205
+ // OSC addresses can also contain UTF-8 characters and must be properly padded
1206
+ const message = {
1207
+ oscType: 'message',
1208
+ address: '/test/😀',
1209
+ args: [{ type: 'string', value: 'data' }]
1210
+ };
1211
+
1212
+ const buffer = nodeOsc.encode(message);
1213
+ const decoded = nodeOsc.decode(buffer);
1214
+
1215
+ t.equal(decoded.address, '/test/😀', 'should correctly encode and decode address with emoji');
1216
+ t.equal(decoded.args[0].value, 'data', 'should correctly encode and decode argument');
1217
+
1218
+ t.end();
1219
+ });
1220
+
1221
+ tap.test('encode and decode: UTF-8 string padding - long mixed string', (t) => {
1222
+ // Test a longer string with mixed content
1223
+ const longString = 'Hello 世界 🌍! Testing UTF-8 encoding with café and naïve.';
1224
+ const message = {
1225
+ oscType: 'message',
1226
+ address: '/test',
1227
+ args: [{ type: 'string', value: longString }]
1228
+ };
1229
+
1230
+ const buffer = nodeOsc.encode(message);
1231
+ const decoded = nodeOsc.decode(buffer);
1232
+
1233
+ t.equal(decoded.args[0].value, longString, 'should correctly encode and decode long mixed UTF-8 string');
1234
+
1235
+ t.end();
1236
+ });
1237
+
1238
+ tap.test('encode and decode: UTF-8 string padding - special characters', (t) => {
1239
+ // Test various special characters that may have different byte lengths
1240
+ const specialChars = '!@#$%^&*()_+-=[]{}|;:,.<>?/~`';
1241
+ const message = {
1242
+ oscType: 'message',
1243
+ address: '/test',
1244
+ args: [{ type: 'string', value: specialChars }]
1245
+ };
1246
+
1247
+ const buffer = nodeOsc.encode(message);
1248
+ const decoded = nodeOsc.decode(buffer);
1249
+
1250
+ t.equal(decoded.args[0].value, specialChars, 'should correctly encode and decode special ASCII characters');
1251
+ t.end();
1252
+ });
1253
+
1254
+ tap.test('encode and decode: UTF-8 string padding - control characters', (t) => {
1255
+ // Test control characters
1256
+ const controlChars = 'line1\nline2\ttab';
1257
+ const message = {
1258
+ oscType: 'message',
1259
+ address: '/test',
1260
+ args: [{ type: 'string', value: controlChars }]
1261
+ };
1262
+
1263
+ const buffer = nodeOsc.encode(message);
1264
+ const decoded = nodeOsc.decode(buffer);
1265
+
1266
+ t.equal(decoded.args[0].value, controlChars, 'should correctly encode and decode strings with newlines and tabs');
1267
+ t.end();
1268
+ });
1269
+
1270
+ tap.test('encode and decode: UTF-8 string padding - surrogate pairs', (t) => {
1271
+ // Test various emoji that are 4-byte UTF-8 sequences
1272
+ const emojis = '🎉🎊🎈🎁';
1273
+ const message = {
1274
+ oscType: 'message',
1275
+ address: '/test',
1276
+ args: [{ type: 'string', value: emojis }]
1277
+ };
1278
+
1279
+ const buffer = nodeOsc.encode(message);
1280
+ const decoded = nodeOsc.decode(buffer);
1281
+
1282
+ t.equal(decoded.args[0].value, emojis, 'should correctly encode and decode multiple 4-byte emoji');
1283
+
1284
+ const emojisByteLength = Buffer.byteLength(emojis);
1285
+ t.equal(emojisByteLength, 16, 'four 4-byte emoji should total 16 bytes');
1286
+
1287
+ t.end();
1288
+ });
1289
+
1290
+ tap.test('encode and decode: UTF-8 string padding - zero-width characters', (t) => {
1291
+ // Test zero-width joiner and other special Unicode characters
1292
+ const zwj = 'a\u200Db'; // zero-width joiner
1293
+ const message = {
1294
+ oscType: 'message',
1295
+ address: '/test',
1296
+ args: [{ type: 'string', value: zwj }]
1297
+ };
1298
+
1299
+ const buffer = nodeOsc.encode(message);
1300
+ const decoded = nodeOsc.decode(buffer);
1301
+
1302
+ t.equal(decoded.args[0].value, zwj, 'should correctly encode and decode strings with zero-width characters');
1303
+ t.end();
1304
+ });
@@ -1,14 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ var node_events = require('node:events');
3
4
  var tap = require('tap');
4
- var util = require('./util.js');
5
5
  var nodeOsc = require('node-osc');
6
6
 
7
- tap.beforeEach(util.bootstrap);
8
-
9
- tap.test('server: socket error event is emitted', (t) => {
7
+ tap.test('server: socket error event is emitted', async (t) => {
10
8
  t.plan(1);
11
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
9
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
10
+ await node_events.once(oscServer, 'listening');
12
11
 
13
12
  oscServer.on('error', (err) => {
14
13
  t.ok(err, 'error event should be emitted');
@@ -19,9 +18,10 @@ tap.test('server: socket error event is emitted', (t) => {
19
18
  oscServer._sock.emit('error', new Error('test socket error'));
20
19
  });
21
20
 
22
- tap.test('server: error listener can be added before listening', (t) => {
21
+ tap.test('server: error listener can be added before listening', async (t) => {
23
22
  t.plan(2);
24
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
23
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
24
+ await node_events.once(oscServer, 'listening');
25
25
 
26
26
  oscServer.on('error', (err) => {
27
27
  t.ok(err, 'error event should be emitted');
@@ -38,7 +38,7 @@ tap.test('server: error listener can be added before listening', (t) => {
38
38
 
39
39
  tap.test('client: socket error event is emitted', (t) => {
40
40
  t.plan(1);
41
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
41
+ const client = new nodeOsc.Client('127.0.0.1', 9999);
42
42
 
43
43
  client.on('error', (err) => {
44
44
  t.ok(err, 'error event should be emitted');
@@ -51,7 +51,7 @@ tap.test('client: socket error event is emitted', (t) => {
51
51
 
52
52
  tap.test('client: error listener can be added at construction', (t) => {
53
53
  t.plan(2);
54
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
54
+ const client = new nodeOsc.Client('127.0.0.1', 9999);
55
55
 
56
56
  client.on('error', (err) => {
57
57
  t.ok(err, 'error event should be emitted');
@@ -68,16 +68,17 @@ tap.test('client: error listener can be added at construction', (t) => {
68
68
 
69
69
  tap.test('client: is an EventEmitter instance', (t) => {
70
70
  t.plan(1);
71
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
71
+ const client = new nodeOsc.Client('127.0.0.1', 9999);
72
72
 
73
73
  t.ok(typeof client.on === 'function', 'client should have EventEmitter methods');
74
74
 
75
75
  client.close();
76
76
  });
77
77
 
78
- tap.test('server: multiple error listeners can be attached', (t) => {
78
+ tap.test('server: multiple error listeners can be attached', async (t) => {
79
79
  t.plan(2);
80
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
80
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
81
+ await node_events.once(oscServer, 'listening');
81
82
 
82
83
  oscServer.on('error', (err) => {
83
84
  t.ok(err, 'first listener should receive error');
@@ -97,7 +98,7 @@ tap.test('server: multiple error listeners can be attached', (t) => {
97
98
 
98
99
  tap.test('client: multiple error listeners can be attached', (t) => {
99
100
  t.plan(2);
100
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
101
+ const client = new nodeOsc.Client('127.0.0.1', 9999);
101
102
 
102
103
  client.on('error', (err) => {
103
104
  t.ok(err, 'first listener should receive error');