LandRegistry / govuk-frontend-jinja

GOV.UK Frontend Jinja Macros
https://pypi.org/project/govuk-frontend-jinja/
MIT License
32 stars 13 forks source link

GOV.UK Frontend v5.0 #70

Closed matthew-shaw closed 7 months ago

matthew-shaw commented 10 months ago

Testing currently blocked by https://github.com/surevine/govuk-frontend-diff/pull/97 and ongoing discussions on https://github.com/alphagov/govuk-frontend/discussions/4389

tim-s-ccs commented 7 months ago

Hi @matthew-shaw I work at Crown Commercial Service and look after the Digital Marketplace (which used to be managed by GDS).

We have a frontend repo for Digital Marketplace components (like GOV.UK Frontend) which contains Nunjucks components and the Flask apps would do some magic (as far as I'm concerned) to allow Jinja to parse the Nunjucks templates. Because this is not going to be maintainable long term I've created a project, inspired by this project, Digital Marketplace Jinja Templates which contains Jinja Templates.

Now I originally looked at forking govuk-frontend-diff and doing something similar for Digital Marketplace but I saw in the README that the GOV.UK Frontend package now includes fixtures (i.e. the expected HTML for the component with different params). So for the next release of Digital Marketplace Frontend, because it was not already, I made it generated fixtures with the HTML for all the components.

I've created an app which responds to requests to generate the components. Within the test it gets all of the fixtures from the node module and generates a set of pytest fixtures to test. It then sends the request to the app and then compares the response.

Now, because there can be difference in how things are rendered (i.e. the indent is slightly different or Nunjucks having true where as Jinja will have True) I have added a method html_to_one_line which "normalises" the results so they can be compared.

This not a perfect solution by any means and may not be what you want with this project but I thought it might be useful to share considering you seem to be at a bit of bottleneck with how you're going to test from v5 onward.