diff --git a/tests/integration/__tests__/cache.js b/tests/integration/__tests__/cache.js index 74891df7f..5d242c31e 100644 --- a/tests/integration/__tests__/cache.js +++ b/tests/integration/__tests__/cache.js @@ -14,14 +14,33 @@ describe("--cache option", () => { ); const nonDefaultCacheFileName = ".non-default-cache-file"; + const directoryNameAsCacheFile = "directory-as-cache-file"; const nonDefaultCacheFilePath = path.join(dir, nonDefaultCacheFileName); - let contentA; - let contentB; + const contentA = `function a() { + console.log("this is a.js") +} +`; + const contentB = `function b() { + console.log("this is b.js"); +} +`; + + const clean = async () => { + await fs.rm(path.join(dir, directoryNameAsCacheFile), { + force: true, + recursive: true, + }); + await fs.rm(nonDefaultCacheFilePath, { force: true }); + await fs.rm(path.join(dir, "a.js"), { force: true }); + await fs.rm(path.join(dir, "b.js"), { force: true }); + }; beforeAll(async () => { - contentA = await fs.readFile(path.join(dir, "a.js"), "utf8"); - contentB = await fs.readFile(path.join(dir, "b.js"), "utf8"); + await clean(); + await fs.mkdir(path.join(dir, directoryNameAsCacheFile)); + await fs.writeFile(path.join(dir, "a.js"), contentA); + await fs.writeFile(path.join(dir, "b.js"), contentB); }); afterEach(async () => { @@ -33,6 +52,7 @@ describe("--cache option", () => { await fs.writeFile(path.join(dir, "a.js"), contentA); await fs.writeFile(path.join(dir, "b.js"), contentB); }); + afterAll(clean); it("throw error when cache-strategy is invalid", async () => { const { stderr } = await runPrettier(dir, [ @@ -73,7 +93,7 @@ describe("--cache option", () => { "foo.js", "--cache", "--cache-location", - "dir", + directoryNameAsCacheFile, ]); expect(stderr.trim()).toEqual( expect.stringMatching( diff --git a/tests/integration/cli/cache/.gitignore b/tests/integration/cli/cache/.gitignore new file mode 100644 index 000000000..03a22858b --- /dev/null +++ b/tests/integration/cli/cache/.gitignore @@ -0,0 +1,6 @@ +# These files are generated by tests +node_modules +directory-as-cache-file +.non-default-cache-file +a.js +b.js diff --git a/tests/integration/cli/cache/a.js b/tests/integration/cli/cache/a.js deleted file mode 100644 index b824ea0f9..000000000 --- a/tests/integration/cli/cache/a.js +++ /dev/null @@ -1,3 +0,0 @@ -function a() { - console.log("this is a.js") -} diff --git a/tests/integration/cli/cache/b.js b/tests/integration/cli/cache/b.js deleted file mode 100644 index 4bc80d22e..000000000 --- a/tests/integration/cli/cache/b.js +++ /dev/null @@ -1,3 +0,0 @@ -function b() { - console.log("this is b.js"); -} diff --git a/tests/integration/cli/cache/dir/.gitkeep b/tests/integration/cli/cache/dir/.gitkeep deleted file mode 100644 index e69de29bb..000000000