From 92fc2f4f3faf8aeaae8a8e71db0de405404fb6c3 Mon Sep 17 00:00:00 2001 From: Terry Date: Wed, 6 Feb 2019 16:17:47 +0800 Subject: [PATCH] Fix: CircularJSON dependency warning (fixes #11052) (#11314) --- package.json | 2 +- tests/lib/cli-engine.js | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index c3ad0008a18..f1776d80495 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "espree": "^5.0.0", "esquery": "^1.0.1", "esutils": "^2.0.2", - "file-entry-cache": "^2.0.0", + "file-entry-cache": "^5.0.1", "functional-red-black-tree": "^1.0.1", "glob": "^7.1.2", "globals": "^11.7.0", diff --git a/tests/lib/cli-engine.js b/tests/lib/cli-engine.js index fd961cb6353..f2cfb03187c 100644 --- a/tests/lib/cli-engine.js +++ b/tests/lib/cli-engine.js @@ -21,6 +21,8 @@ const assert = require("chai").assert, const proxyquire = require("proxyquire").noCallThru().noPreserveCache(); +const fCache = require("file-entry-cache"); + //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ @@ -2375,11 +2377,12 @@ describe("CLIEngine", () => { assert.isTrue(shell.test("-f", cacheFile), "the cache for eslint was created"); - const cache = JSON.parse(fs.readFileSync(cacheFile)); + const fileCache = fCache.createFromFile(cacheFile); + const { cache } = fileCache; - assert.isTrue(typeof cache[goodFile] === "object", "the entry for the good file is in the cache"); + assert.isTrue(typeof cache.getKey(goodFile) === "object", "the entry for the good file is in the cache"); - assert.isTrue(typeof cache[badFile] === "object", "the entry for the bad file is in the cache"); + assert.isTrue(typeof cache.getKey(badFile) === "object", "the entry for the bad file is in the cache"); const cachedResult = engine.executeOnFiles([badFile, goodFile]); @@ -2412,9 +2415,10 @@ describe("CLIEngine", () => { engine.executeOnFiles([badFile, goodFile, toBeDeletedFile]); - let cache = JSON.parse(fs.readFileSync(cacheFile)); + const fileCache = fCache.createFromFile(cacheFile); + let { cache } = fileCache; - assert.isTrue(typeof cache[toBeDeletedFile] === "object", "the entry for the file to be deleted is in the cache"); + assert.isTrue(typeof cache.getKey(toBeDeletedFile) === "object", "the entry for the file to be deleted is in the cache"); // delete the file from the file system fs.unlinkSync(toBeDeletedFile); @@ -2456,9 +2460,10 @@ describe("CLIEngine", () => { engine.executeOnFiles([badFile, goodFile, testFile2]); - let cache = JSON.parse(fs.readFileSync(cacheFile)); + let fileCache = fCache.createFromFile(cacheFile); + let { cache } = fileCache; - assert.isTrue(typeof cache[testFile2] === "object", "the entry for the test-file2 is in the cache"); + assert.isTrue(typeof cache.getKey(testFile2) === "object", "the entry for the test-file2 is in the cache"); /* * we pass a different set of files minus test-file2 @@ -2467,9 +2472,10 @@ describe("CLIEngine", () => { */ engine.executeOnFiles([badFile, goodFile]); - cache = JSON.parse(fs.readFileSync(cacheFile)); + fileCache = fCache.createFromFile(cacheFile); + cache = fileCache.cache; - assert.isTrue(typeof cache[testFile2] === "object", "the entry for the test-file2 is in the cache"); + assert.isTrue(typeof cache.getKey(testFile2) === "object", "the entry for the test-file2 is in the cache"); }); it("should not delete cache when executing on text", () => { @@ -2590,11 +2596,12 @@ describe("CLIEngine", () => { assert.isTrue(shell.test("-f", customCacheFile), "the cache for eslint was created"); - const cache = JSON.parse(fs.readFileSync(customCacheFile)); + const fileCache = fCache.createFromFile(customCacheFile); + const { cache } = fileCache; - assert.isTrue(typeof cache[goodFile] === "object", "the entry for the good file is in the cache"); + assert.isTrue(typeof cache.getKey(goodFile) === "object", "the entry for the good file is in the cache"); - assert.isTrue(typeof cache[badFile] === "object", "the entry for the bad file is in the cache"); + assert.isTrue(typeof cache.getKey(badFile) === "object", "the entry for the bad file is in the cache"); const cachedResult = engine.executeOnFiles([badFile, goodFile]);