#JavaScript #Sequelize #testing #Node

Unit Testing Sequelize 4 ES6 class models

In “Using ES6 classes for Sequelize 4 models” we explored how to define Sequelize models using ES6 classes. One of the benefits of such an approach is that it allows easy unit testing, it allows you to instantiate the model without the baggage of all of Sequelize (and/or a database). The examples will use Jest module auto-mocking but should be portable to other module mocking libraries (eg. Proxyquire) with some modifications. ...

  • Hugo Di Francesco
    Author
2 min read
#graphql #tooling #web development

A gentle introduction to GraphQL API integrations

GraphQL is a great alternative to REST (or other HTTP API designs). This is an quick introduction to the core concepts around consuming a GraphQL API. To see some examples consuming a GraphQL API: In Python, see Python GraphQL client requests example using gql In JavaScript (browser and Node), see last week’s Code with Hugo newsletter What is GraphQL and what problems does it solve? GraphQL is “a query language for your API”. ...

  • Hugo Di Francesco
    Author
5 min read
#JavaScript #Node #tooling #deployment

Build and deploy a Vue/React/Vanilla JS app with Parcel and GitHub pages

Parcel allows us to bundle frontend applications with no configuration and GitHub pages affords us a way to deploy them for free. Here’s how to use these two tools together to deploy a JavaScript application. Full example of a repo deployed like this: https://github.com/HugoDF/js-graphql-client-example, and see https://codewithhugo.com/js-graphql-client-example/. Or the repo with the demos: https://github.com/HugoDF/parcel-gh-pages-deploy and see https://codewithhugo.com/parcel-gh-pages-deploy/. ...

  • Hugo Di Francesco
    Author
2 min read
#git #bash #productivity

Change the date of a git commit

One of the greatest and worst things with git is that you can rewrite the history. Here’s a sneaky way of abusing that, I can’t think of a legitimate reason to do this. As with anything, thanks StackOverflow for all the options I can pick from 👍. Set the date of the last commit to the current date GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)" Set the date of the last commit to an arbitrary date GIT_COMMITTER_DATE="Mon 20 Aug 2018 20:19:19 BST" git commit --amend --no-edit --date "Mon 20 Aug 2018 20:19:19 BST" ...

  • Hugo Di Francesco
    Author
1 min read
#cdn #dev-decoded #productivity

The step-by-step guide to create a domain redirect with Cloudflare

Be logged into your dashboard. Select the domain you want to redirect from Go to page rules Click “Create page rule” Enter your.domain/* (matches all traffic) for which URLs will have their traffic redirected Click “Add a Setting” Select “Forwarding URL” Select the type of redirect, I recommend 302s since they’re less aggressively cached (so if you ever want to use that domain to do something else other than redirect, you can) Enter your forwarding URL Click “Save and Deploy” You’re done, you’ve just created a redirect from your domain to another one 🙂 ...

  • Hugo Di Francesco
    Author
1 min read
#python #graphql #web development

Python GraphQL client requests example using gql

An example consuming a GraphQL API from Python using gql. Full code example at HugoDF/python-graphql-client-example. This was sent out on the Code with Hugo newsletter last Monday. Subscribe to get the latest posts right in your inbox (before anyone else). $ pip install gql # You should use a virtualenvfrom gql import gql, Client from gql.transport.requests import RequestsHTTPTransport _transport = RequestsHTTPTransport( url='https://graphql-pokemon.now.sh/', use_json=True, ) client = Client( transport=_transport, fetch_schema_from_transport=True, ) query = gql(""" { pokemon(name: "Pikachu") { attacks { special { name } } } } """) print(client. ...

  • Hugo Di Francesco
    Author
1 min read
#hugo #meta #css #deployment

Switching the lights on: Hugo vs Hugo config files

A simple Hugo blog setup The story of getting codewithhugo.com up and running. The tl;dr is the following: I always rave about my blog setup, it’s simple, fast and just works I used Hugo, “The world’s fastest framework for building websites”, a static site generator I used a theme, casper-two, which is a Hugo port of the https://ghost.org/ default theme I deployed to GitHub pages behind Cloudflare. ...

  • Hugo Di Francesco
    Author
8 min read
#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. ...

  • Hugo Di Francesco
    Author
6 min read