From 3e959b649301d7631fab080a8f7a14181953b614 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 16 Jun 2021 12:42:20 -0230 Subject: [PATCH] Add `--leave-running` flag to E2E test script (#11321) * Add `--leave-running` flag to E2E test script The `--leave-running` flag has been added to the E2E test runner. This ensures the browser, ganache, and everything else stays running upon test failure. This is useful for local debugging, for investigating what state the extension was in when it failed. * Add `--leave-running` support to `metamask-ui.spec.js` --- test/e2e/helpers.js | 42 ++++++++++++++++++++---------------- test/e2e/metamask-ui.spec.js | 6 ++++++ test/e2e/run-e2e-test.js | 12 ++++++++++- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index ae8b4d6c5..cde3b0243 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -33,6 +33,7 @@ async function withFixtures(options, testSuite) { let segmentStub; let webDriver; + let failed = false; try { await ganacheServer.start(ganacheOptions); if (ganacheOptions?.concurrent) { @@ -103,6 +104,7 @@ async function withFixtures(options, testSuite) { } } } catch (error) { + failed = true; if (webDriver) { try { await webDriver.verboseReportOnFailure(title); @@ -112,26 +114,28 @@ async function withFixtures(options, testSuite) { } throw error; } finally { - await fixtureServer.stop(); - await ganacheServer.quit(); - if (ganacheOptions?.concurrent) { - await secondaryGanacheServer.quit(); - } - if (webDriver) { - await webDriver.quit(); - } - if (dappServer) { - await new Promise((resolve, reject) => { - dappServer.close((error) => { - if (error) { - return reject(error); - } - return resolve(); + if (!failed || process.env.E2E_LEAVE_RUNNING !== 'true') { + await fixtureServer.stop(); + await ganacheServer.quit(); + if (ganacheOptions?.concurrent) { + await secondaryGanacheServer.quit(); + } + if (webDriver) { + await webDriver.quit(); + } + if (dappServer) { + await new Promise((resolve, reject) => { + dappServer.close((error) => { + if (error) { + return reject(error); + } + return resolve(); + }); }); - }); - } - if (segmentServer) { - await segmentServer.stop(); + } + if (segmentServer) { + await segmentServer.stop(); + } } } } diff --git a/test/e2e/metamask-ui.spec.js b/test/e2e/metamask-ui.spec.js index e6dadd200..c28ab6e5c 100644 --- a/test/e2e/metamask-ui.spec.js +++ b/test/e2e/metamask-ui.spec.js @@ -20,6 +20,8 @@ describe('MetaMask', function () { this.bail(true); + let failed = false; + before(async function () { await ganacheServer.start(); const dappDirectory = path.resolve( @@ -54,11 +56,15 @@ describe('MetaMask', function () { } } if (this.currentTest.state === 'failed') { + failed = true; await driver.verboseReportOnFailure(this.currentTest.title); } }); after(async function () { + if (process.env.E2E_LEAVE_RUNNING === 'true' && failed) { + return; + } await ganacheServer.quit(); await driver.quit(); await new Promise((resolve, reject) => { diff --git a/test/e2e/run-e2e-test.js b/test/e2e/run-e2e-test.js index b9b869fe8..ce349ad02 100644 --- a/test/e2e/run-e2e-test.js +++ b/test/e2e/run-e2e-test.js @@ -24,6 +24,12 @@ async function main() { 'Set how many times the test should be retried upon failure.', type: 'number', }) + .option('leave-running', { + default: false, + description: + 'Leaves the browser running after a test fails, along with anything else that the test used (ganache, the test dapp, etc.)', + type: 'boolean', + }) .positional('e2e-test-path', { describe: 'The path for the E2E test to run.', type: 'string', @@ -33,7 +39,7 @@ async function main() { .strict() .help('help'); - const { browser, e2eTestPath, retries } = argv; + const { browser, e2eTestPath, retries, leaveRunning } = argv; if (!browser) { exitWithError( @@ -63,6 +69,10 @@ async function main() { throw error; } + if (leaveRunning) { + process.env.E2E_LEAVE_RUNNING = 'true'; + } + await retry(retries, async () => { await runInShell('yarn', ['mocha', '--no-timeouts', e2eTestPath]); });