Unit tests is a great idea.
At the simplest, use a framework like jest and test your JS files manually with a test command and push if it passes.
You can setup GH Actions to run custom steps. Here I have one which runs an action to deploy to GH pages.
If you find add some steps before around npm install and npm run test then you can make sure the deploy to GH pages only happens if tests pass. Check the sample NPM workflow on the page where you add a new action.
You can also have multiple “jobs” items in the workflow file. You could look at tests and deploy as jobs and make deploy dependent on tests.
I find the syntax heavy to get all that stuff setup.
In Netlify its really simple. One line.
build: npm run test && jekyll build
You don’t even have to install. It figures that out for npm and jekyll based on package files.
Some JS test bootstraps https://github.com/swkBerlin/kata-bootstraps/tree/master/js
That’s great advice thanks. I’m not using GH Pages, but I can obvs include the testing in my deployment script. Probably a lot faster than doing that as a build step too.