From d1c05195dd8a6a1a32986e5dca55bbaba0cff4e1 Mon Sep 17 00:00:00 2001 From: PeterYinusa <53189696+PeterYinusa@users.noreply.github.com> Date: Mon, 7 Mar 2022 19:23:04 +0000 Subject: [PATCH] E2e improve mocking (#13841) * improve mocking * improve mocking * Unnecessary await --- development/mock-e2e.js | 8 ++++---- test/e2e/helpers.js | 11 ++++------- test/e2e/tests/phishing-detection.spec.js | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/development/mock-e2e.js b/development/mock-e2e.js index 2eb05e75e..4fde023d5 100644 --- a/development/mock-e2e.js +++ b/development/mock-e2e.js @@ -1,7 +1,7 @@ -function setupMocking(server, testSpecificMock) { - server.forAnyRequest().thenPassThrough(); +async function setupMocking(server, testSpecificMock) { + await server.forAnyRequest().thenPassThrough(); - server + await server .forOptions('https://gas-api.metaswap.codefi.network/networks/1/gasPrices') .thenCallback(() => { return { @@ -14,7 +14,7 @@ function setupMocking(server, testSpecificMock) { }; }); - server + await server .forGet('https://gas-api.metaswap.codefi.network/networks/1/gasPrices') .thenCallback(() => { return { diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index aebc6b673..fea0e00b7 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -36,11 +36,12 @@ async function withFixtures(options, testSuite) { } = options; const fixtureServer = new FixtureServer(); const ganacheServer = new Ganache(); + const https = await mockttp.generateCACertificate(); + const mockServer = mockttp.getLocal({ https }); let secondaryGanacheServer; let dappServer; let segmentServer; let segmentStub; - let mockServer; let webDriver; let failed = false; @@ -91,9 +92,7 @@ async function withFixtures(options, testSuite) { }); await segmentServer.start(9090); } - const https = await mockttp.generateCACertificate(); - mockServer = mockttp.getLocal({ https }); - setupMocking(mockServer, testSpecificMock); + await setupMocking(mockServer, testSpecificMock); await mockServer.start(8000); if ( process.env.SELENIUM_BROWSER === 'chrome' && @@ -157,9 +156,7 @@ async function withFixtures(options, testSuite) { if (segmentServer) { await segmentServer.stop(); } - if (mockServer) { - await mockServer.stop(); - } + await mockServer.stop(); } } } diff --git a/test/e2e/tests/phishing-detection.spec.js b/test/e2e/tests/phishing-detection.spec.js index 0cacf1e23..63b25dafb 100644 --- a/test/e2e/tests/phishing-detection.spec.js +++ b/test/e2e/tests/phishing-detection.spec.js @@ -2,8 +2,8 @@ const { strict: assert } = require('assert'); const { convertToHexValue, withFixtures } = require('../helpers'); describe('Phishing Detection', function () { - function mockPhishingDetection(mockServer) { - mockServer + async function mockPhishingDetection(mockServer) { + await mockServer .forGet( 'https://cdn.jsdelivr.net/gh/MetaMask/eth-phishing-detect@master/src/config.json', )