Skip to content

Commit a230f84

Browse files
fa93hwsKai Cataldo
authored andcommitted
Update: include node version in cache (#12582)
* Update: Include node version in cache * add test * fix unit test
1 parent 8b65f17 commit a230f84

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

lib/cli-engine/lint-result-cache.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const hash = require("./hash");
2020
//-----------------------------------------------------------------------------
2121

2222
const configHashCache = new WeakMap();
23+
const nodeVersion = process && process.version;
2324

2425
/**
2526
* Calculates the hash of the config
@@ -28,7 +29,7 @@ const configHashCache = new WeakMap();
2829
*/
2930
function hashOfConfigFor(config) {
3031
if (!configHashCache.has(config)) {
31-
configHashCache.set(config, hash(`${pkg.version}_${stringify(config)}`));
32+
configHashCache.set(config, hash(`${pkg.version}_${nodeVersion}_${stringify(config)}`));
3233
}
3334

3435
return configHashCache.get(config);

tests/lib/cli-engine/lint-result-cache.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,35 @@ describe("LintResultCache", () => {
120120
lintResultsCache = new LintResultCache(cacheFileLocation);
121121
});
122122

123+
describe("when calculating the hashing", () => {
124+
it("contains eslint version during hashing", () => {
125+
const version = "eslint-=-version";
126+
const NewLintResultCache = proxyquire("../../../lib/cli-engine/lint-result-cache.js", {
127+
"../../package.json": { version },
128+
"./hash": hashStub
129+
});
130+
const newLintResultCache = new NewLintResultCache(cacheFileLocation);
131+
132+
newLintResultCache.getCachedLintResults(filePath, fakeConfig);
133+
assert.ok(hashStub.calledOnce);
134+
assert.ok(hashStub.calledWithMatch(version));
135+
});
136+
137+
it("contains node version during hashing", () => {
138+
const version = "node-=-version";
139+
140+
sinon.stub(process, "version").value(version);
141+
const NewLintResultCache = proxyquire("../../../lib/cli-engine/lint-result-cache.js", {
142+
"./hash": hashStub
143+
});
144+
const newLintResultCache = new NewLintResultCache(cacheFileLocation);
145+
146+
newLintResultCache.getCachedLintResults(filePath, fakeConfig);
147+
assert.ok(hashStub.calledOnce);
148+
assert.ok(hashStub.calledWithMatch(version));
149+
});
150+
});
151+
123152
describe("When file is changed", () => {
124153
beforeEach(() => {
125154
hashStub.returns(hashOfConfig);

0 commit comments

Comments
 (0)