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

chore: Update switchToDomain signature with args key #20722

Merged
merged 13 commits into from
Mar 24, 2022

Conversation

AtofStryker
Copy link
Contributor

@AtofStryker AtofStryker commented Mar 21, 2022

  • Closes n/a

User facing changelog

n/a

Additional details

The goal of this PR is to update the data argument in switchToDomain to be an object with an args property where users can pass in user defined data to be sent over to their switchToDomain call. This is currently replacing a generic array, which causes issues when there are are multiple types in the array and the index of said type cannot be implied, leading to OR on the types in the array.

Currently, args is required if leveraging the data argument since there currently aren't other options. a TODO comment has been added to overload the type once options become available, which will give better typings to args in the switchToDomain callback itself.

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?
  • Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 21, 2022

Thanks for taking the time to open a PR!

@AtofStryker AtofStryker changed the title Update switch to domain signature Chore: Update switchToDomain signature with args key Mar 21, 2022
@AtofStryker AtofStryker changed the title Chore: Update switchToDomain signature with args key chore: Update switchToDomain signature with args key Mar 21, 2022
@AtofStryker AtofStryker force-pushed the update_switch_to_domain_signature branch from a017acb to bfc574c Compare March 21, 2022 20:23
@cypress
Copy link

cypress bot commented Mar 21, 2022



Test summary

20551 0 282 4Flakiness 0


Run details

Project cypress
Status Passed
Commit 331cf39
Started Mar 23, 2022 8:19 PM
Ended Mar 23, 2022 8:34 PM
Duration 15:33 💡
OS Linux Debian - 10.10
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@AtofStryker AtofStryker marked this pull request as ready for review March 22, 2022 14:41
@AtofStryker AtofStryker requested a review from a team as a code owner March 22, 2022 14:41
Copy link
Contributor

@chrisbreiding chrisbreiding left a comment

Choose a reason for hiding this comment

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

I didn't leave code suggestions everywhere they're needed, but I think we should make sure the argument to switchToDomain is called options and that we consistently use args instead of data for the object getting serialized and passed to the switchToDomain callback.

cli/types/cypress.d.ts Outdated Show resolved Hide resolved
packages/driver/src/cy/multi-domain/index.ts Outdated Show resolved Hide resolved
packages/driver/src/cy/multi-domain/index.ts Outdated Show resolved Hide resolved
packages/driver/src/cy/multi-domain/index.ts Outdated Show resolved Hide resolved
packages/driver/src/cy/multi-domain/validator.ts Outdated Show resolved Hide resolved
packages/driver/src/cy/multi-domain/validator.ts Outdated Show resolved Hide resolved
packages/driver/src/cy/multi-domain/validator.ts Outdated Show resolved Hide resolved
Comment on lines 31 to 36
} else if (options && !Object.getOwnPropertyDescriptor(options, 'args')) {
this.onFailure()

$errUtils.throwErrByPath('switchToDomain.incomplete_options_argument', {
onFail: this.log,
args: { arg: $utils.stringify(options) },
Copy link
Contributor

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 should throw in this case. It's fine for there to be an empty options object and in the future, it will be fine for it only have other options and not the args property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured since we do not have any additional properties as of now, it would make sense to verify that the args key exists, and then update this method and types as we add in other options. Currently, throwing here might be beneficial to the user so they don't try to do something like below and then scratch their head for a while trying to figure out what was missed.

cy.switchToDomain('foobar.com', { foo: 'foo' }, ({ foo }) => {
  expect(foo).to.be('foo') // fails because it's undefined
})

Copy link
Member

Choose a reason for hiding this comment

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

Could we throw if they provide any keys other than the ones we allow? We'd only allow args for now, but that would cover the case where they are a passing in the wrong args at the wrong level.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like @mjhenkes's idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mjhenkes I'll update the PR to favor checking for keys other than that which we allow. I'll probably opt for something similar to how we verify the cypress config

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in 2f8317f

…in options argument over missing the args key
…s-io/cypress into update_switch_to_domain_signature
@AtofStryker AtofStryker merged commit 90d1eb7 into feature-multidomain Mar 24, 2022
@AtofStryker AtofStryker deleted the update_switch_to_domain_signature branch March 24, 2022 14:50
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.

3 participants