Skip to content

Fix Cypress path checks to allow sub-directory#4945

Merged
gziolo merged 2 commits intoWordPress:masterfrom
jaswrks:fix/cypress-path-checks
Feb 8, 2018
Merged

Fix Cypress path checks to allow sub-directory#4945
gziolo merged 2 commits intoWordPress:masterfrom
jaswrks:fix/cypress-path-checks

Conversation

@jaswrks
Copy link
Copy Markdown
Contributor

@jaswrks jaswrks commented Feb 8, 2018

Description

Subtle changes in this PR allow a developer to set a custom base URL for Cypress using an environment variable, where the custom base URL includes a subdirectory. For example, note the /wp subdirectory in this command:

cypress_base_url=http://localhost:8888/wp npm run test-e2e

This wasn't working before. We were running tests against URL paths without considering the possibility of a leading subdirectory in each path. Fixed in this PR.

How Has This Been Tested?

@iseulde and I tested this by running E2E tests in a subdirectory, with help from @youknowriad.

Types of changes

Use regex to test location instead of ===.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.

@ntwb
Copy link
Copy Markdown
Member

ntwb commented Feb 8, 2018

Why a8c Slack? Was that meant to be a WordPress Slack link?

@jaswrks
Copy link
Copy Markdown
Contributor Author

jaswrks commented Feb 8, 2018

My bad. I removed it, thanks for pointing that out to me.

@jaswrks
Copy link
Copy Markdown
Contributor Author

jaswrks commented Feb 8, 2018

It wasn't meant to be a WordPress Slack link, no. The discussion took place in a8c, and I wrongly posted the a8c link without considering the implication.

Cypress.Commands.add( 'visitAdmin', ( adminPath ) => {
cy.visit( '/wp-admin/' + adminPath ).location( 'pathname' ).then( ( path ) => {
if ( path === '/wp-login.php' ) {
if ( /\/wp-login\.php$/.test( path ) ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could use also endsWith to make it even simpler. Not sure if that matters that much though :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I will do that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@ntwb
Copy link
Copy Markdown
Member

ntwb commented Feb 8, 2018

Thanks, but can we please try to have discussions publicly available, please.

If discussions are to take place in Slack then please use the WordPress Slack Workspace that is at least open for anyone to join unlike the Automattic Slack Workspace that is not.

p.s https://chat.wordpress.org if you'd like to join the WordPress Slack workspace 😄

@jaswrks
Copy link
Copy Markdown
Contributor Author

jaswrks commented Feb 8, 2018

Absolutely, I will be sure to do that in the future. 😃

@gziolo gziolo merged commit 907e2d2 into WordPress:master Feb 8, 2018
@gziolo
Copy link
Copy Markdown
Member

gziolo commented Feb 8, 2018

Thanks @jaswrks 👍

@ellatrix
Copy link
Copy Markdown
Member

ellatrix commented Feb 8, 2018

Thanks, but can we please try to have discussions publicly available, please.

If discussions are to take place in Slack then please use the WordPress Slack Workspace that is at least open for anyone to join unlike the Automattic Slack Workspace that is not.

@ntwb This was my fault, I initiated the discussion. I pinged someone privately because I was unsure about the problem I was experiencing. I'll be less shy next time. 😊

Cypress.Commands.add( 'visitAdmin', ( adminPath ) => {
cy.visit( '/wp-admin/' + adminPath ).location( 'pathname' ).then( ( path ) => {
if ( path === '/wp-login.php' ) {
if ( path.endsWith( '/wp-login.php' ) ) {
Copy link
Copy Markdown
Member

@ellatrix ellatrix Feb 8, 2018

Choose a reason for hiding this comment

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

I don't think we polyfill these ATM with Babel. I've been made aware of this several times by @aduth . :) Maybe use the Lodash version here instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Though, this probably runs in the Cypress runner which doesn't have the same constraints as the browser (or all browsers)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, it's node 8 + electron or Chrome. Travis is happy so are we :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, stupid me, I just saw the lines and my alarm bells went off without realising this is Cypress. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants