From 6c505878787fca0ebf3bc15e158aef66ab0b3f48 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 17 Aug 2023 13:32:45 -0230 Subject: [PATCH] Add flag to update E2E snapshots (#20514) The E2E test scripts now have a flag for updating E2E test snapshots. The flag has been documented as well. This makes it easier to update snapshots and raises visbility of this feature. --- README.md | 20 +++++++++++--------- test/e2e/run-all.js | 20 +++++++++++++++++++- test/e2e/run-e2e-test.js | 11 +++++++++++ 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b8e257d1d..fcd7cadd7 100644 --- a/README.md +++ b/README.md @@ -88,15 +88,17 @@ These test scripts all support additional options, which might be helpful for de Single e2e tests can be run with `yarn test:e2e:single test/e2e/tests/TEST_NAME.spec.js` along with the options below. ```console - --browser Set the browser used; either 'chrome' or 'firefox'. - [string] [choices: "chrome", "firefox"] - --debug Run tests in debug mode, logging each driver interaction - [boolean] [default: false] - --retries Set how many times the test should be retried upon failure. - [number] [default: 0] - --leave-running Leaves the browser running after a test fails, along with - anything else that the test used (ganache, the test dapp, - etc.) [boolean] [default: false] + --browser Set the browser used; either 'chrome' or 'firefox'. + [string] [choices: "chrome", "firefox"] + --debug Run tests in debug mode, logging each driver interaction + [boolean] [default: false] + --retries Set how many times the test should be retried upon failure. + [number] [default: 0] + --leave-running Leaves the browser running after a test fails, along with + anything else that the test used (ganache, the test dapp, + etc.) [boolean] [default: false] + --update-snapshot Update E2E test snapshots + [alias: -u] [boolean] [default: false] ``` For example, to run the `account-details` tests using Chrome, with debug logging and with the browser set to remain open upon failure, you would use: diff --git a/test/e2e/run-all.js b/test/e2e/run-all.js index 2556330e0..811f6b8fb 100644 --- a/test/e2e/run-all.js +++ b/test/e2e/run-all.js @@ -74,12 +74,27 @@ async function main() { description: 'Set how many times the test should be retried upon failure.', type: 'number', + }) + .option('update-snapshot', { + alias: 'u', + default: false, + description: 'Update E2E snapshots', + type: 'boolean', }), ) .strict() .help('help'); - const { browser, debug, retries, snaps, mv3, rpc, buildType } = argv; + const { + browser, + debug, + retries, + snaps, + mv3, + rpc, + buildType, + updateSnapshot, + } = argv; let testPaths; @@ -130,6 +145,9 @@ async function main() { if (debug) { args.push('--debug'); } + if (updateSnapshot) { + args.push('--update-snapshot'); + } // For running E2Es in parallel in CI const currentChunkIndex = process.env.CIRCLE_NODE_INDEX ?? 0; diff --git a/test/e2e/run-e2e-test.js b/test/e2e/run-e2e-test.js index 1c2c60362..a7b8f8602 100644 --- a/test/e2e/run-e2e-test.js +++ b/test/e2e/run-e2e-test.js @@ -42,6 +42,12 @@ async function main() { 'Leaves the browser running after a test fails, along with anything else that the test used (ganache, the test dapp, etc.)', type: 'boolean', }) + .option('update-snapshot', { + alias: 'u', + default: false, + description: 'Update E2E snapshots', + type: 'boolean', + }) .positional('e2e-test-path', { describe: 'The path for the E2E test to run.', type: 'string', @@ -58,6 +64,7 @@ async function main() { retries, retryUntilFailure, leaveRunning, + updateSnapshot, } = argv; if (!browser) { @@ -103,6 +110,10 @@ async function main() { exit = '--no-exit'; } + if (updateSnapshot) { + process.env.UPDATE_SNAPSHOTS = 'true'; + } + const configFile = path.join(__dirname, '.mocharc.js'); const extraArgs = process.env.E2E_ARGS?.split(' ') || [];