Nodejs - Download Npm Module for Testing
09/12/2021, SunReliance 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:
-
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.
-
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.
-
Download the appropriate Npm module before running any tests which depends on that module.
-
Any kind of destructive tests performed on the download Npm module should be performed last.
-
Perform cleanup of folders and files which were generated through the test cases.