Skip to content

Cached Libs #2

@bendytree

Description

@bendytree

I love this library; it's very elegant. I noticed that running a test individual can have different results than running the whole suite. Since node caches the modules, future requests are pulled from cache and don't have a chance to get intercepted.

Any thoughts on how to handle this?

At first I thought you could clear the cache for the newly mocked libraries each time, but it gets tricky when you're mocking a dependency of a dependency. I'm using mocha, so maybe other test suites handle this better.

For what it's worth, running this before each test fixes the problem (but it's overkill):

for (prop in require.cache)
    if (require.cache.hasOwnProperty(prop))
        delete require.cache[prop];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions