Skip to content

after reset, don't bust cache for modules that weren't busted/replaced previously #538

@Schommer79

Description

@Schommer79

Here is a zip file with a working demonstration of the problem (npm run test from inside the folder; node version 24.13.0; Windows 11)

jasmin-testdoubleBugExample.zip

My team uses infrastructure to connect loaded code to the chrome nodejs devtools, in order to enable us to debug our code more easily. It is very common for us to run our jasmine tests more than once in a session. That is what the sequential calls to running the tests are meant to simulate.

Sometimes our jasmine tests use testdouble to replace esm dependencies. Every time jasmine.execute() is called, it will use dynamic import to load all spec files, regardless of whether it has loaded it before, relying on the module cache to prevent re-running specs.

So, the first time, jasmine loads the tests and runs them just fine. During the tests, a module is mocked using td.replaceEsm(). At the end of the tests, td.reset() is called.

The second time, jasmine loads the files again using dynamic import, and testdouble causes the cache to be busted for the test files, despite the fact that, up until this point, testdouble has not been asked about loading the test files at all. This causes the spec file to be run again, and jasmine complains about duplicate specs (even if it didn't error, getting duplicate tests added would be aggravating).

While jasmine could help itself by not trying to reload files that it has already loaded (and I have put in an issue about that), there is also no reason for testdouble to be busting cache on those files, seeing as they are not part of the tree of anything imported while replaceEsm was active, and reset was called before further attempts to import these files occurred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions