Skip to content

Commit

Permalink
Update: include node version in cache (#12582)
Browse files Browse the repository at this point in the history
* Update: Include node version in cache

* add test

* fix unit test
  • Loading branch information
fa93hws authored and kaicataldo committed Dec 6, 2019
1 parent 8b65f17 commit a230f84
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cli-engine/lint-result-cache.js
Expand Up @@ -20,6 +20,7 @@ const hash = require("./hash");
//-----------------------------------------------------------------------------

const configHashCache = new WeakMap();
const nodeVersion = process && process.version;

/**
* Calculates the hash of the config
Expand All @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/cli-engine/lint-result-cache.js
Expand Up @@ -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);
Expand Down

0 comments on commit a230f84

Please sign in to comment.