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

Allow tests to access local version of web worker. #9475

Merged
merged 8 commits into from May 26, 2017

Conversation

kmh287
Copy link
Contributor

@kmh287 kmh287 commented May 22, 2017

/to @choumx

@@ -76,7 +76,7 @@ class AmpWorker {
// Use RTV to make sure we fetch prod/canary/experiment correctly.
const useRtvVersion = !getMode().localDev && !getMode().test;
const url = calculateEntryPointScriptUrl(
loc, 'ww', getMode().localDev, useRtvVersion);
loc, 'ww', !useRtvVersion, useRtvVersion, getMode().minified);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this change here. Without it, we're not pulling the web worker from local code. @choumx WDYT?

Choose a reason for hiding this comment

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

That's fine. Could use a better var name though.

const useLocalFile = getMode().localDev || getMode().test;
const useRtvVersion = !useLocalFile;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

* @return {string}
*/
export function calculateEntryPointScriptUrl(
location, entryPoint, isLocalDev, opt_rtv) {
location, entryPoint, isLocalDev, opt_rtv, opt_minifed) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think opt_minified should be changed to opt_notMinified so that the non-max url is returned by defaukt?

Choose a reason for hiding this comment

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

Nah, inverted bools are harder to read.

Copy link

@dreamofabear dreamofabear left a comment

Choose a reason for hiding this comment

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

* @return {string}
*/
export function calculateEntryPointScriptUrl(
location, entryPoint, isLocalDev, opt_rtv) {
location, entryPoint, isLocalDev, opt_rtv, opt_minifed) {

Choose a reason for hiding this comment

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

Nah, inverted bools are harder to read.

return `${base}/rtv/${getMode().rtvVersion}/${entryPoint}.js`;
}
return `${base}/${entryPoint}.js`;
const version = opt_minifed ? '' : '.max';

Choose a reason for hiding this comment

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

filename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return `${base}/${entryPoint}.js`;
const version = opt_minifed ? '' : '.max';
const rtv = opt_rtv ? `/rtv/${getMode().rtvVersion}` : '';
return `${base}${rtv}/${entryPoint}${version}.js`;

Choose a reason for hiding this comment

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

I think having the conditional is more readable 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.

ok

@@ -76,7 +76,7 @@ class AmpWorker {
// Use RTV to make sure we fetch prod/canary/experiment correctly.
const useRtvVersion = !getMode().localDev && !getMode().test;
const url = calculateEntryPointScriptUrl(
loc, 'ww', getMode().localDev, useRtvVersion);
loc, 'ww', !useRtvVersion, useRtvVersion, getMode().minified);

Choose a reason for hiding this comment

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

That's fine. Could use a better var name though.

const useLocalFile = getMode().localDev || getMode().test;
const useRtvVersion = !useLocalFile;

@@ -49,13 +49,13 @@ export function calculateExtensionScriptUrl(location, extensionId, isLocalDev) {
* @param {string} entryPoint
* @param {boolean=} isLocalDev
* @param {boolean=} opt_rtv
* @param {boolean=} opt_minifed

Choose a reason for hiding this comment

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

opt_minified

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

* @return {string}
*/
export function calculateEntryPointScriptUrl(
location, entryPoint, isLocalDev, opt_rtv) {
location, entryPoint, isLocalDev, opt_rtv, opt_minifed) {

Choose a reason for hiding this comment

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

opt_minified

expect(script).to.equal('http://localhost:8000/dist/sw.js');
},
'sw',
/* isLocalDev */ true);

Choose a reason for hiding this comment

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

This indentation looks weird.

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 think so too, but this is what the linter wants. I think it's technically correct since the first argument is on the same line as the call, and the rest of the args are indented by four.

Choose a reason for hiding this comment

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

If these args can't fit on the same line, can you extract the object literal into a separate var instead? The linter ought to be a sanity check rather than the final authority on readability. 😃

