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
Conversation
@@ -54,18 +54,18 @@ describe('ProjectRemix', () => { | |||
}); | |||
|
|||
it('will redirect to sign in if necessary', () => { | |||
sinon.stub(window.location, 'assign'); | |||
sinon.stub(utils, 'navigateToHref'); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
code-dot-org/apps/src/utils.js
Lines 715 to 723 in 209b008
/** | |
* 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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( |
There was a problem hiding this comment.
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?
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: