Skip to content

✅♻️Refactor and test devdash#20651

Merged
alanorozco merged 50 commits intoampproject:masterfrom
alanorozco:devdash-modules
Feb 5, 2019
Merged

✅♻️Refactor and test devdash#20651
alanorozco merged 50 commits intoampproject:masterfrom
alanorozco:devdash-modules

Conversation

@alanorozco
Copy link
Copy Markdown
Member

@alanorozco alanorozco commented Feb 3, 2019

  • Restructure and extract template.js modules for semantic grouping.
  • Fold html.js and html-helpers.js into one.
  • Test exported HTML renderer outputs by DOM selection.
  • Test several helpers.
  • Test top-level renderer output to ensure all devdash pages are AMPHTML valid!

@alanorozco
Copy link
Copy Markdown
Member Author

@sparhami Addressed, PTAL.

// our only way to test [attr] values is via regex.
const getBoundAttr = (el, attr) => {
const match = el./*OK*/outerHTML.match(boundAttrRe(attr));
if (match) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

would prefer to use a guard clause here and reduce nesting:

if (!match) {
  return;
}


const expectValidAmphtml = (validator, string) => {
const {errors, status} = validator.validateString(string);
expect(errors).to.deep.equal([]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

expect(errors).to.be.empty?

Copy link
Copy Markdown
Member Author

@alanorozco alanorozco Feb 5, 2019

Choose a reason for hiding this comment

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

One difference between using .to.be.empty is that the assertion output is different:

AssertionError: expected [ Array(12) ] to be empty
    at expectValidAmphtml (build-system/app-index/test/helpers.js:51:23)
    ...

Whereas you get the actual comparison values when comparing to an empty array, so validation errors are output for free:

AssertionError: expected [ Array(12) ] to deeply equal []
      + expected - actual

      -[
      -  {
      -    "category": "MANDATORY_AMP_TAG_MISSING_OR_INCORRECT"
      -    "code": "MANDATORY_ATTR_MISSING"
      -    "col": 0
      -    "line": 1
      -    "message": "The mandatory attribute '⚡' is missing in tag 'html'."                                                                                                                       [               -    "params": [
      -      "⚡"                                                                                                                                                                                    [               -      "html"
      -    ]
      -    "severity": "ERROR"
      -    "specUrl": "https://www.ampproject.org/docs/reference/spec#required-markup"
      -  }
      ...

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.

validateString returns the validationresult object, which has errors on it. note that errors will also include warnings. if just checking for validity then status would be better to check because if the given string only has warnings it's still valid and errors is not empty.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Gotcha, thanks for weighing in @honeybadgerdontcare. Filtered out non-ERRORs so this won't fail on warning.

<html>
<head></head>
<body>
<form action=whatever.com></form>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

quotes around attribute value

<head></head>
<body>
<div>
<template type=amp-mustache></template>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

quotes around attribute value

<div>
<amp-bar></amp-bar>
<div>
<amp-foo-bar-baz many=1 attributes=2>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

quotes around attribute value

</amp-foo-bar-baz>
</div>
<input>
<amp-state id=myState></amp-state>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

quotes around attribute value

<div>
<amp-bar></amp-bar>
<div>
<amp-foo-bar-baz many=1 attributes=2>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

quotes around attribute value

selectModePrefix: '/',
}));

const {length} = root.getElementsByTagName('amp-list');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you can use .to.have.length on things that are array-like, so you could do

expect(root.getElementsByTagName('amp-list')).to.have.length(1);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Missed those, thanks!

@alanorozco alanorozco merged commit 0224c59 into ampproject:master Feb 5, 2019
@alanorozco alanorozco deleted the devdash-modules branch February 5, 2019 23:35
@torch2424
Copy link
Copy Markdown
Contributor

@alanorozco Sorry for missing this! Was just about to review this. Thanks for the implementation!

Thank you @sparhami for doing the lengthy review! 😄

"dependencies": {
"@ampproject/animations": "0.1.1",
"@ampproject/worker-dom": "0.2.17",
"amphtml-validator": "^1.0.23",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should be in devDependencies and pinned to a version (no ^).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, #20742.

nbeloglazov pushed a commit to nbeloglazov/amphtml that referenced this pull request Feb 12, 2019
- Restructure and extract `template.js` modules for semantic grouping.
- Fold `html.js` and `html-helpers.js` into one.
- Test exported HTML renderer outputs by DOM selection.
- Test several helpers.
- Test top-level renderer output to ensure all devdash pages are AMPHTML valid!
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
- Restructure and extract `template.js` modules for semantic grouping.
- Fold `html.js` and `html-helpers.js` into one.
- Test exported HTML renderer outputs by DOM selection.
- Test several helpers.
- Test top-level renderer output to ensure all devdash pages are AMPHTML valid!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants