-
Notifications
You must be signed in to change notification settings - Fork 205
fix(tests): Update filter expression script to use ExperimentAPI module. #12855
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
Conversation
const TargetingContext = ChromeUtils.importESModule("resource://messaging-system/targeting/Targeting.sys.mjs"); | ||
|
||
const _experiment = JSON.parse(arguments[1]); | ||
ExperimentAPI.ready(); |
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 returns a promise
ExperimentAPI.ready(); | |
await ExperimentAPI.ready(); |
There is a typo in the PR title: |
|
||
return results; | ||
remoteSettings(targetingString, recipe, callback); |
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.
Instead of taking the callback as an arg, lets do remoteSettings(targetingString, recipe).then(callback, () => null)
It makes the control flow of remoteSettings
cleaner and it doesnt need a bunch of try/catch.
const targetingContext = new TargetingContext.TargetingContext(context); | ||
let result = false; | ||
try { | ||
result = await targetingContext.evalWithDefault(targetingString) !== undefined; |
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 we dont take callback as an arg, we can just return immediately here. We dont even need to try/catch
} catch (err) { | ||
result = null; | ||
callback(null); |
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.
and here.
experimenter/tests/integration/nimbus/utils/filter_expression.js
Outdated
Show resolved
Hide resolved
experimenter/tests/integration/nimbus/utils/filter_expression.js
Outdated
Show resolved
Hide resolved
4241515
to
b9858e6
Compare
else: | ||
return self.execute_script | ||
return self.execute_async_script |
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 do not understand how this is supposed to 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.
We use it in the test
with filter_expression_path.open() as js:
result = Browser.execute_async_script(
selenium,
targeting,
json.dumps({"experiment": recipe}),
script=js.read(),
context="chrome",
)
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 the example you gave, context="chrome" so we're in the other branch. From inspection, you would have to use this like:
result = Browser.execute_async_script()(script)
experimenter/tests/integration/nimbus/utils/filter_expression.js
Outdated
Show resolved
Hide resolved
experimenter/tests/integration/nimbus/utils/filter_expression.js
Outdated
Show resolved
Hide resolved
else: | ||
return self.execute_script | ||
return self.execute_async_script |
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 the example you gave, context="chrome" so we're in the other branch. From inspection, you would have to use this like:
result = Browser.execute_async_script()(script)
if "chrome" in context: | ||
with self.context(self.CONTEXT_CHROME): | ||
return self.execute_script(script, *args) | ||
return self.execute_async_script(script, *args) | ||
else: | ||
return self.execute_script | ||
return self.execute_async_script |
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 should be
return self.execute_async_script(script, *args)
see my other comment.
Because
This commit
ExperimenterAPI
module.Fixes #12851