Nodejs - Download Npm Module for Testing

09/12/2021, Sun
Categories: #JavaScript
Tags: #NodeJs

Reliance on another NPM module

A Npm module which is heavily dependent on another Npm module because the module being written wraps another module's methods, and it might entail having to download the other module during testing.

Also, you might have to do this when your node module's functionality creates new project instances with the downloaded module which you want to perform checks with test cases. You won't necessarily test the other module's methods directly, but you are testing your own module to see if the indirect calling of methods is wired up properly.

Recommendations when interacting with downloaded Npm modules during testing:

  1. Make it the first step in the testing process. However, any kind of units test which do not rely on the downloaded module should be run in parallel to the download Npm module step for speed. You will need to create a new Npm script command to execute the two operations in parallel.

  2. Check for internet connectivity and provide warnings if connection is not found and skip the set of tests which depends on the download of the module.

  3. Download the appropriate Npm module before running any tests which depends on that module.

  4. Any kind of destructive tests performed on the download Npm module should be performed last.

  5. Perform cleanup of folders and files which were generated through the test cases.