From 640daec6e60b592b4e85298fa9cf29e567db2d8c Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 20 Nov 2019 16:38:33 +1100 Subject: [PATCH 1/3] New: Include node version in cache --- lib/cli-engine/lint-result-cache.js | 3 ++- 1 file changed, 2 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); From 1ea6459f6f7b6f5d8f2e68e359fac5d2cd9d96b1 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 21 Nov 2019 18:15:59 +1100 Subject: [PATCH 2/3] add test --- tests/lib/cli-engine/lint-result-cache.js | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/lib/cli-engine/lint-result-cache.js b/tests/lib/cli-engine/lint-result-cache.js index 7c5cc20a1e6..2d89470c561 100644 --- a/tests/lib/cli-engine/lint-result-cache.js +++ b/tests/lib/cli-engine/lint-result-cache.js @@ -120,6 +120,37 @@ describe("LintResultCache", () => { lintResultsCache = new LintResultCache(cacheFileLocation); }); + describe("when calculating the hashing", () => { + const calculateHash = sinon.stub(); + + it("contains eslint version during hashing", () => { + const version = "eslint-=-version"; + const NewLintResultCache = proxyquire("../../../lib/cli-engine/lint-result-cache.js", { + "../../package.json": { version }, + "./hash": calculateHash + }); + const newLintResultCache = new NewLintResultCache(cacheFileLocation); + + newLintResultCache.getCachedLintResults(filePath, fakeConfig); + assert.ok(calculateHash.calledOnce); + assert.ok(calculateHash.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": calculateHash + }); + const newLintResultCache = new NewLintResultCache(cacheFileLocation); + + newLintResultCache.getCachedLintResults(filePath, fakeConfig); + assert.ok(calculateHash.calledOnce); + assert.ok(calculateHash.calledWithMatch("version")); + }); + }); + describe("When file is changed", () => { beforeEach(() => { hashStub.returns(hashOfConfig); From 068b36b49b125bdc70f6c85f99eea7a690c8409d Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 21 Nov 2019 18:29:46 +1100 Subject: [PATCH 3/3] fix unit test --- tests/lib/cli-engine/lint-result-cache.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/lib/cli-engine/lint-result-cache.js b/tests/lib/cli-engine/lint-result-cache.js index 2d89470c561..a3b6ee3ab2c 100644 --- a/tests/lib/cli-engine/lint-result-cache.js +++ b/tests/lib/cli-engine/lint-result-cache.js @@ -121,19 +121,17 @@ describe("LintResultCache", () => { }); describe("when calculating the hashing", () => { - const calculateHash = sinon.stub(); - it("contains eslint version during hashing", () => { const version = "eslint-=-version"; const NewLintResultCache = proxyquire("../../../lib/cli-engine/lint-result-cache.js", { "../../package.json": { version }, - "./hash": calculateHash + "./hash": hashStub }); const newLintResultCache = new NewLintResultCache(cacheFileLocation); newLintResultCache.getCachedLintResults(filePath, fakeConfig); - assert.ok(calculateHash.calledOnce); - assert.ok(calculateHash.calledWithMatch(version)); + assert.ok(hashStub.calledOnce); + assert.ok(hashStub.calledWithMatch(version)); }); it("contains node version during hashing", () => { @@ -141,13 +139,13 @@ describe("LintResultCache", () => { sinon.stub(process, "version").value(version); const NewLintResultCache = proxyquire("../../../lib/cli-engine/lint-result-cache.js", { - "./hash": calculateHash + "./hash": hashStub }); const newLintResultCache = new NewLintResultCache(cacheFileLocation); newLintResultCache.getCachedLintResults(filePath, fakeConfig); - assert.ok(calculateHash.calledOnce); - assert.ok(calculateHash.calledWithMatch("version")); + assert.ok(hashStub.calledOnce); + assert.ok(hashStub.calledWithMatch(version)); }); });