Testing this static site with Playwright!

Why test?

This blog has been a place I want to share what I’ve learned while writing code. It’s not a terribly important part of my life but that does not mean I want it broken. The biggest thing I was worried about was having links to nowhere, especially when referencing other posts. This is a perfect use case to put Playwright to the test!

What is Playwright?

It’s just my favorite from the increasingly packed category of browser automation tools. It’s way more state of the art than selenium and it’s got a great API. I can highly recommend it to anyone who wants to test any scale of web application.

The problem, and the solution

Simply, there’s a number of blog posts (9) and I want to assert that every <a...>... tag has a valid href attribute.

Check out the code below. I promise it’s not much. You just need to scan it.

This all took about an hour of playing around. Just took adding an npm test in the cloudflare pages build and I’m good to go. Now my build fails before it ever gets to the site.

Cloudflare Pages test build

The lesson

I’m a huge fan of testing. This was a little reminder that it can be fun, and the warm fuzzies of knowing that the most updated part of my site doesn’t have a embarassingly obvious mistake to anyone who visits is really nice.

Take some time, node is easy to get a project going with and playwright makes it dead simple to test.