node.js require() cache - possible to invalidate?

后端 未结 17 1947
我寻月下人不归
我寻月下人不归 2020-11-22 06:52

From the node.js documentation:

Modules are cached after the first time they are loaded. This means (among other things) that every call to require(\'

17条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 07:30

    For anyone coming across this who is using Jest, because Jest does its own module caching, there's a built-in function for this - just make sure jest.resetModules runs eg. after each of your tests:

    afterEach( function() {
      jest.resetModules();
    });
    

    Found this after trying to use decache like another answer suggested. Thanks to Anthony Garvan.

    Function documentation here.

提交回复
热议问题