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

Node.js

A collection of 58 posts

#jest #node #javascript #testing

Jest Array/Object partial match with objectContaining and arrayContaining

It’s possible to do partial matches on Arrays and Objects in Jest using expect.objectContaining and expect.arrayContaining. expect has some powerful matcher methods to do things like the above partial matches. Using Jest at an advanced level means using tools like these to ...

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

Jest explicitly or arbitrarily force fail() a test

When testing code with Jest, it can sometimes be useful to fail a test arbitrarily. This post goes through a few scenarios where that might be useful and how to fail a Jest test explicitly/in a forced manner. It also presents more idiomatic Jest patterns that could be used interc ...

  • Hugo Di Francesco
    Author
10 min read
#node #javascript #python

How to integrate Python/Ruby/PHP/shell script with Node.js using child_process.spawn or child_process.exec

There are occasions when running a Python/Ruby/PHP shell script from Node.js is necessary. This post looks at best practices around leveraging child_process.spawn and child_process.exec to encapsulate this call in Node.js/JavaScript. The goal here is to have an interoperability l ...

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

Jest Full and Partial Mock/Spy of CommonJS and ES6 Module Imports

JavaScript import/require module testing do’s and don’ts with Jest The example repository is available at github.com/HugoDF/mock-spy-module-import. This post goes through how to achieve different types of module mocking scenarios with Jest. From simple Import interce ...

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

How to run, ignore or skip Jest tests, suites and files

When debugging or writing units tests with Jest it can be useful to specify a single file or test to run or to exclude a specific failing test for the Jest run. This post goes how to skip and exclude a single test, a whole Jest test suite and a whole Jest test file using the CLI ...

  • Hugo Di Francesco
    Author
9 min read
#micro #node #javascript #SQLite

Record analytics events with a Zeit "micro" + SQLite3 Node.js application

micro-analytics-events - A Node.js microservice to record analytics events to SQLite3 with Zeit’s “micro” In order to finally switch off Google Analytics, I need to replace my goal conversion tracking somehow. I’ve got pageview data using Simple Analytics ...

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

How to run Jest tests sequentially

By default Jest runs tests in parallel with a “a worker pool of child processes that run tests” (Jest CLI docs). As per the Jest documentation, running tests in sequence (serially), can be helpful for debugging purposes and for test run performance reasons. ...

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

Detect if the current file/module is the entrypoint or import/require-d in Node.js

How does one identify whether a JavaScript file is being run directly (node file.js) or it’s being import/require-d (require('./file') in another JS file). In Python the pattern leverages the __main__ property in modules like so: if __name__ == '__main__': # do some ...

  • Hugo Di Francesco
    Author
1 min read
#javascript #node #meta

Yarn Workspaces: monorepo management without Lerna for applications and coding examples

How to use Yarn Workspaces to manage applications/coding examples. Lerna isn’t required when you don’t need the git diffing and versioning facilites. What’s more Yarn Workspaces are a great lightweight tool to get up and running faster for simple Node.js monore ...

  • Hugo Di Francesco
    Author
3 min read
#node #lunrjs #hugo #meta #javascript

Add Search to a Hugo site with Lunr.js and Node.js

Hugo “The world’s fastest framework for building websites” is a great option for JAMStack (JavaScript, APIs, prebuild Markup) sites. Lunr.js is “A bit like Solr, but much smaller and not as bright”, it’s a pure JavaScript implementation of a Solr-lik ...

  • Hugo Di Francesco
    Author
5 min read
← Next Posts Page 3 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