mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
refactor: convert file fetch_commands to ts (#28139)
This commit is contained in:
parent
df08325ef6
commit
3f59f05f3f
@ -1,9 +1,11 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
Cypress.Commands.add('delayRequestToRoutes', (routes = [], delay = 0) => {
|
function delayRequestToRoutes(routes = [], delay = 0) {
|
||||||
cy.on('window:before:load', (win) => addDelay(win, routes, delay));
|
cy.on('window:before:load', (win) => addDelay(win, routes, delay));
|
||||||
});
|
}
|
||||||
|
|
||||||
|
Cypress.Commands.add('delayRequestToRoutes', delayRequestToRoutes);
|
||||||
|
|
||||||
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
@ -23,12 +25,14 @@ const addDelay = (win, routes, delay) => {
|
|||||||
// Websocket list to use with mockWebsockets
|
// Websocket list to use with mockWebsockets
|
||||||
window.mockWebsockets = [];
|
window.mockWebsockets = [];
|
||||||
|
|
||||||
// Wrap websocket to be able to connect and close connections on demand
|
function mockWebsockets() {
|
||||||
Cypress.Commands.add('mockWebsockets', () => {
|
cy.on('window:before:load', (win) => mockWebsocketsFn(win));
|
||||||
cy.on('window:before:load', (win) => mockWebsockets(win));
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const mockWebsockets = (win) => {
|
// Wrap websocket to be able to connect and close connections on demand
|
||||||
|
Cypress.Commands.add('mockWebsockets', mockWebsockets);
|
||||||
|
|
||||||
|
const mockWebsocketsFn = (win) => {
|
||||||
const RealWebSocket = WebSocket;
|
const RealWebSocket = WebSocket;
|
||||||
cy.stub(win, 'WebSocket').callsFake((...args) => {
|
cy.stub(win, 'WebSocket').callsFake((...args) => {
|
||||||
const mockWebSocket = {
|
const mockWebSocket = {
|
||||||
@ -61,3 +65,13 @@ const mockWebsockets = (win) => {
|
|||||||
return mockWebSocket;
|
return mockWebSocket;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||||
|
namespace Cypress {
|
||||||
|
interface Chainable {
|
||||||
|
delayRequestToRoutes: typeof delayRequestToRoutes;
|
||||||
|
mockWebsockets: typeof mockWebsockets;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user