Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Selective clear when useCleanCache is true #49

Open
alanszp opened this issue May 31, 2016 · 1 comment
Open

Selective clear when useCleanCache is true #49

alanszp opened this issue May 31, 2016 · 1 comment

Comments

@alanszp
Copy link

alanszp commented May 31, 2016

There is a missing feature, that when I use useCleanCache: true, I can't specify a file/folder to be excluded from the cleaning, and to remain as a chached module.

The problems is this:
I have a file that creates an in-memory database with bookshelf.js (and a few options setting the connection is to a sqlite db). If I use useCleanCache: true, that file will be "unloaded" and when I require it again in my tests, it will be loaded again.
The result of this, will be that I will have an unlodaded in-memory database and a new in-memory database.

Notes:
I know there is a discussion if I should or shouldn't test with a db or not. I know it's not the best practice to do it, because it won't be a real unit test, but I would like to in this case. Also, setting up a real db for testing would make the testing slower. I don't want to enter in this discusion right now :D

The solution:
Add a new option: remainingCache: [RegExp] which will contain an array of RegExps, and will be used only if useCleanCache: true. This will change the override of m._cache = {} with an object filled with the original modules that the file name matched any of the RegExps.

I will make a PR with this if you are ok!

@javieranselmi
Copy link

I am having exactly the same issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants