Hey guys, this post is about writing tests for projects that access the file system by reading and writing files to disk.
A lot of my past projects in some way had to do with file access. I started to test with mocking libraries like mock-fs, but soon recognized that they do not work for all cases, and sometimes you are using third party libraries internally that you cannot mock easily. So I thought of a different solution and the one I’m using right now for most projects actually uses real files.
I recently tried out @nuxt/content, a Git-based CMS for Nuxt projects. And I really like it! It allows me to write markdown files and host them right in my existing project.
One thing I noticed when deploying the project to my server was that the
updatedAt fields were always reset and didn't reflect the actual dates. The reason for this is that Git does not keep file metadata. This means that the timestamps that
@nuxt/content relies on are of no use.
Modernizr uses a plugin-based architecture, and you have to build the package yourself, depending on the features you need to detect — at least if you are not using Nuxt.js! I have created the nuxt-modernizr module that makes it easy to add Modernizr to your Nuxt.js app. You pass the features as module options…
Snapshot testing is a testing mechanism that for long has seemed to be exclusive to Jest. The main idea is to generate expected values into a separate file and to compare the actual tested values with these saved values. It is also possible to update snapshots by passing an environment variable. This testing approach is great for complex data like large strings, DOM content, or images.
Snapshot testing itself is a built-in feature of Jest, and when searching specifically for image snapshots, you’ll quickly find jest-image-snapshot, which does great work comparing and updating image snapshots. …
When I started to work with Nuxt.js, I frequently had the problem that I wanted so send emails via a contact form. While there are third party services to do that, I thought: Why not use the existing server infrastructure that comes with Nuxt.js?
That is why I wrote nuxt-mail, a Nuxt.js module that adds a
/mail/send route to the server and injects a
You start by installing the module and @nuxtjs/axios via
npm install nuxt-mail @nuxtjs/axios or
yarn add nuxt-mail @nuxtjs/axios.
@nuxtjs/axios is important here because it allows the module to do…