Skip to content

Commit

Permalink
Add tests for timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed May 27, 2022
1 parent b0593a4 commit 835c201
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/integration/__tests__/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 835c201

Please sign in to comment.