From a61e351234d9c74f9fe80b35f6f97769e0758d78 Mon Sep 17 00:00:00 2001 From: Vadim Nicolai Date: Mon, 1 Apr 2019 13:10:58 +0300 Subject: [PATCH] [14494] - Improve e2e testing docs and add cli args. (#14717) * Updated readme and added local arg. * Lint fixes. * Replaced dumb namings with a more reasonable ones. * Added --wordpress- to cleanUpPrefixes. * Align argument name with env key. --- packages/scripts/README.md | 3 +++ packages/scripts/scripts/test-e2e.js | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index 0c1687ed49f9c..e6bc450c54ba0 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -216,6 +216,9 @@ This is how you execute those scripts using the presented setup: * `npm run test:e2e` - runs all unit tests. * `npm run test:e2e:help` - prints all available options to configure unit tests runner. +* `npm run test-e2e -- --puppeteer-interactive` - runs all unit tests interactively. +* `npm run test-e2e FILE_NAME -- --puppeteer-interactive ` - runs one test file interactively. +* `npm run test-e2e:watch -- --puppeteer-interactive` - runs all tests interactively and watch for changes. This script automatically detects the best config to start Puppeteer but sometimes you may need to specify custom options: - You can add a `jest-puppeteer.config.js` at the root of the project or define a custom path using `JEST_PUPPETEER_CONFIG` environment variable. Check [jest-puppeteer](https://github.com/smooth-code/jest-puppeteer#jest-puppeteerconfigjs) for more details. diff --git a/packages/scripts/scripts/test-e2e.js b/packages/scripts/scripts/test-e2e.js index 8105891c8d838..374ebc59f6fbe 100644 --- a/packages/scripts/scripts/test-e2e.js +++ b/packages/scripts/scripts/test-e2e.js @@ -43,11 +43,23 @@ const runInBand = ! hasRunInBand ? [ '--runInBand' ] : []; -const cleanUpPrefixes = [ '--puppeteer-' ]; - if ( hasCliArg( '--puppeteer-interactive' ) ) { process.env.PUPPETEER_HEADLESS = 'false'; process.env.PUPPETEER_SLOWMO = getCliArg( '--puppeteer-slowmo' ) || 80; } +const configsMapping = { + WP_BASE_URL: '--wordpress-base-url', + WP_USERNAME: '--wordpress-username', + WP_PASSWORD: '--wordpress-password', +}; + +Object.entries( configsMapping ).forEach( ( [ envKey, argName ] ) => { + if ( hasCliArg( argName ) ) { + process.env[ envKey ] = getCliArg( argName ); + } +} ); + +const cleanUpPrefixes = [ '--puppeteer-', '--wordpress-' ]; + jest.run( [ ...config, ...runInBand, ...getCliArgs( cleanUpPrefixes ) ] );