From a230f8404e4f2423dd79378b065d24c12776775b Mon Sep 17 00:00:00 2001 From: Eric Wang Date: Sat, 7 Dec 2019 10:44:01 +1100 Subject: [PATCH] Update: include node version in cache (#12582) * Update: Include node version in cache * add test * fix unit test --- lib/cli-engine/lint-result-cache.js | 3 ++- tests/lib/cli-engine/lint-result-cache.js | 29 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/cli-engine/lint-result-cache.js b/lib/cli-engine/lint-result-cache.js index 14e19d9e5a1..23a142097ba 100644 --- a/lib/cli-engine/lint-result-cache.js +++ b/lib/cli-engine/lint-result-cache.js @@ -20,6 +20,7 @@ const hash = require("./hash"); //----------------------------------------------------------------------------- const configHashCache = new WeakMap(); +const nodeVersion = process && process.version; /** * Calculates the hash of the config @@ -28,7 +29,7 @@ const configHashCache = new WeakMap(); */ function hashOfConfigFor(config) { if (!configHashCache.has(config)) { - configHashCache.set(config, hash(`${pkg.version}_${stringify(config)}`)); + configHashCache.set(config, hash(`${pkg.version}_${nodeVersion}_${stringify(config)}`)); } return configHashCache.get(config); diff --git a/tests/lib/cli-engine/lint-result-cache.js b/tests/lib/cli-engine/lint-result-cache.js index 7c5cc20a1e6..a3b6ee3ab2c 100644 --- a/tests/lib/cli-engine/lint-result-cache.js +++ b/tests/lib/cli-engine/lint-result-cache.js @@ -120,6 +120,35 @@ describe("LintResultCache", () => { lintResultsCache = new LintResultCache(cacheFileLocation); }); + describe("when calculating the hashing", () => { + it("contains eslint version during hashing", () => { + const version = "eslint-=-version"; + const NewLintResultCache = proxyquire("../../../lib/cli-engine/lint-result-cache.js", { + "../../package.json": { version }, + "./hash": hashStub + }); + const newLintResultCache = new NewLintResultCache(cacheFileLocation); + + newLintResultCache.getCachedLintResults(filePath, fakeConfig); + assert.ok(hashStub.calledOnce); + assert.ok(hashStub.calledWithMatch(version)); + }); + + it("contains node version during hashing", () => { + const version = "node-=-version"; + + sinon.stub(process, "version").value(version); + const NewLintResultCache = proxyquire("../../../lib/cli-engine/lint-result-cache.js", { + "./hash": hashStub + }); + const newLintResultCache = new NewLintResultCache(cacheFileLocation); + + newLintResultCache.getCachedLintResults(filePath, fakeConfig); + assert.ok(hashStub.calledOnce); + assert.ok(hashStub.calledWithMatch(version)); + }); + }); + describe("When file is changed", () => { beforeEach(() => { hashStub.returns(hashOfConfig);