Skip to content

Commit ac99dd4

Browse files
Revert "test: add Solana Websocket server by default in all our e2e (#36165)"
This reverts commit 5cfb23e.
1 parent 5cfb23e commit ac99dd4

File tree

5 files changed

+44
-36
lines changed

5 files changed

+44
-36
lines changed

test/e2e/helpers.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ async function withFixtures(options, testSuite) {
128128
ethConversionInUsd,
129129
monConversionInUsd,
130130
manifestFlags,
131-
solanaWebSocketSpecificMocks = [],
131+
withSolanaWebSocket = {
132+
server: false,
133+
mocks: [],
134+
},
132135
} = options;
133136

134137
// Normalize localNodeOptions
@@ -155,7 +158,7 @@ async function withFixtures(options, testSuite) {
155158
let localNode;
156159
const localNodes = [];
157160

158-
let webSocketServer;
161+
let localWebSocketServer;
159162

160163
try {
161164
// Start servers based on the localNodes array
@@ -261,10 +264,11 @@ async function withFixtures(options, testSuite) {
261264
}
262265
}
263266

264-
// Start WebSocket server and apply Solana mocks (defaults + overrides)
265-
webSocketServer = LocalWebSocketServer.getServerInstance();
266-
webSocketServer.start();
267-
await setupSolanaWebsocketMocks(solanaWebSocketSpecificMocks);
267+
if (withSolanaWebSocket.server) {
268+
localWebSocketServer = LocalWebSocketServer.getServerInstance();
269+
localWebSocketServer.start();
270+
await setupSolanaWebsocketMocks(withSolanaWebSocket.mocks);
271+
}
268272

269273
const { mockedEndpoint, getPrivacyReport } = await setupMocking(
270274
mockServer,
@@ -274,6 +278,7 @@ async function withFixtures(options, testSuite) {
274278
ethConversionInUsd,
275279
monConversionInUsd,
276280
},
281+
withSolanaWebSocket,
277282
);
278283
if ((await detectPort(8000)) !== 8000) {
279284
throw new Error(
@@ -450,20 +455,9 @@ async function withFixtures(options, testSuite) {
450455
})(),
451456
);
452457

453-
shutdownTasks.push(
454-
(async () => {
455-
try {
456-
if (
457-
webSocketServer &&
458-
typeof webSocketServer.stopAndCleanup === 'function'
459-
) {
460-
await webSocketServer.stopAndCleanup();
461-
}
462-
} catch (e) {
463-
console.log('WebSocket server already stopped or not initialized');
464-
}
465-
})(),
466-
);
458+
if (withSolanaWebSocket.server) {
459+
shutdownTasks.push(localWebSocketServer.stopAndCleanup());
460+
}
467461

468462
const results = await Promise.allSettled(shutdownTasks);
469463
const failures = results.filter((result) => result.status === 'rejected');

test/e2e/mock-e2e.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,14 @@ const privateHostMatchers = [
143143
* @param {object} options - Network mock options.
144144
* @param {string} options.chainId - The chain ID used by the default configured network.
145145
* @param {string} options.ethConversionInUsd - The USD conversion rate for ETH.
146+
* @param {object} withSolanaWebSocket - Solana WebSocket configuration with server flag and mocks function
146147
* @returns {Promise<SetupMockReturn>}
147148
*/
148149
async function setupMocking(
149150
server,
150151
testSpecificMock,
151152
{ chainId, ethConversionInUsd = 1700 },
153+
withSolanaWebSocket,
152154
) {
153155
const privacyReport = new Set();
154156
await server.forAnyRequest().thenPassThrough({
@@ -944,12 +946,14 @@ async function setupMocking(
944946
* Solana Websocket
945947
* Setup HTTP intercept for WebSocket handshake requests
946948
*/
947-
await server
948-
.forAnyWebSocket()
949-
.matching((req) =>
950-
/^wss:\/\/solana-(mainnet|devnet)\.infura\.io\//u.test(req.url),
951-
)
952-
.thenForwardTo('ws://localhost:8088');
949+
if (withSolanaWebSocket.server) {
950+
await server
951+
.forAnyWebSocket()
952+
.matching((req) =>
953+
/^wss:\/\/solana-(mainnet|devnet)\.infura\.io\//u.test(req.url),
954+
)
955+
.thenForwardTo('ws://localhost:8088');
956+
}
953957

954958
// Test Dapp Styles
955959
const TEST_DAPP_STYLES_1 = fs.readFileSync(TEST_DAPP_STYLES_1_PATH);

test/e2e/tests/solana/common-solana.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ACCOUNT_TYPE } from '../../constants';
1111
import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow';
1212
import { mockProtocolSnap } from '../../mock-response-data/snaps/snap-binary-mocks';
1313
import AssetListPage from '../../page-objects/pages/home/asset-list';
14+
import { DEFAULT_SOLANA_WS_MOCKS } from './mocks/websocketDefaultMocks';
1415

1516
const SOLANA_URL_REGEX_MAINNET =
1617
/^https:\/\/solana-(mainnet|devnet)\.infura\.io\/v3*/u;
@@ -1611,6 +1612,10 @@ export async function withSolanaAccountSnap(
16111612
fixtures: fixtures.build(),
16121613
title,
16131614
dapp: true,
1615+
withSolanaWebSocket: {
1616+
server: true,
1617+
mocks: DEFAULT_SOLANA_WS_MOCKS,
1618+
},
16141619
manifestFlags: {
16151620
// This flag is used to enable/disable the remote mode for the carousel
16161621
// component, which will impact to the slides count.

test/e2e/tests/solana/web-socket-connection.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import HeaderNavbar from '../../page-objects/pages/header-navbar';
88
import AccountListPage from '../../page-objects/pages/account-list-page';
99
import FixtureBuilder from '../../fixture-builder';
1010
import LocalWebSocketServer from '../../websocket-server';
11+
import { DEFAULT_SOLANA_WS_MOCKS } from './mocks/websocketDefaultMocks';
1112

1213
describe('Solana Web Socket', function (this: Suite) {
1314
it('a websocket connection is open when MetaMask full view is open', async function () {
1415
await withFixtures(
1516
{
1617
fixtures: new FixtureBuilder().build(),
1718
title: this.test?.fullTitle(),
19+
withSolanaWebSocket: {
20+
server: true,
21+
mocks: DEFAULT_SOLANA_WS_MOCKS,
22+
},
1823
manifestFlags: {
1924
remoteFeatureFlags: {
2025
addSolanaAccount: true,
@@ -49,6 +54,10 @@ describe('Solana Web Socket', function (this: Suite) {
4954
{
5055
fixtures: new FixtureBuilder().build(),
5156
title: this.test?.fullTitle(),
57+
withSolanaWebSocket: {
58+
server: true,
59+
mocks: DEFAULT_SOLANA_WS_MOCKS,
60+
},
5261
manifestFlags: {
5362
remoteFeatureFlags: {
5463
addSolanaAccount: true,
@@ -93,6 +102,10 @@ describe('Solana Web Socket', function (this: Suite) {
93102
{
94103
fixtures: new FixtureBuilder().build(),
95104
title: this.test?.fullTitle(),
105+
withSolanaWebSocket: {
106+
server: true,
107+
mocks: DEFAULT_SOLANA_WS_MOCKS,
108+
},
96109
manifestFlags: {
97110
remoteFeatureFlags: {
98111
addSolanaAccount: true,

test/e2e/websocket-solana-mocks.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// eslint-disable-next-line @typescript-eslint/no-shadow
22
import { WebSocket } from 'ws';
33
import LocalWebSocketServer from './websocket-server';
4-
import {
5-
WebSocketMessageMock,
6-
DEFAULT_SOLANA_WS_MOCKS,
7-
} from './tests/solana/mocks/websocketDefaultMocks';
4+
import { WebSocketMessageMock } from './tests/solana/mocks/websocketDefaultMocks';
85

96
/**
107
* Sets up Solana WebSocket mocks with configurable message handlers
@@ -17,11 +14,6 @@ export async function setupSolanaWebsocketMocks(
1714
const localWebSocketServer = LocalWebSocketServer.getServerInstance();
1815
const wsServer = localWebSocketServer.getServer();
1916

20-
const mergedMocks: WebSocketMessageMock[] = [
21-
...mocks,
22-
...DEFAULT_SOLANA_WS_MOCKS,
23-
];
24-
2517
// Add Solana-specific message handlers to the existing server
2618
wsServer.on('connection', (socket: WebSocket) => {
2719
console.log('Client connected to the local WebSocket server');
@@ -32,7 +24,7 @@ export async function setupSolanaWebsocketMocks(
3224
console.log('Message received from client:', message);
3325

3426
// Check each mock configuration
35-
for (const mock of mergedMocks) {
27+
for (const mock of mocks) {
3628
const includes = Array.isArray(mock.messageIncludes)
3729
? mock.messageIncludes
3830
: [mock.messageIncludes];

0 commit comments

Comments
 (0)