Skip to content

Commit

Permalink
Fix: Delete cache only when executing on files (fixes #6459) (#6540)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo authored and nzakas committed Jun 28, 2016
1 parent e0d4b19 commit d601f6b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,6 @@ function CLIEngine(options) {
*/
this._fileCache = fileEntryCache.create(cacheFile);

if (!this.options.cache) {
this._fileCache.destroy();
}

// load in additional rules
if (this.options.rulePaths) {
var cwd = this.options.cwd;
Expand Down Expand Up @@ -665,6 +661,8 @@ CLIEngine.prototype = {
// move to the next file
return;
}
} else {
fileCache.destroy();
}

debug("Processing " + filename);
Expand Down
90 changes: 90 additions & 0 deletions tests/lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,7 @@ describe("CLIEngine", function() {

assert.isFalse(fs.existsSync(cacheFile), "the cache for eslint was deleted since last run did not used the cache");
});

it("should not store in the cache a file that failed the test", function() {

var cacheFile = getFixturePath(".eslintcache");
Expand Down Expand Up @@ -1812,6 +1813,95 @@ describe("CLIEngine", function() {
assert.deepEqual(result, cachedResult, "result is the same with or without cache");
});

it("should not delete cache when executing on text", function() {
var cacheFile = getFixturePath(".eslintcache");

engine = new CLIEngine({
cwd: path.join(fixtureDir, ".."),
useEslintrc: false,
cacheFile: cacheFile,
rules: {
"no-console": 0,
"no-unused-vars": 2
},
extensions: ["js"]
});

assert.isTrue(fs.existsSync(cacheFile), "the cache for eslint exists");

engine.executeOnText("var foo = 'bar';");

assert.isTrue(fs.existsSync(cacheFile), "the cache for eslint still exists");
});

it("should not delete cache when executing on text with a provided filename", function() {
var cacheFile = getFixturePath(".eslintcache");

engine = new CLIEngine({
cwd: path.join(fixtureDir, ".."),
useEslintrc: false,
cacheFile: cacheFile,
rules: {
"no-console": 0,
"no-unused-vars": 2
},
extensions: ["js"]
});

assert.isTrue(fs.existsSync(cacheFile), "the cache for eslint exists");

engine.executeOnText("var bar = foo;", "fixtures/passing.js");

assert.isTrue(fs.existsSync(cacheFile), "the cache for eslint still exists");
});

it("should not delete cache when executing on files with --cache flag", function() {
var cacheFile = getFixturePath(".eslintcache");

engine = new CLIEngine({
cwd: path.join(fixtureDir, ".."),
useEslintrc: false,
cache: true,
cacheFile: cacheFile,
rules: {
"no-console": 0,
"no-unused-vars": 2
},
extensions: ["js"]
});

var file = getFixturePath("cli-engine", "console.js");

assert.isTrue(fs.existsSync(cacheFile), "the cache for eslint exists");

engine.executeOnFiles([file]);

assert.isTrue(fs.existsSync(cacheFile), "the cache for eslint still exists");
});

it("should delete cache when executing on files without --cache flag", function() {
var cacheFile = getFixturePath(".eslintcache");

engine = new CLIEngine({
cwd: path.join(fixtureDir, ".."),
useEslintrc: false,
cacheFile: cacheFile,
rules: {
"no-console": 0,
"no-unused-vars": 2
},
extensions: ["js"]
});

var file = getFixturePath("cli-engine", "console.js");

assert.isTrue(fs.existsSync(cacheFile), "the cache for eslint exists");

engine.executeOnFiles([file]);

assert.isFalse(fs.existsSync(cacheFile), "the cache for eslint has been deleted");
});

describe("cacheFile", function() {
it("should use the specified cache file", function() {
var customCacheFile = path.resolve(".cache/custom-cache");
Expand Down

0 comments on commit d601f6b

Please sign in to comment.