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

JavaScript

A collection of 102 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
#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
#javascript #mermaid

Docsify Mermaid 10

Using Docsify and Mermaid 10 can be tricky since Mermaid 10 renders asynchronously (mermaid.render returns a Promise). This post shows how to work around the mismatch between Docsify’s markdown.renderer.code and Mermaid’s render function on Mermaid v9 and v10. ...

  • Hugo Di Francesco
    Author
3 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
#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
#node:test #node #testing #javascript

Node.js Native Test Runner

If anyone missed it, Node.js 18 includes a test runner/test definition module (node --test and node:test respectively). node:test exports a test function and you can run the Node CLI with a --test flag which does some basic search/matching for test files. Full Documentation: node ...

  • Hugo Di Francesco
    Author
4 min read
#alpinejs #javascript

Tips for real-world Alpine.js

Alpine Day 2021 Talk: tackling Alpine FAQs, common issues & web patterns with Alpine.js ...

  • Hugo Di Francesco
    Author
6 min read
Page 1 of 11  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