From 835c20163eeb37d0c433dea5c33379cf0d323def Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Fri, 27 May 2022 18:39:13 +0900 Subject: [PATCH] Add tests for timestamp --- tests/integration/__tests__/cache.js | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/integration/__tests__/cache.js b/tests/integration/__tests__/cache.js index 35932595da49..8b89888e64bf 100644 --- a/tests/integration/__tests__/cache.js +++ b/tests/integration/__tests__/cache.js @@ -110,6 +110,37 @@ describe("--cache option", () => { ); }); + it("re-formats when timestamp has been updated", async () => { + const { stdout: firstStdout } = await runPrettier(dir, [ + "--cache", + "--write", + ".", + ]); + expect(stripAnsi(firstStdout).split("\n").filter(Boolean)).toEqual( + expect.arrayContaining([ + expect.stringMatching(/^a\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms$/), + ]) + ); + + // update timestamp + const time = new Date(); + await fs.utimes(path.join(dir, "a.js"), time, time); + + const { stdout: secondStdout } = await runPrettier(dir, [ + "--cache", + "--write", + ".", + ]); + expect(stripAnsi(secondStdout).split("\n").filter(Boolean)).toEqual( + // the cache of `b.js` is only available. + expect.arrayContaining([ + expect.stringMatching(/^a\.js .+ms$/), + expect.stringMatching(/^b\.js .+ms \(cached\)$/), + ]) + ); + }); + it("re-formats when options has been updated.", async () => { const { stdout: firstStdout } = await runPrettier(dir, [ "--cache",