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

ProjectRemixTest passes on ChromeHeadless #32520

Merged
merged 1 commit into from Jan 6, 2020

Conversation

islemaster
Copy link
Contributor

I've been trying to run tests in ChromeHeadless on my local machine, since PhantomJS isn't working properly on recent versions of Ubuntu. Eventually, I'd like us to use ChromeHeadless in our CI builds too, but to do that, we need to fix up all the tests that fail on this browser.

One of the tests that fails is ProjectRemix#will redirect to sign in if necessary. I believe this fixes that test under both ChromeHeadless and PhantomJS.

See also

Reviewer Checklist:

  • Tests provide adequate coverage
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@@ -54,18 +54,18 @@ describe('ProjectRemix', () => {
});

it('will redirect to sign in if necessary', () => {
sinon.stub(window.location, 'assign');
sinon.stub(utils, 'navigateToHref');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ChromeHeadless complains right here, because Chrome won't let you stub methods on its built-in Location object.

@@ -21,7 +21,7 @@ class ProjectRemix extends React.Component {
) {
dashboard.project.serverSideRemix();
} else if (!this.props.isSignedIn) {
window.location.assign(
utils.navigateToHref(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We fix by switching to our own navigateToHref function, which exists entirely for making scenarios like this testable.

/**
* Wrapper for window.location.href which we can stub in unit tests.
* @param {string} href Location to navigate to.
*/
export function navigateToHref(href) {
if (!IN_UNIT_TEST) {
window.location.href = href;
}
}

And if you're wondering about the difference between location.assign(x) and location.href = x... apparently there is none.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that location.assign enforces same-origin domain (see the specs for location.href = and location.assign); are we confident that's not relevant here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, I had no idea. Nice catch. I'm pretty sure it's not relevant here because we've hard-coded /users/sign_in into the call, which is an origin-relative path to begin with. The only thing I can think of is if there's some convoluted case with iframes, but window.location != window.parent.location so I think that's a non-issue too.

@islemaster islemaster changed the title ProjectRemix passes on ChromeHeadless ProjectRemixTest passes on ChromeHeadless Dec 20, 2019
Copy link
Contributor

@Hamms Hamms left a comment

Choose a reason for hiding this comment

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

one question, otherwise LGTM

@@ -21,7 +21,7 @@ class ProjectRemix extends React.Component {
) {
dashboard.project.serverSideRemix();
} else if (!this.props.isSignedIn) {
window.location.assign(
utils.navigateToHref(
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that location.assign enforces same-origin domain (see the specs for location.href = and location.assign); are we confident that's not relevant here?

@islemaster islemaster merged commit a700b0d into staging Jan 6, 2020
@islemaster islemaster deleted the projectremix-chromeheadless branch January 6, 2020 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants