0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-quic-internal-setcallbacks.js
James M Snell cdae315706 quic: start adding in the internal quic js api
While the external API for QUIC is expected to be
the WebTransport API primarily, this provides the
internal API for QUIC that aligns with the native
C++ QUIC components.

PR-URL: https://github.com/nodejs/node/pull/53256
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2024-09-29 11:41:03 -07:00

48 lines
1.3 KiB
JavaScript

// Flags: --expose-internals --no-warnings
'use strict';
const { hasQuic } = require('../common');
const {
describe,
it,
} = require('node:test');
describe('quic internal setCallbacks', { skip: !hasQuic }, () => {
const { internalBinding } = require('internal/test/binding');
const quic = internalBinding('quic');
it('require all callbacks to be set', (t) => {
const callbacks = {
onEndpointClose() {},
onSessionNew() {},
onSessionClose() {},
onSessionDatagram() {},
onSessionDatagramStatus() {},
onSessionHandshake() {},
onSessionPathValidation() {},
onSessionTicket() {},
onSessionVersionNegotiation() {},
onStreamCreated() {},
onStreamBlocked() {},
onStreamClose() {},
onStreamReset() {},
onStreamHeaders() {},
onStreamTrailers() {},
};
// Fail if any callback is missing
for (const fn of Object.keys(callbacks)) {
// eslint-disable-next-line no-unused-vars
const { [fn]: _, ...rest } = callbacks;
t.assert.throws(() => quic.setCallbacks(rest), {
code: 'ERR_MISSING_ARGS',
});
}
// If all callbacks are present it should work
quic.setCallbacks(callbacks);
// Multiple calls should just be ignored.
quic.setCallbacks(callbacks);
});
});