I would like to run my unit tests before the app builds. I’ve read a few articles but couldn’t work out the proper way to do it. Currently I’ve amended my build process from yarn build to yarn test && yarn build. If the test suite fails then the build will fail and if the test suite passes then the build will run.
This is the desired outcome, I was just wondering if there is a better way to do this?
You can have a more fine grained control over you build process steps with the new Netlify Build Plugin this is in beta, but i would highly recommend using it if you have scenarios when you need to test something in the site after the site was built but not deployed (preDeploy step).
There are other steps which can be used pending on your use cases. check the link above
If your tests are not dependent on the generated output from the SSG you could use github actions an stop the flow before it hits Netlify.
This is useful to check spelling errors or linting for instance, so stuff which are more bound to code (code quality, security issues, formatting, etc)