sjinks / node-config-reloadable

Reloadable version of lorenwest/node-config
https://www.npmjs.com/package/config-reloadable
MIT License
8 stars 1 forks source link

Reload scenario failed with jest #83

Open provDannyLaw opened 2 years ago

provDannyLaw commented 2 years ago

Hi,

I am trying out the node-config-reloadable dependency without success. I copied the test case

let config = require('config-reloadable');

describe("node-config load", () => {
    test("loading", () => {
        const r1 = config().get('rand');
        config.reloadConfigs();
        const r2 = config().get('rand');
        expect(r1).not.toEqual(r2);
    });
});

The expectation came back as false as the rand value did not get recalculated.

The dependencies I am using are

    "config": "3.3.7",
    "config-reloadable": "1.0.9",
provDannyLaw commented 2 years ago

It seems to be only malfunctioning in a jest test. reloadConfigs is working as expected when I integrated that into my project.

sjinks commented 2 years ago

I suspect that this happens because Jest hooks into require() and implements its own logic to support mocks etc.

node-config-reloadable also uses require()'s internals, probably in a way that is incompatible with jest.

I will take a look, but I am not sure how easy to fix it will be.