const base = calculateScriptBaseUrl(location, isLocalDev);
if (opt_rtv) {
if (opt_rtv && opt_minified) {
Copy link
Contributor

Choose a reason for hiding this comment

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

const rtv = opt_rtv ? `/rtv/${getMode().rtvVersion}` : '';
const max = opt_minified ? '' : '.max';
return `${base}${rtv}/${entryPoint}${max}.js`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I had before. @choumx @jridgewell which way do we want to go with?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ours are almost 100% the same. I think that means it's the better option. 😉

Choose a reason for hiding this comment

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

Not a big deal, but I think having possibly empty strings in the format string makes it harder to verify that slashes, etc. are correct. Another option is to incrementally build the url string.

* @return {string}
*/
export function calculateEntryPointScriptUrl(
location, entryPoint, isLocalDev, opt_rtv) {
location, entryPoint, isLocalDev, opt_rtv, opt_minified) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@kmh287 Trying to understand why we need it back? I think we are trying to avoid this minified logic in PROD as much as we can.

Copy link

Choose a reason for hiding this comment

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

To be able to run gulp test without --compiled. Currently we always serve the minified version which requires gulp dist to be run first.

We can remove this once unit tests no longer require gulp build.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you set the test server to serve max files?

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we always serve unminified version when running gulp test without --compiled
https://github.com/ampproject/amphtml/blob/master/build-system/tasks/runtime-test.js#L181

Choose a reason for hiding this comment

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

Can't you set the test server to serve max files?

Hmm, we could do that. We'd need to dupe the logic in app.js into test-server.js.

I thought we always serve unminified version when running gulp test without --compiled

Only for the app.js server which currently doesn't run during testing.

Another issue is that location.host actually returns the Karma server on localhost, so that needs to change to the test server's port.

Copy link
Contributor

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Looks like that var refers to test-server.js. Perhaps we should consolidate though.

return `${base}/rtv/${getMode().rtvVersion}/${entryPoint}.js`;
} else if (opt_rtv) {
return `${base}/rtv/${getMode().rtvVersion}/${entryPoint}.max.js`;
Copy link
Contributor

Choose a reason for hiding this comment

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

can someone walk me through on how the opt-rtv work?

Choose a reason for hiding this comment

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

It fetches the current RTV file instead of the un-versioned file, e.g. cdn.ampproject.org/rtv/123/v0.js vs. cdn.ampproject.org/v0.js. We should never fetch max AND RTV though.

Choose a reason for hiding this comment

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

It's needed to support canary-ing of ww.js since it's fetched by AMP JS rather than from the AMP page.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think better solution here is to always return ${base}/rtv/${getMode().rtvVersion}/${entryPoint}.js And let the local server choose what the right file to serve based on serving mode. Just like what we do with #calculateExtensionScriptUrl?

Choose a reason for hiding this comment

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

Yea, maybe we can make this change in test-server.js along with the other stuff above.

@dreamofabear
Copy link

@kmh287 A couple of good suggested changes, let's discuss it more tomorrow. 😄

Copy link
Contributor Author

@kmh287 kmh287 left a comment

Choose a reason for hiding this comment

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

Thanks for the comments, everyone. I've updated the approach and hopefully addressed all previous comments. PTAL.

@kmh287 kmh287 changed the title Add support for fetching non-compiled URLs in extension-location#calculateEntryPointScriptUrl. Allow tests to access max version of web worker. May 24, 2017
/**
* Serve entry point script url
*/
app.get('/dist/ww.js', function(req, res, next) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this is needed.
We have https://github.com/ampproject/amphtml/blob/master/build-system/tasks/karma.conf.js#L188
where we import our gulp webserver as a Karma server middleware.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In app.js, around line 850, mode is not set to 'default' and so the min version is used.

When I comment out the added code in test-server.js, test-bind-impl.js pulls in the min version or outright fails if gulp dist hasn't been run since the last gulp clean. Witht his code added, the test pulls in the max version.

Choose a reason for hiding this comment

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

Yea, the middleware setting isn't working for some reason. Kevin, can you add a TODO/issue to investigate that?

Copy link
Contributor

Choose a reason for hiding this comment

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

we should eventually get rid of this 2nd server running in a different port. This probably can fix your problem: #9561

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So close this PR in favor of #9561 ?

Copy link
Contributor Author

@kmh287 kmh287 May 26, 2017

Choose a reason for hiding this comment

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

@lannka I've pulled in that PR and I'm still seeing errors while testing if I don't first run gulp dist. Without the changes to test-server.js, the test still requests the minified web worker.

Copy link
Contributor

Choose a reason for hiding this comment

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

In your test browser, can you try to load "http://localhost:9876/dist/ww.js"? It worked on our end.

Choose a reason for hiding this comment

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

I think he was saying we should eventually get rid of the second server, not that the referenced PR does it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lannka I get the min version only if I've run gulp dist since running gulp clean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lannka and I resolved on chat. I needed to update karma.

@kmh287 kmh287 force-pushed the bind_integration_test_fixes branch 2 times, most recently from d531fc1 to 387858e Compare May 26, 2017 19:39
@kmh287 kmh287 force-pushed the bind_integration_test_fixes branch from 387858e to 329da81 Compare May 26, 2017 19:39
@kmh287 kmh287 changed the title Allow tests to access max version of web worker. Allow tests to access local version of web worker. May 26, 2017
@kmh287
Copy link
Contributor Author

kmh287 commented May 26, 2017

@jridgewell @zhouyx @choumx @lannka PTAL

@dreamofabear dreamofabear merged commit 392bfad into ampproject:master May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants