How to Get Code Coverage From Playwright Tests in a Sveltekit App

In this post, I will show you how to get code coverage reports from your Playwright tests in your SvelteKit app. So let’s imagine we are starting with the basic SvelteKit template. First, we need to install: npm i -D vite-plugin-istanbul We need the vite plugin to instrument our code using Istanbul. Istanbul is a tool which allows us to instrument our code such that it can determine which lines were covered by our tests. ...

TIL: How to Get VSCode ESLint to Sort Imports

I use VS Code as my text editor, one of the features I really like about VS Code is that it will format our file on save. Which saves needing to run a CLI tool to do it. For example, running prettier. As part of the formatting on save you can set an option to organise your imports as well. If you open your settings.json, you can add a section like this: ...

TIL: How to Deploy 'Multiple' Sites on One GitLab Page Site

I have a repo which I use to store all of my conference and similar talks. This repo includes any code examples and most importantly the slides. At the moment all the slides are RevealJS “sites”, which means it’s a presentation built in HTML. Now I would like to have all my talks deployed to single GitLab pages site. For example something like: https://hmajid2301.io/talks/an-intro-to-pocketbase/ https://hmajid2301.io/talks/docker-as-a-dev-tool/ So how can we do this ? ...

TIL: How to Mock Classes Using Vitest

TIL: How to Mock Classes Using Vitest Recently I have been creating a SvelteKit app, when creating a new SvelteKit app you get a choice of different things you can add. Such as using vitest for unit testing. I needed to spy on/mock a method in a class, to see if it was called when a button was pressed and, it was called with the correct arguments. Let’s say we have a Button component which looks like this: ...

TIL: How to Use Multiple Auth Files in Playwright

TIL: How to Load Authenticate State in Playwright In this post, I will quickly show you how you can reduce boilerplate code to log in to your app in Playwright tests. Log in to our app is a very common action that will likely be required in most of our tests. You can read this documentation here, which will explain how you can set this up. However, what do you do if you want to say test the login flow or the register flow? ...

How to Create New Posts on Hugo Using Archetypes

In this post, I will go over how you can use Hugo’s archetypes to quickly create new posts. I have previously used NetlifyCMS to help create new posts, but recently I have found that to be a bit overkill for my blog. So I decided to simplify my workflow by using Hugo’s archetypes 1. Archetypes allow us to create templates markdown files, which is then used to create our blog posts. ...

TIL: How to Set a Relationship on Golang Pocketbase

TIL: How to Set a Relationship on Golang Pocketbase Pocketbase is a backend as a service, it is very nice because it is written in Golang it can compile down to a single binary. It also allows us to extend it using Golang and use it as a framework. In my case, I needed some extra logic before adding data to the database so I decided to extend Pocketbase and write some of my business logic. ...

TIL: How to Run Parallel Jobs on Gitlab CI (Different Stages)

TIL: How to Run Parallel Jobs on Gitlab CI (Different Stages) If you are familiar with Gitlab CI you probably know that jobs in the same stages will run in parallel. However you can also run jobs in different stages at the same time. Let’s see our .gitlab-ci.yml looks like this: stages: - test - deploy format: stage: test script: - task format lint: stage: test script: - task lint deploy:preview: stage: deploy only: - merge_request image: docker script: - task deploy So for my use case when a user creates a merge request, I want to run some tests against the code, such as linting and formatting. ...

How to Setup Netlify Deployment Notifications on Discord with Pipedream

Hi everyone, I recently went about setting up notifications about my Netlify deploys in Discord. Netlify does have an official way to do however, you cannot use it on the free tier. So I looked at other solutions, and I eventually discovered a SaaS product called PipeDream. It is a website which allows us to connect different components without needing to write any code. Such as what to do when we receive a webhook. ...

TIL: How to fix `structuredClone` to work on Netlify SvelteKit Site

TIL: How to fix structuredClone to work on Netlify SvelteKit Site Recently I was working on my SvelteKit site and added some code like so to my hook.server.ts: try { if (event.locals.pb.authStore.isValid) { await event.locals.pb.collection("users").authRefresh(); event.locals.user = structuredClone(event.locals.pb?.authStore.model); } } catch (err) { console.log("failed to refresh auth", err); event.locals.user = undefined; event.locals.pb.authStore.clear(); } I needed to add the structuredClone function so that only POJO (plain old javascript objects) would get stored in the event. ...

TIL: How to Autofocus on Inputs in Svelte

TIL: How to Autofocus on Inputs in Svelte In this post, I will show you how you can autofocus on input that is in a child component. So in my use case, I want the user to click a button to add a “collection” and then it will show the input and immediately focus on it. Which looks something like this: So how can we do this? Let’s say we have a child component called Input. ...

How Can We Update GitLab CI on the Status of the Netlify Deploy Part I

In this post, I will show you how you can update your GitLab CI pipeline with the status of your Netlify deploys. As it is quite nice to have everything in one place if our CI pipeline passed or failed. I have spoken about this in a previous article, how you might go about setting up merge request preview environments with Netlify. This can be set up to also leave comments as shown above, and notify us if our website deployed successfully. ...

TIL: How Includes, Extends work with TS Config (with SvelteKit)

TIL: How Includes, Extends work with TS Config (with SvelteKit) I have recently been creating an app with SvelteKit and Typescript. I noticed all of a sudden Typescript and VS Code not playing nice with each other. It wouldn’t show me the types of variables that I knew it was showing me before. So I started to investigate and work out what was wrong. I was getting locals with a type any: ...

How to Autosort our SvelteKit Imports

In this post, we will go over how we can auto-sort our imports in our svelte files. To do this we will be using eslint and the eslint-import-plugin plugin. If you’re anything like me you like have ordered imports, rather than random imports that can be hard to make sense of. In Python we have isort in golang we have goimports. In JavaScript we can use eslint with the above plugin. ...

How to add Have I Been Pwned to Your Registration Flow in SvelteKit

In this post, I will go over how you can use the have I been pwned (hibp) API to improve UX 1 in our registration flow in our SvelteKit app. When the user signs up we can check if that password has been compromised in a previous data breach (on another site). Then we can prompt the user to enter another password. This will help avoid users using simple & common passwords like password11. ...

How to Remote Debug your SvelteKit on an Android Device in Firefox

In this post, we will go over how you can test your SvelteKit app on your Android device in Firefox. If you’re like me you are building an app that you want users to use on both normal PCs (laptops, Desktop) and their smartphones. But the question arises how can we debug our app on a smartphone? One way to achieve this is to use Firefox and remote debugging, you will need to connect your smartphone via USB to your device running the SvelteKit app i. ...

TIL: How to Setup Netlify, Gitlab And Sentry

TIL: How to Setup Netlify, Gitlab And Sentry I will show you in this post how you can integrate Gitlab, Netlify and Sentry. I may do a more detailed post in the future. GitLab -> Sentry To connect Gitlab and Sentry follow this guide. Then add the repos you want to monitor in Sentry. In my case, it is the Bookmarkey GUI. Netlify -> GitLab This integration is pretty simple just go through the normal Netlify setup process to add a new site. ...

TIL: How To Add Custom Syntax Highlighting Rules in VS Code

TIL: How To Add Custom Syntax Highlighting Rules in VS Code The other day (a few months ago) I was comparing Goland and VS Code for Golang development. I noticed Goland by default seemed to have nicer syntax highlighting, so I started looking at what I could do in VS Code to do this. Before After It turns out we can do this with our own custom rules using editor.tokenColorCustomizations. To do this go to our settings (settings. ...

TIL: How to Connect PocketBase and BackBlaze S3

TIL: How to Connect PocketBase and BackBlaze S3 By default PocketBase uses the local file system to store uploaded files. If you have limited disk space, you could optionally connect to a S3 compatible storage. - PocketBase Why BackBlaze ? Simple the prices are generally cheaper as compared with other S3 compatible storage platforms. How can we set up BackBlaze as our S3 bucket to store uploaded files such as user avatars? ...

TIL: How to Use DinD, localhost & Gitlab CI

TIL: How to Use DinD, localhost & Gitlab CI In this post, I will go over how you can use docker-compose and Gitlab CI. In this example, we will be running playwright tests directly on the Gitlab runner. The tests will start a SvelteKit server also running on the Gitlab runner. The SvelteKit server will connect to PocketBase (backend) running in docker-compose. So essentially we need a way for something running locally to connect to something running in docker in Gitlab CI (on a runner). ...

How to Setup OAuth2 with SvelteKit and Pocketbase

Out of date This article maybe a bit out of date as PocketBase is adding new features and deprecating old functions. If you encounter an issue with the setup see this issue by Dominick Hi everyone, I’ve been building a new bookmarking app, using SvelteKit and PocketBase. PocketBase, is an open-source backend, that we need to self-host 1. It is written in Golang, think of it similar to Firebase or Supabase. ...

How to use DotBot to personalise your VSCode Devcontainers

Devcontainers This article assumes you are already familiar with dev containers. You can read more about devcontainers here. In this article, we will go over how you can personalise your dev containers. Devcontainers allow us to create consistent development environments. One of the main advantages of dev containers is we can provide a “one button” setup for new developers. We do this by using a container (Docker), and we end up developing inside a container. ...

TIL: How to Use Prettier with Hugo/Golang Templates

TIL: How to Use Prettier with Hugo/Golang Templates If you try to use prettier on a (Hugo) Golang HTML template you may get something that looks like this: {{- if or .Params.author site.Params.author }} {{- $author := (.Params.author | default site.Params.author) }} {{- $author_type := (printf "%T" $author) }} {{- if (or (eq $author_type "[]string") (eq $author_type "[]interface {}")) }} {{- (delimit $author ", " ) }} {{- else }} {{- $author }} {{- end }} {{- end -}} into this ...

TIL: How to Deploy a SvelteKit site on Netlify

TIL: How to Deploy a SvelteKit site on Netlify So you have a SvelteKit site you want to deploy to Netlify how can we do that? First, go about setting up a site like normal! In my case, I am going to import an existing site from Gitlab. Netlify In the build settings we want the following settings: Branch Adjust the branch to whatever your main branch is i.e. the branch you want to deploy from. ...

How to Update a Project using a Copier Template

In this article, I will show you how you can update a project, that was created from a copier template. In my previous article, we learnt how we can create a project template. I listed the only reason I choose to use copier over say cookiecutter was that it provided an “easy” way to update downstream projects. Existing Repository From here on out we will assume you have a template repository that uses copier. ...