#javascript #node #testing #jestConfigure Timezone for Jest/Node.js with the `TZ` env varIn 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 ...
#nock #jest #testing #nodeNock on Node 18/20/22 Fails to Intercept isomorphic-unfetch/fetch RequestOn 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 ...
#javascript #node`dotenv` not required: load `.env` and parse env vars natively in modern Node.jsdotenv 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 ...
#javascript #jest #node #Testing #dateMocking/stubbing the current Date in Jest testsThere 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 ...
#javascript #mermaidDocsify Mermaid 10Using 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. ...
#node:test #testing #node #javascriptMocking/stubbing the Date and timers (setTimeout) in Node.js tests with built-in `node:test` MockTimersMockTimers 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. ...
#cli #node #git #direnv #awsDirenv setup for multiple git/GitHub, npm and AWS accounts/credentialsIn 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. ...
#node:test #testing #nodeTest Native `fetch` in Node.js with Undici interception and mock utilsNode.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 ...
#node:test #node #testing #javascriptNode Test Runner: skip a test if an environment variable is missing/emptyThe 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 ...
#lerna #tooling #node #javascriptLerna publish with no git commit, tag or pushTo 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 ...