#jest #javascript #node #testingHow to run Jest tests sequentiallyBy 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. ...
#javascript #nodeDetect if the current file/module is the entrypoint or import/require-d in Node.jsHow 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 ...
#meta #jamstack #hugo #javascriptAdd Diagrams to your Jekyll/Hugo/Gatsby blog with Mermaid JSAdd diagrams to your JAMStack (Jekyll/Hugo/Gatsby) blog with Mermaid JS Update 17th January 2024: Hugo now has native hooks for diagrams, so that code-fences using ```mermaid [content]``` can have a custom template, see the Content Management > Diagrams > Mermaid diagrams ...
#javascript #node #metaYarn Workspaces: monorepo management without Lerna for applications and coding examplesHow 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 ...
#node #lunrjs #hugo #meta #javascriptAdd Search to a Hugo site with Lunr.js and Node.jsHugo “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 ...
#javascriptJavaScript Data Type Check CheatsheetJavaScript (JS) is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions. MDN Web Docs - javascript Detailed in this post are common JavaScript data type checks, pitfalls and idiomatic workarounds. ...
#javascript #jest #testing #nodeJest ignore or exclude file/function/statement from test coverageIn computer science, test coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs. Code coverage - Wikipedia Code coverage is usually used as a quality metric for software eg. “Our code has to have 80% ...
#node #serverless #javascript #automation #deploymentSuper-powered newsletter content with Pocket and Netlify LambdaAn example Netlify Lambda to fetch all “newsletter” posts from Pocket. Pocket is an application and web service for managing a reading list of articles from the Internet. It’s quite widely used and tightly integrated into the Firefox browser. I find that I use it extensive ...
#javascript #node #jest #testing #MongoDBAvoiding recursion pitfalls: MongoDB nested query clause addition and removalA case-study on where recursion can be useful for enterprise Node.js applications and how to avoid its common pitfalls like RangeError: Maximum call stack size exceeded. The full repository for this post is on GitHub: github.com/HugoDF/mongo-query-clause-modification We’ll ...
#node #Express #javascriptRead and parse POST/PATCH/PUT request JSON or form body with Express and no dependenciesWhen asked to handle data in a request body, developers who have used Express (the “Fast, unopinionated, minimalist web framework for Node.js”) before, reach for the body-parser library. What they might not know is that body-parser is a dependency of Express and its main JSON par ...