Fix mock websocket race condition, add optional mempool blocks waiter

This commit is contained in:
Felipe Knorr Kuhn 2026-02-06 19:51:46 -08:00
parent decc03f529
commit 7dec74404c
No known key found for this signature in database
GPG key ID: 79619B52BB097C1A

View file

@ -32,7 +32,7 @@ export const mockWebSocketV2 = () => {
const winWebSocket = win.WebSocket;
cy.stub(win, 'WebSocket').callsFake((url) => {
console.log(url);
if ((new URL(url).pathname.indexOf('/sockjs-node/') !== 0)) {
if ((new URL(url).pathname.indexOf('/sockjs-node/') !== 0) && (new URL(url).pathname.indexOf('/ng-cli-ws') !== 0)) {
const { server, websocket } = createMock(url);
win.mockServer = server;
@ -117,10 +117,16 @@ export const receiveWebSocketMessageFromServer = ({
};
const MOCK_SOCKET_WAIT_TIMEOUT_MS = 5000;
export const emitMempoolInfo = ({
params
}: { params?: any } = {}) => {
cy.window().then((win) => {
cy.window({ timeout: MOCK_SOCKET_WAIT_TIMEOUT_MS })
.should((win) => {
expect(win.mockSocket, 'mockSocket to be set (app should open WebSocket within timeout)').to.not.be.undefined;
})
.then((win) => {
//TODO: Refactor to take into account different parameterized mocking scenarios
switch (params.network) {
//TODO: Use network specific mocks
@ -133,7 +139,6 @@ export const emitMempoolInfo = ({
switch (params.command) {
case 'init': {
win.mockSocket.send('{"conversions":{"USD":32365.338815782445}}');
cy.readFile('cypress/fixtures/mainnet_live2hchart.json', 'utf-8').then((fixture) => {
win.mockSocket.send(JSON.stringify(fixture));
});
@ -159,7 +164,11 @@ export const emitMempoolInfo = ({
}
});
cy.waitForSkeletonGone();
return cy.get('#mempool-block-0');
if (!params.waitForMempoolBlocks) {
return
} else {
return cy.get('#mempool-block-0');
}
};
export const dropWebSocket = (() => {