Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Include node version in cache #12582

Merged
merged 3 commits into from Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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