1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Avoid resetting the mock server (#18661)

This commit is contained in:
Peter 2023-04-19 15:36:23 +01:00 committed by GitHub
parent 7bc13e90f8
commit 02e8e9c679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 21 deletions

View File

@ -105,7 +105,7 @@ async function withFixtures(options, testSuite) {
});
}
}
await setupMocking(mockServer, testSpecificMock);
const mockedEndpoint = await setupMocking(mockServer, testSpecificMock);
await mockServer.start(8000);
if (
process.env.SELENIUM_BROWSER === 'chrome' &&
@ -143,10 +143,10 @@ async function withFixtures(options, testSuite) {
await testSuite({
driver: driverProxy ?? driver,
mockServer,
contractRegistry,
ganacheServer,
secondaryGanacheServer,
mockedEndpoint,
});
} catch (error) {
failed = true;

View File

@ -32,6 +32,11 @@ async function setupMocking(server, testSpecificMock) {
return {};
},
});
const mockedEndpoint = await testSpecificMock(server);
// Mocks below this line can be overridden by test-specific mocks
await server
.forPost(
'https://arbitrum-mainnet.infura.io/v3/00000000000000000000000000000000',
@ -369,10 +374,6 @@ async function setupMocking(server, testSpecificMock) {
};
});
testSpecificMock(server);
// Mocks below this line can be overridden by test-specific mocks
await server.forGet(STALELIST_URL).thenCallback(() => {
return {
statusCode: 200,
@ -399,6 +400,8 @@ async function setupMocking(server, testSpecificMock) {
},
};
});
return mockedEndpoint;
}
module.exports = { setupMocking };

View File

@ -9,8 +9,6 @@ describe('ENS', function () {
'https://mainnet.infura.io/v3/00000000000000000000000000000000';
async function mockInfura(mockServer) {
await mockServer.reset();
await mockServer.forAnyRequest().thenPassThrough();
await mockServer
.forPost(infuraUrl)
.withJsonBodyIncluding({ method: 'eth_blockNumber' })
@ -103,7 +101,7 @@ describe('ENS', function () {
await driver.clickElement('[data-testid="eth-overview-send"]');
await driver.fill(
await driver.pasteIntoField(
'input[placeholder="Search, public address (0x), or ENS"]',
sampleEnsDomain,
);

View File

@ -3,9 +3,7 @@ const { convertToHexValue, withFixtures } = require('../helpers');
const FixtureBuilder = require('../fixture-builder');
describe('Sentry errors', function () {
async function mockSegment(mockServer) {
mockServer.reset();
await mockServer.forAnyRequest().thenPassThrough();
async function mockSentry(mockServer) {
return await mockServer
.forPost('https://sentry.io/api/0000000/store/')
.thenCallback(() => {
@ -36,9 +34,9 @@ describe('Sentry errors', function () {
ganacheOptions,
title: this.test.title,
failOnConsoleError: false,
testSpecificMock: mockSentry,
},
async ({ driver, mockServer }) => {
const mockedEndpoint = await mockSegment(mockServer);
async ({ driver, mockedEndpoint }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);

View File

@ -4,8 +4,6 @@ const FixtureBuilder = require('../fixture-builder');
describe('Segment metrics', function () {
async function mockSegment(mockServer) {
mockServer.reset();
await mockServer.forAnyRequest().thenPassThrough();
return await mockServer
.forPost('https://api.segment.io/v1/batch')
.withJsonBodyIncluding({ batch: [{ type: 'page' }] })
@ -36,18 +34,17 @@ describe('Segment metrics', function () {
.build(),
ganacheOptions,
title: this.test.title,
failOnConsoleError: false,
testSpecificMock: mockSegment,
},
async ({ driver, mockServer }) => {
const mockedEndpoints = await mockSegment(mockServer);
async ({ driver, mockedEndpoint }) => {
await driver.navigate();
await driver.fill('#password', 'correct horse battery staple');
await driver.press('#password', driver.Key.ENTER);
await driver.wait(async () => {
const isPending = await mockedEndpoints.isPending();
const isPending = await mockedEndpoint.isPending();
return isPending === false;
}, 10000);
const mockedRequests = await mockedEndpoints.getSeenRequests();
const mockedRequests = await mockedEndpoint.getSeenRequests();
assert.equal(mockedRequests.length, 3);
const [firstMock, secondMock, thirdMock] = mockedRequests;
let [mockJson] = firstMock.body.json.batch;

View File

@ -8,6 +8,7 @@ describe('Gas API fallback', function () {
.forGet(
'https://gas-api.metaswap.codefi.network/networks/1/suggestedGasFees',
)
.always()
.thenCallback(() => {
return {
statusCode: 200,