Make new-style script objects a bundle.#32
Make new-style script objects a bundle.#32hawkinsw wants to merge 1 commit intomozilla:masterfrom hawkinsw:bundle_prepost_in_script
Conversation
ncalexan
left a comment
There was a problem hiding this comment.
So I can see where this is going, but I have some high-level questions to discuss before nailing down the specifics.
-
Fundamentally I still don't understand why the new pre- and post-scripts look so different to the existing pre- and post-scripts. We talked about this before we split out the first part of the work, and it's not clarified here. To whit: this is all possible right now with a
--{pre,post}Script-- it's just a little hidden 'cuz of the new JS execution APIs. It's very awkward to transition between a regular and a new-style pre-script, say, 'cuz the APIs are different. Can we harmonize this? -
This doesn't handle the most fundamental "pre" condition, which is whether a particular script is wanted. Let's make the pre-script return a boolean, allowing it to inspect the environment/command line (see the API changes requested above) in order to know whether or not to run it. (Without this we can't add new "feature-like" measurements that are opt-in.)
What happens if a pre- or post- script raises an error? We shouldn't run the measurement collection if we couldn't set up the pre-conditions.
| const filterWhitelisted = require('../../../support/userTiming') | ||
| .filterWhitelisted; | ||
| const { isAndroidConfigured, createAndroidConnection } = require('../../../android'); | ||
| const { |
There was a problem hiding this comment.
Minimize these white space changes, please. Every one is a merge conflict waiting to happen.
There was a problem hiding this comment.
Here and many places. They're not only merge conflicts, they take time to review and process.
| * Look through the scripts and try to do our post scripts. | ||
| */ | ||
| if (this.scriptsByCategory) { | ||
| await browser.runScripts( |
There was a problem hiding this comment.
This is very horizontally narrow. Can we please use our large monitors? We don't have infinite vertical space!
There was a problem hiding this comment.
eslint (correctly, imo!) says that we do not want lines longer than 80 characters, the standard terminal size. Because this line will end up being longer than 80 characters, eslint seems to aggressively add new lines between each of the parameters and line them up vertically. What do you suggest as the maximum line length? I can change that and commit it to the eslint rules in the repo so that this is not a problem in the future.
| module.exports = { | ||
| requires: { privilege: true }, | ||
| function: async function() { | ||
| pre: function() {}, |
There was a problem hiding this comment.
Can we have an example (or a new script?) with non-trivial pre and post?
There was a problem hiding this comment.
There is an example included in the docs/ directory. Would you like me to commit it to the repo?
There was a problem hiding this comment.
Yes, I want there to be an example (command-line-option-ed off) that's easy for everybody to run/copy.
| try { | ||
| result[name] = generateScriptObject(name, root, script); | ||
| } catch (e) { | ||
| log.error('Could not parse user script ' + name + ': ' + e); |
There was a problem hiding this comment.
Why is this a problem now? Can we avoid this whole business by having generateScriptObject do whatever it would have done before?
| ScriptType.POST | ||
| ); | ||
| } | ||
| if (this.asyncScriptsByCategory) { |
There was a problem hiding this comment.
Do we think that order matters? Should we try to execute like:
pre-A
pre-B
A
B
post-B
post-A
As we discussed on our call today, I believe that there are two fundamental reasons for consolidating pre/post + collection into a single bundle:
This is a very good critique and suggestion. I agree that the pre script should be expected to return a boolean that will signal whether the measurement should take place. To answer the question of, "How does the developer use the pre function to tell browsertime that this feature is optional and the browsertime user does not want its measurement executed?" does this sound reasonable: The pre script will take a(n) (optional) parameter to the pre script which will be an array of the CLI options from the invocation of browsertime that browsertime did not consume for itself (in other words, the ones that it didn't recognize). The script can iterate through those CLI options and decide whether or not to execute. If it needs to execute, it does the required setup methods and returns true. If those required setup methods cannot be executed, it can return false and the measurement will not run. Alternatively, the script can simply return false based on the values from the CLI, indicating that the browsertime user does not want the measurement executed. What do you think about this?
See above. |
With this, a user will be able to store in a single file a new-style script object that bundles the entirety of the functionality necessary to prepare the browser to run a test, collect the generated data and restore the browser to its previous state.
You can still put the pre-script in the same file, keeping the code close together. You're already
Sure, it'll strain the developer. We're adding a general mechanism for adding features to browsertime; that's not easy. This way you can define a pre-condition (flags, whatever else), take the measurement, and post-process it -- potentially doing things like pulling files off an Android device, etc. That doesn't make sense in a browser context and never will. I trust developers to understand these different contexts (they already have to for pre/post scripts and measurements).
This seems very specific when there's a general mechanism for doing this and more already. |
You are advocating, then, for having the
If we are being expansive, what would you think about having all three take the same parameters and executing in the
|
|
First, sorry for the delayed reply.
Yes.
I'm all for this. In fact, I'm embarrassed not to have counselled this the first time around. When I first started using browsertime I spent some time digging into the mechanics of result collection and was disappointed that I could not get at One big advantage with this would be that it generalizes smoothly to other browsers (e.g., Chrome); and in fact it subsumes existing browsertime features like HAR collection and log/trace collection. Can you work this up, and see if the changes to the |
With this, a user will be able to store in a single file
a new-style script object that bundles the entirety of the
functionality necessary to prepare the browser to run a
test, collect the generated data and restore the browser
to its previous state.