Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Testing and validating code

Kevan Hannah edited this page Apr 27, 2023 · 3 revisions

Automated tests

  • test/test.js has some simple tests using Mocha to check the app is being built as expected
  • The tests can be run at any time with npm run test

HTML validation

  • You can validate the source .njk files using npm run htmlValidateSrc
  • You can validate the built .html files using npm run htmlValidateDist
  • Any files in the vendor directory are ignored when validating
  • The validator configuration is in .htmlvalidate.json

Git Hooks

This project uses pre-commit to manage its Git Hooks. After installing pre-commit on your system, use the following to install the project's hooks.

  • pre-commit autoupdate
  • pre-commit install
  • pre-commit install --hook-type prepare-commit-msg

Prettier

Prettier is an opinionated code formatter that ensures all outputted code confrms to our consistent style. We have an accepted common style guide and this tool allows us to automate it. This allows us to avoid style discussions, unneccessary code review discussions on style, and separate the responsible of formatting from the linter. It is also very useful for new team members who may be used to other styles.

  • Format all files: npx prettier --write .
  • Format files in a directory: npx prettier --write src/_data/
  • Format a specific file: npx prettier --write src/_data/app/eleventyComputed.js
  • Check that things are formatted without overwriting: npx pretter --check .
  • Integrate with Visual Studio Code by installing Prettier Formatter for Visual Studio Code
  • Ignore the next node in the abstract syntax tree from formatting
    • JS - // prettier-ignore comment on the preceding line
    • NJK - <!-- prettier ignore --> or <!-- prettier-ignore-attribute -->
    • NJK - {​​​​{​​​​! prettier-ignore }​​​​}​​​​
    • CSS - /* prettier-ignore */
Clone this wiki locally