test: fixed `npm search` tests failing on CI

Fixed `helpers.runNpmInDirectory()` to configure custom npm cache directory.
This ensures that both developers and CI server use the same cache.

Fixed `npm search` tests to clean the npm cache before running the test. This
solves the problem where the test was failing because npm was using a stale
cached search result.

Added more debug logging to help troubleshoot failing tests.

Modified `helpers.runNpmInDirectory()` to pass `enc` to `child_process.exec()`,
now it's no longer necessary to convert `stdout` and `stderr` to string.
Fixed exception being thrown on index() method after package was deleted.

index() method tries to access empty versions array. Added check to see if
the version exists in the versions array.