Code with Hugo

Node.js and JavaScript Guides

  • Home
  • Books
  • Node
  • Testing
  • JavaScript
  • More...
  • Search
  • About
  • Gear & Setup
Subscribe
#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
#web development #deployment #seo

Importance of Blocking Web Crawlers and Bots From Your Website

The technical term, “crawling” means accessing websites automatically and obtaining data. Web crawlers, spiders, or search engine bots download and index web content from the Internet. Search engines, like Google, use bots or web crawlers and apply search algorithm to ...

  • Paolo Sallow
    Author
4 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
#deployment #netlify #jamstack #meta

Auto-publish future posts with JAMstack on Netlify and IFTTT/CircleCI 2.0 scheduled jobs

Static site generators like Hugo, Jekyll, Hexo, Gatsby or other JAMstack alternative are a great option to run your blog on. One of the earliest and possibly most painful issues you will come across is “How do I schedule content to publish for later?”. In the traditional database ...

  • Hugo Di Francesco
    Author
4 min read
#javascript #react #vuejs

Detect ctrl/cmd/alt/shift + Click in Vanilla JavaScript, React and Vue.js

Detecting control-click, command-click, meta-click, alt-click and shift-click in JavaScript without listening to keydown events is straightforward. The naive approach is to bind aggressively to key events (keydown, keypress, keyup) and to maintain state of what is currently press ...

  • Hugo Di Francesco
    Author
2 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
← Next Posts Page 7 of 15  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