@webex/internal-plugin-mercury 3.11.0 → 3.12.0-next.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.
- package/README.md +54 -0
- package/dist/mercury.js +388 -198
- package/dist/mercury.js.map +1 -1
- package/dist/socket/constants.js +16 -0
- package/dist/socket/constants.js.map +1 -0
- package/dist/socket/socket-base.js +36 -3
- package/dist/socket/socket-base.js.map +1 -1
- package/package.json +17 -17
- package/src/mercury.js +389 -171
- package/src/socket/constants.js +6 -0
- package/src/socket/socket-base.js +40 -3
- package/test/unit/spec/mercury-events.js +20 -2
- package/test/unit/spec/mercury.js +201 -139
- package/test/unit/spec/socket.js +61 -0
package/test/unit/spec/socket.js
CHANGED
|
@@ -653,6 +653,67 @@ describe('plugin-mercury', () => {
|
|
|
653
653
|
});
|
|
654
654
|
assert.calledOnce(socket._ping);
|
|
655
655
|
});
|
|
656
|
+
|
|
657
|
+
[
|
|
658
|
+
{
|
|
659
|
+
description: 'manually triggers close handler when socket is still connecting',
|
|
660
|
+
closeOptions: {code: 3001, reason: 'Custom close while connecting'},
|
|
661
|
+
expectedCode: 3001,
|
|
662
|
+
expectedReason: 'Custom close while connecting',
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
description:
|
|
666
|
+
'manually triggers close handler with default code when socket is connecting',
|
|
667
|
+
closeOptions: undefined,
|
|
668
|
+
expectedCode: 1000,
|
|
669
|
+
expectedReason: 'Done',
|
|
670
|
+
},
|
|
671
|
+
].forEach(({description, closeOptions, expectedCode, expectedReason}) => {
|
|
672
|
+
it(description, async () => {
|
|
673
|
+
const s = new Socket();
|
|
674
|
+
let socketInstance;
|
|
675
|
+
|
|
676
|
+
// Save the current stub and replace it
|
|
677
|
+
const previousStub = Socket.getWebSocketConstructor;
|
|
678
|
+
Socket.getWebSocketConstructor = sinon.stub().callsFake(
|
|
679
|
+
() =>
|
|
680
|
+
function (...args) {
|
|
681
|
+
socketInstance = new MockWebSocket(...args);
|
|
682
|
+
return socketInstance;
|
|
683
|
+
}
|
|
684
|
+
);
|
|
685
|
+
|
|
686
|
+
// open the socket
|
|
687
|
+
s.open('ws://example.com', mockoptions);
|
|
688
|
+
|
|
689
|
+
// Keep socket in CONNECTING state (readyState 0)
|
|
690
|
+
socketInstance.readyState = 0;
|
|
691
|
+
|
|
692
|
+
const closeSpy = sinon.spy();
|
|
693
|
+
s.on('close', closeSpy);
|
|
694
|
+
|
|
695
|
+
// Call close and await the result
|
|
696
|
+
const result = await s.close(closeOptions);
|
|
697
|
+
|
|
698
|
+
// Verify the promise resolved with the correct close event
|
|
699
|
+
assert.equal(result.code, expectedCode);
|
|
700
|
+
assert.equal(result.reason, expectedReason);
|
|
701
|
+
|
|
702
|
+
// Verify close handler was called with expected code/reason
|
|
703
|
+
assert.calledOnce(closeSpy);
|
|
704
|
+
assert.calledWith(closeSpy, {
|
|
705
|
+
code: expectedCode,
|
|
706
|
+
reason: expectedReason,
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
// Verify the underlying socket.close was called with the correct params
|
|
710
|
+
assert.calledOnce(socketInstance.close);
|
|
711
|
+
assert.calledWith(socketInstance.close, expectedCode, expectedReason);
|
|
712
|
+
|
|
713
|
+
// Restore the previous stub
|
|
714
|
+
Socket.getWebSocketConstructor = previousStub;
|
|
715
|
+
});
|
|
716
|
+
});
|
|
656
717
|
});
|
|
657
718
|
|
|
658
719
|
describe('#send()', () => {
|