Why Istanbul Is Not Working After Cloning A Repo

I got a new laptop. I installed the latest Node.js and cloned a repo to keep continuing with my React project. I ran npm i to install all dependencies. The app started fine and built fine. However, when I ran npm test, the test was not running.

My test script was this:

nyc --reporter=html --reporter=text mocha -r ts-node/register -r jsdom-global/register ^
-r unitTestSetup.ts **/tests/**/*.ts  --recursive --timeout 5000

The error message was this:

internal/modules/cjs/loader.js:800
    throw err;
    ^
Error: Cannot find module 'C:\Users\takah\Projects\my-to-do-app-typescript-react-hooks\node'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
    at Function.Module._load (internal/modules/cjs/loader.js:690:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

After a little bit of investigation, I realised that Istanbul (nyc) was not working for some reason. The module was used for test coverage.

I actually struggled to solve this issue, but in the end I worked out that I needed to upgrade the version of nyc. The version of nyc was 13.3.0. So I uninstalled module and reinstalled it. This upgraded nyc to 15.0.0.

npm uninstall nyc
npm i --save-dev nyc

For some reason, the older version of nyc is not compatible with the newer version of node and npm. If you are having the same issue with running nyc, just upgrade it. It will start running again.

It took me a while to resolve this. Hopefully this post saves you a bit of time troubleshooting the same problem I had!

Front-End
TypeScript: type aliases to check type equality

This post is to analyse how the type equality check by using type aliases proposed by Matt Pocock in his twitter post. These type aliases allow us to elegantly express type equality checks in unit tests. All we need to do is to pass the output and expected types in …

Front-End
Fixing it.only type error in Jest

If you are getting a type error with it.only in Jest, it could be due to incorrect TypeScript typings or incompatible versions of Jest and TypeScript. To resolve this issue, you can try the following steps: Make sure you have the latest versions of Jest and its TypeScript typings installed …

Front-End
yup conditional validation example

Here’s an example of a Yup validation logic where the first input field is optional but, if filled, it must contain only alphabetic characters, and the second input field is required: import * as Yup from “yup”; const validationSchema = Yup.object().shape({ firstField: Yup.string().matches(/^[A-Za-z]*$/, { message: “First field must contain only …