torchbox / tbxforms

A Torchbox-flavoured template pack for django-crispy-forms, adapted from crispy-forms-gds.
https://pypi.org/project/tbxforms/
BSD 2-Clause "Simplified" License
6 stars 5 forks source link

Use snapshot tests instead of HTML fixtures #42

Closed jams2 closed 1 year ago

jams2 commented 1 year ago

Closes #41

This PR adds syrupy, a pytest plugin for snapshot tests, to the project. The aim of this is to remove the need for manual maintenance of HTML fixtures.

In addition to adding syrupy, this PR:

The snapshots shouldn't need individual comparison with the old fixtures - they were generated from main branch, where all tests were passing.

jams2 commented 1 year ago

I changed the poetry CI cache key to include the full Python version (as per this) and it fixed the Python test job. It seems that there has been a Python bugfix release that was not playing nicely with the poetry environment built on an older version.

jams2 commented 1 year ago

I've added djlint as a dev dependency. I went with djlint over djhtml as the former does autoformatting. My thinking is that we should autoformat the snapshots, so they are easy to read in code review if they are changed. Reading diffs of single-line HTML is a nightmare.

If we format the snapshots, we also need to format the rendered markup they are compared with. So, I've added a call to djlint's auto-formatter to the render_form and render_template utils.

I've also added linting of templates with djlint. Personally I don't feel that we need to enforce formatting for templates, but happy to change that. (also, I don't love how djlint formats hanging attributes, and it's not configurable)

Linting and format checks have been added to pre-commit and CI.