mirror of
https://github.com/mempool/mempool.git
synced 2024-12-28 17:24:25 +01:00
9e46cde9b7
* initial version of the update config script
* fix duplicated content
* update cypress ci settings
* add workflow to run e2e tests when pushing
* record cypress results to the dashboard
* pull the cypress record key and project id from the secrets
* add start-server-and-test to replace concurrently
* replace concurrently with start-server-and-test
* remove concurrently
* add new cypress target to record
* update cypress to 7.7.0
* add tests for signet
* add tests for testnet
* run tests on chrome and firefox
* update test matrix: add edge and run firefox on container
* fix copypasta
* update docker image for firefox
* fix task name again
* fix edge tests task name
* improve bisq tests
* update workflow config
* enable cypress debug logs
* add a manual trigger for the e2e tests
* add config:defaults target
* use more of the GHA options
* fix config command
* add cypress-fail-on-console-error
* upgrade cypress to v8.0.0
* add helper to wait for the loader skeleton to be gone
* use skeleton waiter on the tests
* remove manual test trigger
* fix tv test when only one mempool block is available
* add waiter for pagination
* add extra steps to debug firefox launch issue
* remove whoami step
* Revert "upgrade cypress to v8.0.0"
This reverts commit cb3ff7d906
.
* remove userinfo debug step
* enable test retries in run mode
* update proxy config to reduce ECONNRESET errors
* add mock-socket dev dependency
* add helpers to mock websockets and detect page idleness
* stabilize mainnet tests
* fix tv mode test on Liquid
* add basic tests for the mainnet status page
* cleanup mainnet tests
* update bisq tests
* update signet tests
* update testnet tests
* add initial support for parameterized websocket mocks
* move testing dependencies to optionalDependencies
* comment out mempool size check until the live updates are fixed
* comment out tx regex test
* update fixture for the new difficulty adjustment component
* fix the assertions on the status page
85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
import { v4 as uuid } from 'uuid';
|
|
import { WebSocket, Server } from 'mock-socket';
|
|
|
|
declare global {
|
|
interface Window {
|
|
mockServer: Server;
|
|
mockSocket: WebSocket;
|
|
}
|
|
}
|
|
|
|
const mocks: { [key: string]: { server: Server; websocket: WebSocket } } = {};
|
|
|
|
const cleanupMock = (url: string) => {
|
|
if (mocks[url]) {
|
|
mocks[url].websocket.close();
|
|
mocks[url].server.stop();
|
|
delete mocks[url];
|
|
}
|
|
};
|
|
|
|
const createMock = (url: string) => {
|
|
cleanupMock(url);
|
|
const server = new Server(url);
|
|
const websocket = new WebSocket(url);
|
|
mocks[url] = { server, websocket };
|
|
|
|
return mocks[url];
|
|
};
|
|
|
|
export const mockWebSocket = () => {
|
|
cy.on('window:before:load', (win) => {
|
|
const winWebSocket = win.WebSocket;
|
|
cy.stub(win, 'WebSocket').callsFake((url) => {
|
|
console.log(url);
|
|
if ((new URL(url).pathname.indexOf('/sockjs-node/') !== 0)) {
|
|
const { server, websocket } = createMock(url);
|
|
|
|
win.mockServer = server;
|
|
win.mockServer.on('connection', (socket) => {
|
|
win.mockSocket = socket;
|
|
});
|
|
|
|
win.mockServer.on('message', (message) => {
|
|
console.log(message);
|
|
});
|
|
|
|
return websocket;
|
|
} else {
|
|
return new winWebSocket(url);
|
|
}
|
|
});
|
|
});
|
|
|
|
cy.on('window:before:unload', () => {
|
|
for (const url in mocks) {
|
|
cleanupMock(url);
|
|
}
|
|
});
|
|
};
|
|
|
|
export const emitMempoolInfo = ({
|
|
params
|
|
}: { params?: any } = {}) => {
|
|
cy.window().then((win) => {
|
|
//TODO: Refactor to take into account different parameterized mocking scenarios
|
|
switch (params.network) {
|
|
//TODO: Use network specific mocks
|
|
case "signet":
|
|
case "testnet":
|
|
default:
|
|
win.mockSocket.send('{"action":"init"}');
|
|
win.mockSocket.send('{"action":"want","data":["blocks","stats","mempool-blocks","live-2h-chart"]}');
|
|
cy.readFile('cypress/fixtures/mainnet_mempoolInfo.json', 'ascii').then((fixture) => {
|
|
win.mockSocket.send(JSON.stringify(fixture));
|
|
});
|
|
win.mockSocket.send('{"conversions":{"USD":32365.338815782445}}');
|
|
cy.readFile('cypress/fixtures/mainnet_live2hchart.json', 'ascii').then((fixture) => {
|
|
win.mockSocket.send(JSON.stringify(fixture));
|
|
});
|
|
}
|
|
});
|
|
cy.waitForSkeletonGone();
|
|
return cy.get('#mempool-block-0');
|
|
};
|