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

Unmute tests for amp-experiment variant replacement. #20233

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/service/url-replacements-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,12 @@ export class GlobalVariableSource extends VariableSource {
this.setAsync('VARIANT', /** @type {AsyncResolverDef} */(experiment => {
return this.getVariantsValue_(variants => {
const variant = variants[/** @type {string} */(experiment)];
userAssert(variant !== undefined,
'The value passed to VARIANT() is not a valid experiment name:' +
experiment);
if (variant === undefined) {
user().error(TAG,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be happening here? Or should we replace rethrowAsync upstream with the user().log()? E.g. the logic that says "ignore errors and return empty string" is already part of this system. This duplicates it slightly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree this is a duplicates. will need a root fix. was plan to have this as a temporary work around to unblock your PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Up to you - you could allow my PR w/o unmuting these tests :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will let your PR go if you can confirm the tests pass locally

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep. Can confirm that it works with patches.

'The value passed to VARIANT() is ' +
'not a valid experiment name:' + experiment);
return '';
}
// When no variant assigned, use reserved keyword 'none'.
return variant === null ? 'none' : /** @type {string} */(variant);
}, 'VARIANT');
Expand Down
12 changes: 6 additions & 6 deletions test/unit/test-url-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,17 +598,17 @@ describes.sandboxed('UrlReplacements', {}, () => {
});
});

// TODO(#16916): Make this test work with synchronous throws.
it.skip('should replace VARIANT', () => {
it('should replace VARIANT', () => {
expectAsyncConsoleError(/not a valid experiment name/);
return expect(expandUrlAsync(
'?x1=VARIANT(x1)&x2=VARIANT(x2)&x3=VARIANT(x3)',
/*opt_bindings*/undefined, {withVariant: true}))
.to.eventually.equal('?x1=v1&x2=none&x3=');
});

// TODO(#16916): Make this test work with synchronous throws.
it.skip('should replace VARIANT with empty string if ' +
it('should replace VARIANT with empty string if ' +
'amp-experiment is not configured ', () => {
expectAsyncConsoleError(/should be configured/);
return expect(expandUrlAsync(
'?x1=VARIANT(x1)&x2=VARIANT(x2)&x3=VARIANT(x3)'))
.to.eventually.equal('?x1=&x2=&x3=');
Expand All @@ -619,9 +619,9 @@ describes.sandboxed('UrlReplacements', {}, () => {
{withVariant: true})).to.eventually.equal('?x1.v1!x2.none');
});

// TODO(#16916): Make this test work with synchronous throws.
it.skip('should replace VARIANTS with empty string if ' +
it('should replace VARIANTS with empty string if ' +
'amp-experiment is not configured ', () => {
expectAsyncConsoleError(/should be configured/);
return expect(expandUrlAsync('?VARIANTS')).to.eventually.equal('?');
});

Expand Down