Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve e2e testing docs and add cli args. #14717

Merged
merged 5 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 14 additions & 2 deletions packages/scripts/scripts/test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ] );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const cleanUpPrefixes = [ '--puppeteer-' ];

At the moment cleanUpPrefixes doesn't filter out --wordpress-. It should be a good practice to ensure they are never passed to Jest as we discovered some issues with --interactive in the past.

Screen Shot 2019-04-01 at 10 23 38

That's why @draganescu added logic which allows to filter out CLI args starting with a given pattern.

Copy link
Member Author

@nicolad nicolad Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't knew that, had adjusted, thx.