From f44af06f9bc0e211004aaeb6328644f0f63a6482 Mon Sep 17 00:00:00 2001 From: seaona <54408225+seaona@users.noreply.github.com> Date: Fri, 25 Nov 2022 12:06:48 +0100 Subject: [PATCH] [e2e] Setup MV3 specific test folder and add 1 simple testcase introducing Service Worker re-start (#16606) * First e2e mv3 specific dapp testcase * Fix testpath for snaps * Update `it` description Co-authored-by: Mark Stacey * e2e test paths improvement Co-authored-by: Mark Stacey --- .circleci/config.yml | 2 +- test/e2e/mv3/dapp-interactions.spec.js | 66 ++++++++++++++++++++++++++ test/e2e/run-all.js | 26 ++++++---- 3 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 test/e2e/mv3/dapp-interactions.spec.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 5bbc7ddc7..f1ad78042 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -590,7 +590,7 @@ jobs: command: | if .circleci/scripts/test-run-e2e.sh then - yarn test:e2e:chrome --retries 2 || echo "Temporarily suppressing MV3 e2e test failures" + yarn test:e2e:chrome --retries 2 --mv3 || echo "Temporarily suppressing MV3 e2e test failures" fi no_output_timeout: 20m - store_artifacts: diff --git a/test/e2e/mv3/dapp-interactions.spec.js b/test/e2e/mv3/dapp-interactions.spec.js new file mode 100644 index 000000000..8020047cf --- /dev/null +++ b/test/e2e/mv3/dapp-interactions.spec.js @@ -0,0 +1,66 @@ +const { strict: assert } = require('assert'); +const { convertToHexValue, withFixtures } = require('../helpers'); +const FixtureBuilder = require('../fixture-builder'); + +describe('MV3 - Dapp interactions', function () { + let windowHandles; + const ganacheOptions = { + accounts: [ + { + secretKey: + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', + balance: convertToHexValue(25000000000000000000), + }, + ], + }; + it('should continue to support dapp interactions after service worker re-start', async function () { + await withFixtures( + { + dapp: true, + fixtures: new FixtureBuilder() + .withPermissionControllerConnectedToTestDapp() + .build(), + ganacheOptions: { + ...ganacheOptions, + }, + title: this.test.title, + }, + async ({ driver }) => { + await driver.navigate(); + await driver.fill('#password', 'correct horse battery staple'); + await driver.press('#password', driver.Key.ENTER); + + await driver.openNewPage('http://127.0.0.1:8080/'); + + // Terminate Service Worker + await driver.openNewPage('chrome://inspect/#service-workers/'); + await driver.clickElement({ + text: 'Service workers', + tag: 'button', + }); + + await driver.clickElement({ + text: 'terminate', + tag: 'span', + }); + + // Trigger Notification + windowHandles = await driver.getAllWindowHandles(); + await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles); + await driver.clickElement('#addEthereumChain'); + await driver.waitUntilXWindowHandles(4); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + + const notification = await driver.isElementPresent({ + text: 'Allow this site to add a network?', + tag: 'h3', + }); + + assert.ok(notification, 'Dapp action does not appear in Metamask'); + }, + ); + }); +}); diff --git a/test/e2e/run-all.js b/test/e2e/run-all.js index 5ef37e433..75e708105 100644 --- a/test/e2e/run-all.js +++ b/test/e2e/run-all.js @@ -40,6 +40,10 @@ async function main() { description: `run snaps e2e tests`, type: 'boolean', }) + .option('mv3', { + description: `run mv3 specific e2e tests`, + type: 'boolean', + }) .option('retries', { description: 'Set how many times the test should be retried upon failure.', @@ -49,22 +53,26 @@ async function main() { .strict() .help('help'); - const { browser, retries, snaps } = argv; + const { browser, retries, snaps, mv3 } = argv; - let testDir = path.join(__dirname, 'tests'); + let testPaths; if (snaps) { - testDir = path.join(__dirname, 'snaps'); - } - - let testPaths = await getTestPathsForTestDir(testDir); - - if (!snaps) { + const testDir = path.join(__dirname, 'snaps'); + testPaths = await getTestPathsForTestDir(testDir); + } else { + const testDir = path.join(__dirname, 'tests'); testPaths = [ - ...testPaths, + ...(await getTestPathsForTestDir(testDir)), ...(await getTestPathsForTestDir(path.join(__dirname, 'swaps'))), path.join(__dirname, 'metamask-ui.spec.js'), ]; + + if (mv3) { + testPaths.push( + ...(await getTestPathsForTestDir(path.join(__dirname, 'mv3'))), + ); + } } const runE2eTestPath = path.join(__dirname, 'run-e2e-test.js');