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

app-tests: validates HTML source saved from page-layout tests #6072

Merged
merged 5 commits into from
Aug 19, 2021

Conversation

cfm
Copy link
Member

@cfm cfm commented Aug 18, 2021

Status

Ready for review

Description of Changes

Closes #1897 by:

  1. installing html5validator in the test-requirements used in CI pipelines;
  2. providing and using in all page-layout tests a convenience function FunctionalTest._save_html() in the spirit of FunctionalTest._screenshot();
  3. adding a Make target validate-test-html to validate the HTML source saved from such tests; and
  4. executing this target (as informational-only for now) after tests have run in app-tests.

Discussion points

  1. This is arguably a strict form of linting, but (per discussion in Lint HTML #1897) requires the outputs of higher-level tests, in this case page-layout tests. Given this infelicity, is there some other way we want to integrate this check into CI? For example, we could run it only as part of the nightly workflow.
  2. If we do want this to be part of routine CI: Do we want to include this step in app-tests, further prolonging its runtime? One alternative would be to factor out page-layout tests to a separate job altogether, in parallel to app-tests, and include this validation step there.
  3. html5validator requires a JDK, installed here as default-jdk. Is this an acceptable addition to the development/test container?

Testing

  • After running page-layout tests locally, make validate-test-html reports meaningful results (i.e., lots of errors :-).
  • app-tests passes (e.g.) despite lots of "informational" errors reported in the "Validate HTML" step.

Deployment

Development-only; no deployment considerations.

Checklist

If you added or updated a code dependency:

  • I have performed a diff review and pasted the contents to the packaging wiki
  • I would like someone else to do the diff review

test-requirements only.

@cfm cfm requested a review from a team as a code owner August 18, 2021 01:35
@kushaldas kushaldas self-assigned this Aug 18, 2021
Copy link
Contributor

@kushaldas kushaldas left a comment

Choose a reason for hiding this comment

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

The code and rest of the change looks good to me. Tested locally, can get many errors like below:

"file:/root/code/securedrop/securedrop/tests/pageslayout/html/ar/journalist-admin_ossec_alert_button.html":1.1-1.26: error: Start tag seen without seeing a doctype first. Expected "<!DOCTYPE html>".
"file:/root/code/securedrop/securedrop/tests/pageslayout/html/ar/journalist-admin_ossec_alert_button.html":36.5-36.37: error: Element "div" not allowed as child of element "label" in this context. (Suppressing further errors from this subtree.)
"file:/root/code/securedrop/securedrop/tests/pageslayout/html/ar/journalist-admin_ossec_alert_button.html":39.5-39.37: error: Element "div" not allowed as child of element "label" in this context. (Suppressing further errors from this subtree.)
"file:/root/code/securedrop/securedrop/tests/pageslayout/html/ar/journalist-admin_ossec_alert_button.html":42.5-42.40: error: Element "div" not allowed as child of element "label" in this context. (Suppressing further errors from this subtree.)
"file:/root/code/securedrop/securedrop/tests/pageslayout/html/ar/journalist-login.html":1.1-1.26: error: Start tag seen without seeing a doctype first. Expected "<!DOCTYPE html>".
"file:/root/code/securedrop/securedrop/tests/pageslayout/html/ar/journalist-login.html":30.5-30.37: error: Element "div" not allowed as child of element "label" in this context. (Suppressing further errors from this subtree.)
"file:/root/code/securedrop/securedrop/tests/pageslayout/html/ar/journalist-login.html":33.5-33.37: error: Element "div" not allowed as child of element "label" in this context. (Suppressing further errors from this subtree.)
"file:/root/code/securedrop/securedrop/tests/pageslayout/html/ar/journalist-login.html":36.5-36.40: error: Element "div" not allowed as child of element "label" in this context. (Suppressing further errors from this subtree.)
make: *** [Makefile:231: validate-test-html] Error 255

But, in CI I can not see the actual errors. I guess we want that too (as mentioned in the test plan).

image

@SaptakS please let me know what do you think.

@@ -13,6 +13,8 @@ RUN apt-get update && apt-get install -y paxctl && \
python3-pip python3-all python3-venv virtualenv libpython3.8-dev libssl-dev \
gnupg2 ruby redis-server git xvfb curl wget \
gettext paxctl x11vnc enchant libffi-dev sqlite3 gettext sudo \
# for html5validator
default-jdk \
Copy link
Contributor

Choose a reason for hiding this comment

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

Finally we are an enterprise application :)

@cfm
Copy link
Member Author

cfm commented Aug 18, 2021

@kushaldas in #6072 (review):

But, in CI I can not see the actual errors. I guess we want that too (as mentioned in the test plan).

This threw me too! As CircleCI is currently splitting the tests across the three parallel runs, run 0 (at least on this execution) doesn't include any page-layout tests, so it doesn't save any HTML to validate. But runs 1 and 2 do.

I tried to anticipate this by having the validate-test-html target start by echoing "Validating HTML source saved from any page-layout tests run" (emphasis added). But I will think about whether there's a better way to document this behavior and/or highlight it in the CircleCI view.

cfm added a commit that referenced this pull request Aug 18, 2021
…ted (per review feedback)

Otherwise, "app-tests" runs to which CircleCI has not assigned any
page-layout tests will appear to include a validation step that returns
no results.

thread: #6072 (review)
@cfm
Copy link
Member Author

cfm commented Aug 18, 2021

#6072 (comment):

I tried to anticipate this by having the validate-test-html target start by echoing "Validating HTML source saved from any page-layout tests run" (emphasis added). But I will think about whether there's a better way to document this behavior and/or highlight it in the CircleCI view.

In 2ed9fce I've added an explicit count of how many *.html files have been saved from page-layout tests and will be validated.

Copy link
Contributor

@kushaldas kushaldas left a comment

Choose a reason for hiding this comment

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

Testing steps

  • After running page-layout tests locally, make validate-test-html reports meaningful results (i.e., lots of errors :-).
  • app-tests passes (e.g.) despite lots of "informational" errors reported in the "Validate HTML" step.

Tested locally, works as expected. html directory is also marked in .gitignore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint HTML
2 participants