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

Allow for extra Playwright CLI options when running e2e tests #1768

Merged
merged 5 commits into from
Apr 2, 2024

Conversation

jdeanwallace
Copy link
Contributor

@jdeanwallace jdeanwallace commented Mar 31, 2024

Resolves #1696

This PR allows for extra Playwright CLI options to passed to Playwright when running e2e tests.

For example, this means you can guide Playwright on which tests to run like so:

./dev-scripts/run-e2e-tests -- --grep 'shows privacy policy'

Review on CodeApprove

@jdeanwallace jdeanwallace marked this pull request as ready for review March 31, 2024 14:03
@jdeanwallace jdeanwallace changed the title Allow for extra Playwright CLI options. Allow for extra Playwright CLI options when running e2e test Mar 31, 2024
@jdeanwallace jdeanwallace changed the title Allow for extra Playwright CLI options when running e2e test Allow for extra Playwright CLI options when running e2e tests Mar 31, 2024
Copy link
Contributor Author

Automated comment from CodeApprove ➜

@jotaen4tinypilot please review this Pull Request

Copy link
Contributor

@jotaen4tinypilot jotaen4tinypilot left a comment

Choose a reason for hiding this comment

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

Automated comment from CodeApprove ➜

⏳ Approval Pending (1 unresolved comments)
Approval will be granted automatically when all comments are resolved


In: dev-scripts/run-e2e-tests:

> Line 40
# If the first positional argument starts with 'http', strip it to export it as

Just bouncing this as a thought here: I’m a bit on the fence with providing two optional positional arguments, as that is ambiguous to parse. Without reading this code comment, it might not be 100% clear from the outside how this script disambiguates the two arguments.

In my mind, the ideal and most “conventional” way for the script API would be:

  • Make E2E_BASE_URL a named flag, like --baseUrl http://...
  • Separate the script flags from the Playwright flags via a -- separator

That way, you could do:

./run-e2e-tests --baseUrl http://localhost:123 -- --grep 'foo'

That being said, I think we’ve never used the -- separator in our scripts, so I don’t know how much work it would be, or whether it’d be worth to invest that for an internal dev script.

So depending on what your thoughts are, to me it would be fine to leave this as proposed, though I think we could then address the flag parsing behaviour more explicitly in the help output.


👀 @jdeanwallace it's your turn please take a look

Copy link
Contributor Author

@jdeanwallace jdeanwallace left a comment

Choose a reason for hiding this comment

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

Automated comment from CodeApprove ➜

In: dev-scripts/run-e2e-tests:
Oh yeah, that makes sense. I was intrigued by the -- idea, so did implement it here.

Can you check once again if all is in order?


👀 @jotaen4tinypilot it's your turn please take a look

mtlynch
mtlynch previously requested changes Apr 1, 2024
Copy link
Contributor

@mtlynch mtlynch left a comment

Choose a reason for hiding this comment

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

Automated comment from CodeApprove ➜

In: dev-scripts/run-e2e-tests:
Neat!


In: dev-scripts/run-e2e-tests:

> Line 88
npx playwright test "${PLAYWRIGHT_ARGS[@]+"${PLAYWRIGHT_ARGS[@]}"}"

This is some wacky bash!

Can we add a comment explaining what it's doing? I feel like nobody will understand it except for like the top 5% of bash developers.


👀 @jdeanwallace, @jotaen4tinypilot it's your turn please take a look

Copy link
Contributor

@jotaen4tinypilot jotaen4tinypilot left a comment

Choose a reason for hiding this comment

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

Automated comment from CodeApprove ➜

⏳ Approval Pending (3 unresolved comments)
Approval will be granted automatically when all comments are resolved


In: dev-scripts/run-e2e-tests:
🎉


In: dev-scripts/run-e2e-tests:

> Line 19
  --                      Optional. Indicate the end of this script's CLI

I’m wondering whether we could consolidate -- and PLAYWRIGHT_ARGS into a single help item. My reasoning would be that they are not independent from each other, but it’s either both or none (i.e., you specify -- to enter Playwright-args land).

This should in theory be clear from the Usage string definition, which we only reference here, but I think there might still be potential room for misunderstanding.


In: dev-scripts/run-e2e-tests:

> Line 48
      shift

What would you think about initializing $PLAYWRIGHT_ARGS as empty array (PLAYWRIGHT_ARGS=()) above the while, and then doing the ("$@") assignment here? I’m thinking that this could make the code more cohesive, and thus slightly easier to follow – like:

--)
  # Stop parsing command-line arguments, and capture all remaining
  # args to pass them through to Playwright.
  shift
  PLAYWRIGHT_ARGS=("$@")
  break

In: dev-scripts/run-e2e-tests:

> Line 88
npx playwright test "${PLAYWRIGHT_ARGS[@]+"${PLAYWRIGHT_ARGS[@]}"}"

Would it be safe to always pass on $PLAYWRIGHT_ARGS to npx ..., even if it’s empty? Or is there a scenario where Playwright might complain?


👀 @jdeanwallace, @mtlynch it's your turn please take a look

Copy link
Contributor Author

@jdeanwallace jdeanwallace left a comment

Choose a reason for hiding this comment

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

Automated comment from CodeApprove ➜

In: dev-scripts/run-e2e-tests:
Done.


In: dev-scripts/run-e2e-tests:

> Line 49
      shift

Done.


In: dev-scripts/run-e2e-tests:

> Line 93
npx playwright test "${PLAYWRIGHT_ARGS[@]+"${PLAYWRIGHT_ARGS[@]}"}"

Can we add a comment explaining what it's doing?

Done.

Would it be safe to always pass on $PLAYWRIGHT_ARGS to npx ..., even if it’s empty? Or is there a scenario where Playwright might complain?

Yes, if $PLAYWRIGHT_ARGSis empty, nothing is passed to npx.


👀 @mtlynch it's your turn please take a look

@jotaen4tinypilot jotaen4tinypilot dismissed their stale review April 2, 2024 13:07

Review approved on CodeApprove

Copy link
Contributor

@jotaen4tinypilot jotaen4tinypilot left a comment

Choose a reason for hiding this comment

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

Automated comment from CodeApprove ➜

Approved: I have approved this change on CodeApprove and all of my comments have been resolved.

@mtlynch mtlynch dismissed their stale review April 2, 2024 13:07

Review approved on CodeApprove

@jdeanwallace jdeanwallace merged commit aa9bd31 into master Apr 2, 2024
14 checks passed
@jdeanwallace jdeanwallace deleted the e2e-playwright-options branch April 2, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it easier to run a single playwright test
3 participants