diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 702a2cf28e8..8576a418bc4 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -190,7 +190,7 @@ class TruffleConfig { // The require-nocache module used to do this for us, but // it doesn't bundle very well. So we've pulled it out ourselves. //@ts-ignore - delete require.cache[Module._resolveFilename(file, module)]; + delete originalRequire.cache[Module._resolveFilename(file, module)]; const staticConfig = originalRequire(file); config.merge(staticConfig); diff --git a/packages/config/test/methods.test.ts b/packages/config/test/methods.test.ts index 381cf31dd84..808900f1c1a 100644 --- a/packages/config/test/methods.test.ts +++ b/packages/config/test/methods.test.ts @@ -38,6 +38,58 @@ describe("TruffleConfig.detect", () => { }); }); +describe("TruffleConfig.load", () => { + it("re-loads a config file after being modified", () => { + const options = { + workingDirectory: `${process.cwd()}/test` + }; + + fs.writeFileSync( + "./test/truffle-config.js", + ` + module.exports = { + networks: { + development: { + url: "http://127.0.0.1:8545" + }, + }, + }; + ` + ); + { + const config = TruffleConfig.detect(options); + delete config.networks["dashboard"]; + assert.deepStrictEqual(config.networks, { + development: { url: "http://127.0.0.1:8545" } + }); + } + + fs.writeFileSync( + "./test/truffle-config.js", + ` + module.exports = { + networks: { + development: { + url: "http://127.0.0.1:8545" + }, + development2: { + url: "http://127.0.0.1:8546" + }, + }, + }; + ` + ); + { + const config = TruffleConfig.detect(options); + delete config.networks["dashboard"]; + assert.deepStrictEqual(config.networks, { + development: { url: "http://127.0.0.1:8545" }, + development2: { url: "http://127.0.0.1:8546" } + }); + } + }); +}); + describe("when it can't find a config file", () => { beforeEach(() => { sinon.stub(TruffleConfig, "search").returns(null);