#Testing #JavaScript #ES6

Abusing Jest snapshot tests: some nice use-cases 📸

There’s some nice use-cases for snapshot tests outside of the well-travelled React/Vue UI component ones. In other words, although React and Vue testing with snapshots is pretty well documented, that’s not the only place they’re useful. As a rule of thumb, you could replace a lot of unit tests that assert on with specific data with snapshot tests. We have the following pros for snapshot tests: - the match data is stored in a separate file so it’s harder to lose track of things, eg. ...

#tooling #git #ci #bash

Deploy to multiple environments with git and CircleCI

Easily deploying to multiple environments in a simple manner using GitHub, CircleCI and Heroku. Continuous Integration is awesome, but sometimes you need a buffer between auto-deploying things on merge and the production release. To do that with CircleCI requires some git branch-wrangling and a few lines of bash scripting. We’ll imagine a scenario where a deploy is trivial (ie. we’ll pretend we’re using Heroku). For more complicated build steps we should still be able to follow similar principles. ...

#Redis #tooling

Install just redis-cli on Ubuntu, Debian, Jessie

As part of adding integration tests to an app on CircleCI I ran into the following issues: redis-cli’s API has changed from version 2 to 3 to 4 ie. this works in v4 redis-cli -u ${REDIS_URL} but doesn’t in v2 the “only way” to install redis-cli is through a redis-tools or redis-server install and I only need redis-cli not the server or any other tools What follows is how not to install redis-cli and then how to install redis-cli latest, properly. ...

#JavaScript #Node #Docker #redis

Bring Redux to your queue logic: an Express setup with ES6 and bull queue

There always comes a point in a web application’s life where an operation is best served in the background, this is where queues come in. There are a few queuing solutions in Node. None of them are ridiculously dominant, eg. Kue, RSMQ, Bee Queue, bull. The issue with Kue, RSMQ and Bee Queue was its use of a done callback as the recommended API. Bull https://github.com/OptimalBits/bull is a premium Queue package for handling jobs and messages in NodeJS. It’s backed by Redis and is pretty feature-rich. Most of all, it leverages a Promise-based processing API which means async/await. We’ll walk through an application that sends webhooks with a given payload to a set of URLs. ...

#JavaScript #Node

ES6 by example: a module/CLI to wait for Postgres in docker-compose

When using docker-compose, it’s good practice to make anything that relies on Postgres wait for it to be up before launching. This avoids connection issues inside the app. This post walks through how to deliver this functionality both as a CLI and a module that works both as a CommonJS module (require) and ES modules, without transpilation. “A fast, production ready, zero-dependency ES module loader for Node 6+!” is esm’s promise. From this sample project, it’s worked. ...