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`
feature/default_network_editable
Mark Stacey 4 years ago committed by GitHub
parent a08d927681
commit 3e959b6493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      test/e2e/helpers.js
  2. 6
      test/e2e/metamask-ui.spec.js
  3. 12
      test/e2e/run-e2e-test.js

@ -33,6 +33,7 @@ async function withFixtures(options, testSuite) {
let segmentStub; let segmentStub;
let webDriver; let webDriver;
let failed = false;
try { try {
await ganacheServer.start(ganacheOptions); await ganacheServer.start(ganacheOptions);
if (ganacheOptions?.concurrent) { if (ganacheOptions?.concurrent) {
@ -103,6 +104,7 @@ async function withFixtures(options, testSuite) {
} }
} }
} catch (error) { } catch (error) {
failed = true;
if (webDriver) { if (webDriver) {
try { try {
await webDriver.verboseReportOnFailure(title); await webDriver.verboseReportOnFailure(title);
@ -112,6 +114,7 @@ async function withFixtures(options, testSuite) {
} }
throw error; throw error;
} finally { } finally {
if (!failed || process.env.E2E_LEAVE_RUNNING !== 'true') {
await fixtureServer.stop(); await fixtureServer.stop();
await ganacheServer.quit(); await ganacheServer.quit();
if (ganacheOptions?.concurrent) { if (ganacheOptions?.concurrent) {
@ -135,6 +138,7 @@ async function withFixtures(options, testSuite) {
} }
} }
} }
}
module.exports = { module.exports = {
tinyDelayMs, tinyDelayMs,

@ -20,6 +20,8 @@ describe('MetaMask', function () {
this.bail(true); this.bail(true);
let failed = false;
before(async function () { before(async function () {
await ganacheServer.start(); await ganacheServer.start();
const dappDirectory = path.resolve( const dappDirectory = path.resolve(
@ -54,11 +56,15 @@ describe('MetaMask', function () {
} }
} }
if (this.currentTest.state === 'failed') { if (this.currentTest.state === 'failed') {
failed = true;
await driver.verboseReportOnFailure(this.currentTest.title); await driver.verboseReportOnFailure(this.currentTest.title);
} }
}); });
after(async function () { after(async function () {
if (process.env.E2E_LEAVE_RUNNING === 'true' && failed) {
return;
}
await ganacheServer.quit(); await ganacheServer.quit();
await driver.quit(); await driver.quit();
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {

@ -24,6 +24,12 @@ async function main() {
'Set how many times the test should be retried upon failure.', 'Set how many times the test should be retried upon failure.',
type: 'number', 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', { .positional('e2e-test-path', {
describe: 'The path for the E2E test to run.', describe: 'The path for the E2E test to run.',
type: 'string', type: 'string',
@ -33,7 +39,7 @@ async function main() {
.strict() .strict()
.help('help'); .help('help');
const { browser, e2eTestPath, retries } = argv; const { browser, e2eTestPath, retries, leaveRunning } = argv;
if (!browser) { if (!browser) {
exitWithError( exitWithError(
@ -63,6 +69,10 @@ async function main() {
throw error; throw error;
} }
if (leaveRunning) {
process.env.E2E_LEAVE_RUNNING = 'true';
}
await retry(retries, async () => { await retry(retries, async () => {
await runInShell('yarn', ['mocha', '--no-timeouts', e2eTestPath]); await runInShell('yarn', ['mocha', '--no-timeouts', e2eTestPath]);
}); });

Loading…
Cancel
Save