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]); });