Skip to content

amp-apester: Support keyword lookup in AmpDocShadow#27345

Merged
mdmower merged 5 commits intoampproject:masterfrom
mdmower:pr-apester
Apr 3, 2020
Merged

amp-apester: Support keyword lookup in AmpDocShadow#27345
mdmower merged 5 commits intoampproject:masterfrom
mdmower:pr-apester

Conversation

@mdmower
Copy link
Copy Markdown
Contributor

@mdmower mdmower commented Mar 22, 2020

Query meta[name="keywords"] using method supported by
AmpDocShadow as well as other AmpDoc subtypes.

Query meta[name="keywords"] using method supported by
AmpDocShadow as well as other AmpDoc subtypes.
@mdmower mdmower requested a review from cathyxz March 26, 2020 04:07
@rsimha rsimha requested review from alanorozco and caroqliu and removed request for cathyxz April 2, 2020 18:14
Copy link
Copy Markdown
Contributor

@caroqliu caroqliu left a comment

Choose a reason for hiding this comment

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

A few comments, thanks for making this change. Is there an issue to attach to this PR, or was the change motivated by general code health?

.split(',')
.filter((e) => e)
.map((e) => e.trim());
.map((e) => e.trim())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are the filter and map swapped here to catch whitespace-only entries?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing this far after the fact, but something I've seen Justin do that is really nice-looking is .filter(Boolean) :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, slick, I'll totally adopt that in the future. Thanks!

articleMetaTags.length ? articleMetaTags : extratctTitle(root) || []
articleMetaTags.length
? articleMetaTags
: extratctTitle(ampdoc.getRootNode()) || []
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: This method name appears to be a typo, mind fixing it here and elsewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will fix.

document.head.textContent = '';
});
afterEach(() => {
Services.ampdoc(document).meta_ = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of accessing the private property, let's reset using setMetaByName -- keywords is the only one that needs to be reset for the purposes of tests, right?

Copy link
Copy Markdown
Contributor Author

@mdmower mdmower Apr 2, 2020

Choose a reason for hiding this comment

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

I suppose we could do that, but this is the most direct means of resetting the cached meta tags in an AmpDoc, see:

// Ensure cached meta name/content pairs are cleared before each test
ampdoc.meta_ = null;
. My preference would be to leave this as-is, but let me know if it needs to change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK, feel free to leave as is. If you could include the same comment that would be helpful too.

Copy link
Copy Markdown
Contributor Author

@mdmower mdmower left a comment

Choose a reason for hiding this comment

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

Is there an issue to attach to this PR, or was the change motivated by general code health?

This is the last issue to be fixed in #26652 .

Copy link
Copy Markdown
Contributor

@caroqliu caroqliu left a comment

Choose a reason for hiding this comment

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

Thanks!

@mdmower mdmower merged commit 22b70b0 into ampproject:master Apr 3, 2020
@mdmower mdmower deleted the pr-apester branch April 3, 2020 17:42
ChrisAntaki pushed a commit to ChrisAntaki/amphtml that referenced this pull request Apr 3, 2020
* amp-apester: Support keyword lookup in AmpDocShadow

Query meta[name="keywords"] using method supported by
AmpDocShadow as well as other AmpDoc subtypes.

* extratctTitle --> extractTitle

* Add test note about clearing meta_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants