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
Allow tests to access local version of web worker. #9475
Conversation
src/web-worker/amp-worker.js
Outdated
@@ -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); |
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.
Not sure about this change here. Without it, we're not pulling the web worker from local code. @choumx WDYT?
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.
That's fine. Could use a better var name though.
const useLocalFile = getMode().localDev || getMode().test;
const useRtvVersion = !useLocalFile;
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.
done
src/service/extension-location.js
Outdated
* @return {string} | ||
*/ | ||
export function calculateEntryPointScriptUrl( | ||
location, entryPoint, isLocalDev, opt_rtv) { | ||
location, entryPoint, isLocalDev, opt_rtv, opt_minifed) { |
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.
Do you think opt_minified should be changed to opt_notMinified so that the non-max url is returned by defaukt?
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.
Nah, inverted bools are harder to read.
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.
/cc @zhouyx @jridgewell
src/service/extension-location.js
Outdated
* @return {string} | ||
*/ | ||
export function calculateEntryPointScriptUrl( | ||
location, entryPoint, isLocalDev, opt_rtv) { | ||
location, entryPoint, isLocalDev, opt_rtv, opt_minifed) { |
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.
Nah, inverted bools are harder to read.
src/service/extension-location.js
Outdated
return `${base}/rtv/${getMode().rtvVersion}/${entryPoint}.js`; | ||
} | ||
return `${base}/${entryPoint}.js`; | ||
const version = opt_minifed ? '' : '.max'; |
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.
filename
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.
done
src/service/extension-location.js
Outdated
return `${base}/${entryPoint}.js`; | ||
const version = opt_minifed ? '' : '.max'; | ||
const rtv = opt_rtv ? `/rtv/${getMode().rtvVersion}` : ''; | ||
return `${base}${rtv}/${entryPoint}${version}.js`; |
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.
I think having the conditional is more readable 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.
ok
src/web-worker/amp-worker.js
Outdated
@@ -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); |
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.
That's fine. Could use a better var name though.
const useLocalFile = getMode().localDev || getMode().test;
const useRtvVersion = !useLocalFile;
src/service/extension-location.js
Outdated
@@ -49,13 +49,13 @@ export function calculateExtensionScriptUrl(location, extensionId, isLocalDev) { | |||
* @param {string} entryPoint | |||
* @param {boolean=} isLocalDev | |||
* @param {boolean=} opt_rtv | |||
* @param {boolean=} opt_minifed |
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.
opt_minified
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.
thanks
src/service/extension-location.js
Outdated
* @return {string} | ||
*/ | ||
export function calculateEntryPointScriptUrl( | ||
location, entryPoint, isLocalDev, opt_rtv) { | ||
location, entryPoint, isLocalDev, opt_rtv, opt_minifed) { |
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.
opt_minified
expect(script).to.equal('http://localhost:8000/dist/sw.js'); | ||
}, | ||
'sw', | ||
/* isLocalDev */ true); |
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.
This indentation looks weird.
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.
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.
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.
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. 😃
src/service/extension-location.js
Outdated
const base = calculateScriptBaseUrl(location, isLocalDev); | ||
if (opt_rtv) { | ||
if (opt_rtv && opt_minified) { |
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.
const rtv = opt_rtv ? `/rtv/${getMode().rtvVersion}` : '';
const max = opt_minified ? '' : '.max';
return `${base}${rtv}/${entryPoint}${max}.js`
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.
This is what I had before. @choumx @jridgewell which way do we want to go with?
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.
Ours are almost 100% the same. I think that means it's the better option. 😉
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.
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.
src/service/extension-location.js
Outdated
* @return {string} | ||
*/ | ||
export function calculateEntryPointScriptUrl( | ||
location, entryPoint, isLocalDev, opt_rtv) { | ||
location, entryPoint, isLocalDev, opt_rtv, opt_minified) { |
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.
@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.
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.
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
.
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.
Can't you set the test server to serve max files?
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.
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
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.
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.
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.
I thought https://github.com/ampproject/amphtml/blob/master/build-system/tasks/runtime-test.js#L196 did the work for us
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.
Looks like that var refers to test-server.js
. Perhaps we should consolidate though.
src/service/extension-location.js
Outdated
return `${base}/rtv/${getMode().rtvVersion}/${entryPoint}.js`; | ||
} else if (opt_rtv) { | ||
return `${base}/rtv/${getMode().rtvVersion}/${entryPoint}.max.js`; |
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.
can someone walk me through on how the opt-rtv
work?
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.
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.
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.
It's needed to support canary-ing of ww.js
since it's fetched by AMP JS rather than from the AMP page.
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.
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
?
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.
Yea, maybe we can make this change in test-server.js
along with the other stuff above.
@kmh287 A couple of good suggested changes, let's discuss it more tomorrow. 😄 |
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.
Thanks for the comments, everyone. I've updated the approach and hopefully addressed all previous comments. PTAL.
build-system/test-server.js
Outdated
/** | ||
* Serve entry point script url | ||
*/ | ||
app.get('/dist/ww.js', function(req, res, next) { |
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.
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.
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.
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.
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.
Yea, the middleware setting isn't working for some reason. Kevin, can you add a TODO/issue to investigate that?
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 should eventually get rid of this 2nd server running in a different port. This probably can fix your problem: #9561
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.
So close this PR in favor of #9561 ?
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.
@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.
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.
In your test browser, can you try to load "http://localhost:9876/dist/ww.js"? It worked on our end.
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.
I think he was saying we should eventually get rid of the second server, not that the referenced PR does it.
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.
@lannka I get the min version only if I've run gulp dist
since running gulp clean
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.
@lannka and I resolved on chat. I needed to update karma.
d531fc1
to
387858e
Compare
387858e
to
329da81
Compare
@jridgewell @zhouyx @choumx @lannka PTAL |
/to @choumx