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

Use getMode().test to indicate testing environment during test #3699

Merged
merged 2 commits into from Jun 23, 2016

Conversation

muxin
Copy link
Contributor

@muxin muxin commented Jun 21, 2016

No description provided.

@@ -196,8 +196,8 @@ export function getBootstrapBaseUrl(parentWindow, opt_strictForUnitTest) {
* @return {string}
*/
function getDefaultBootstrapBaseUrl(parentWindow) {
if (getMode().localDev || parentWindow.AMP_TEST) {
const prefix = parentWindow.AMP_TEST ? '/base' : '';
if (getMode().localDev || getMode().test) {
Copy link
Member

Choose a reason for hiding this comment

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

@erwinmombay This should still be DCEable with our custom pass, right?

Copy link
Member

Choose a reason for hiding this comment

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

@cramforce yes, will continue working on that. will need to expose it at module level instead of a value from getMode(). was struggling with getting tests to pass with my DCE changes but should be close.

@cramforce
Copy link
Member

LGTM

@@ -71,7 +71,7 @@ export function createFixtureIframe(fixture, initialIframeHeight, opt_beforeLoad
// on that window.
window.beforeLoad = function(win) {
// Flag as being a test window.
win.AMP_TEST = true;
win.AMP_TEST_IFRAME = true;
Copy link
Member

Choose a reason for hiding this comment

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

You still need to set AMP_TEST 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.

I assume AMP_TEST belongs to the global window, not the testing iframe. I set it here

Copy link
Member

Choose a reason for hiding this comment

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

Maybe these names should be changed, but I think the semantics are simple:

  • AMP_TEST: behave specific to a unit test. This should e.g. trigger localhost-y URLs
  • AMP_TEST_IFRAME: This is a per-test iframe. Behave accordingly.

With that you either always want to set AMP_TEST when AMP_TEST_IFRAME is set, or make getMode look at both variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's the semantics I mean.
The getMode method currently is reading cached mode variable once the mode is set (see this) Shall I update the mode variable every time I set window.AMP_TEST? If that's the case, we can just set mode.test to true for every unit test and we don't even need to set window.AMP_TEST.
I don't understand the usage of AMP_TEST_IFRAME. Why do we need such a flag for each testing iframe?

Copy link
Member

Choose a reason for hiding this comment

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

I think we are speaking entirely passed easy other. Lets chat in person.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set window.AMP_TEST to true.

@muxin
Copy link
Contributor Author

muxin commented Jun 23, 2016

@cramforce PTAL

@cramforce
Copy link
Member

LGTM

@muxin muxin merged commit 3917f80 into ampproject:master Jun 23, 2016
@muxin muxin deleted the test-mode branch June 23, 2016 17:58
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.

None yet

3 participants