ioBroker / testing

Shared testing utilities for ioBroker
MIT License
8 stars 12 forks source link

Subsequent integration tests won't grab the newest source code but will re-use a cached version #612

Closed MiSchroe closed 3 months ago

MiSchroe commented 3 months ago

Description of the issue

Expected behaviour

As a developer I would like to run an integration test against a real js-controller to check that my adapter starts successfully and eventually I would like to add some additional tests using the defineAdditionalTests method. Eventually, some of these tests may fail.

Eventually, I would like to modify my source code to fix those bugs and re-run the integration tests. Now, the tests will pass.

Actual behaviour

Even after fixing the bugs the tests will still fail, because my changes won't be copied to the node_modules folder in the temp folder of the integration test. See also the discussion at https://discord.com/channels/743167951875604501/743171252377616476/1263559755025223841 (in German language)

Steps to reproduce

  1. Run test:integration -> The adapter starts and does e.g. some logging.
  2. Make changes to your adapter, e.g. include some new logging at the beginning of your adapter, so that you will see some difference.
  3. Re-run test:integration -> The changes won't be applied. Instead, you will find the previous code in the node_modules folder in the temp folder.

Further analysis of the issue

I have debugged the adapterSetup.ts and also the npm installprocess.

The following lines are deleting the folder of the adapter in the node_modules folder: https://github.com/ioBroker/testing/blob/58c0bc073230c31060c39c6df19ae6b9d557c8c2/src/tests/integration/lib/adapterSetup.ts#L98-L100

Unfortunately, this is not enough. Probably during npm pack or npm install the package is saved to the local cache in C:\Users\myusername\AppData\Local\npm-cache\_cacache (on a Windows machine, on Linux there will be some other path). On the next run of npm install - even with a changed tarball - the cached version is used.

AlCalzone commented 3 months ago

I think wiping the test directory is not desired, since this will also cause js-controller and admin to be reinstalled, which takes time. Some thoughts, since I've been recently noticing similar behavior in a different situation:

MiSchroe commented 3 months ago

npm updatedoes the trick and automatically runs an install if the package is not installed. I have provided a pull request.

AlCalzone commented 3 months ago

Huh, good find!