• Home
  • Books
  • Node
  • Testing
  • JavaScript
  • More...
  • Search
  • About
  • Gear & Setup

Node.js

A collection of 58 posts

#javascript #node #testing #jest

Configure Timezone for Jest/Node.js with the `TZ` env var

In order to test code that involves date and time manipulation and parsing. It can be useful to set the timezone under which the Jest tests run. Thankfully Node.js supports the TZ environment variable: “The TZ environment variable is used to specify the timezone configurati ...

  • Hugo Di Francesco
    Author
2 min read
#nock #jest #testing #node

Nock on Node 18/20/22 Fails to Intercept isomorphic-unfetch/fetch Request

On Node versions 18, 20 and 22, users may encounter an issue where Nock fails to intercept requests made via isomorphic-unfetch. What follows is a sample error you may see (timeout is reached because the request is not intercepted). returns a valid response thrown: "Exceeded ...

  • Hugo Di Francesco
    Author
2 min read
#javascript #node

`dotenv` not required: load `.env` and parse env vars natively in modern Node.js

dotenv is a 39 million download a week package allows Node.js apps to load environment variables from .env files and other utilities around environment variables. It’s very useful for building 12-factor apps for which a principle is to read configuration from environment va ...

  • Hugo Di Francesco
    Author
2 min read
#javascript #jest #node #Testing #date

Mocking/stubbing the current Date in Jest tests

There are situations where new Date() or Date.now is used in application code. That code needs to be tested, and it’s always a struggle to remember how to mock/stub or spy on Date.now/new Date with Jest. This post goes through multiple approaches to mocking, stubbing and spying o ...

  • Hugo Di Francesco
    Author
4 min read
#node:test #testing #node #javascript

Mocking/stubbing the Date and timers (setTimeout) in Node.js tests with built-in `node:test` MockTimers

MockTimers is an experimental class in the node:test module which concerns itself with allowing mocking of timers (setTimeout, setInterval, setImmediate) and the Date built-ins. ...

  • Hugo Di Francesco
    Author
4 min read
#cli #node #git #direnv #aws

Direnv setup for multiple git/GitHub, npm and AWS accounts/credentials

In this post, we’ll look at how to configure direnv to manage multiple git, GitHub, npm and AWS accounts and credentials on a single machine. ...

  • Hugo Di Francesco
    Author
2 min read
#node:test #testing #node

Test Native `fetch` in Node.js with Undici interception and mock utils

Node.js 18+ has a built-in fetch available, where prior versions had to use libraries such a node-fetch, axios, got or other to get such functionality. The “native fetch” was implemented in userland first as the undici package. This post goes through how to use undici ...

  • Hugo Di Francesco
    Author
5 min read
#node:test #node #testing #javascript

Node Test Runner: skip a test if an environment variable is missing/empty

The node:test module is a built-in test runner and orchestrator in Node.js. It’s available as experimental since Node 18 but has stabilised in Node 20 and some features are still experimental at the time of writing, in Node 21. node:test supports test skipping throught mult ...

  • Hugo Di Francesco
    Author
5 min read
#lerna #tooling #node #javascript

Lerna publish with no git commit, tag or push

To lerna publish without a git commit or attempting to git push, use --no-push --no-git-tag-version, like so: lerna publish --no-push --no-git-tag-version For official documentation on these options see the lerna version docs. To understand the specifics of --no-push, --no-git-ta ...

  • Hugo Di Francesco
    Author
2 min read
#jest #testing #javascript #node

What is Jest and why should I use it?

Jest is a delightful JavaScript Testing Framework with a focus on simplicity. jestjs.io Jest is a batteries-included framework. Due to its fully-featured nature and large surface area, we can compare it to test runners (Mocha), assertion libraries (Chai, ShouldJS, power-assert, ...

  • Hugo Di Francesco
    Author
7 min read
Page 1 of 6  Previous Posts →

Interested in Alpine.js?

Power up your debugging with the Alpine.js Devtools Extension for Chrome and Firefox. Trusted by over 15,000 developers (rated 4.5 ⭐️).

Install Now close
Code with Hugo
Latest Posts Github