Repository: prettier/prettier
File: tests/integration/__tests__/cache.js (JavaScript)

Code before:
    await fs.writeFile(path.join(dir, "a.js"), contentA);
    await fs.writeFile(path.join(dir, "b.js"), contentB);
  });

  afterEach(async () => {
    await fs.rm(path.join(dir, "node_modules"), {
      force: true,
      recursive: true,
    });
    await fs.rm(nonDefaultCacheFilePath, { force: true });
    await fs.writeFile(path.join(dir, "a.js"), contentA);
    await fs.writeFile(path.join(dir, "b.js"), contentB);
  });
  afterAll(clean);

  it("creates cache file with --cache", async () => {
    await runCliWithoutGitignore(dir, ["--cache", "*.js"]);
    await expect(fs.stat(defaultCacheFile)).resolves.not.toThrow();
  });

  it("doesn't create cache directory without --cache", async () => {
    await runCliWithoutGitignore(dir, ["*.js"]);
    await expect(
      fs.stat(path.join(dir, "node_modules/.cache")),
    ).rejects.toHaveProperty("code", "ENOENT");
  });

  it("throw error when cache-strategy is invalid", async () => {
    const { stderr } = await runCliWithoutGitignore(dir, [
      "--cache",
      "--cache-strategy",
      "invalid",
      "*.js",
    ]);
    expect(stderr.trim()).toBe(
      '[error] Invalid --cache-strategy value. Expected "content" or "metadata", but received "invalid".',
    );
  });

  it("throws error when use with --stdin-filepath", async () => {
    const { stderr } = await runCliWithoutGitignore(
      dir,
      ["--cache", "--stdin-filepath", "foo.js"],
      { input: "const a = a;" },
    );
    expect(stderr.trim()).toBe(
      "[error] `--cache` cannot be used when formatting stdin.",
    );
  });

  it("throws error when use `--cache-strategy` without `--cache`.", async () => {

Review comment (performance):
```suggestion
  it("creates cache file with --cache", async () => {
    await runCliWithoutGitignore(dir, ["--cache", "a.js"]);
    await expect(fs.stat(defaultCacheFile)).resolves.not.toThrow();
  });

  it("doesn't create cache directory without --cache", async () => {
    await runCliWithoutGitignore(dir, ["a.js"]);
    await expect(
      fs.stat(path.join(dir, "node_modules/.cache")),
    ).rejects.toHaveProperty("code", "ENOENT");
  });
```

Code after:
    await fs.writeFile(path.join(dir, "a.js"), contentA);
    await fs.writeFile(path.join(dir, "b.js"), contentB);
  });

  afterEach(async () => {
    await fs.rm(path.join(dir, "node_modules"), {
      force: true,
      recursive: true,
    });
    await fs.rm(nonDefaultCacheFilePath, { force: true });
    await fs.writeFile(path.join(dir, "a.js"), contentA);
    await fs.writeFile(path.join(dir, "b.js"), contentB);
  });
  afterAll(clean);

  it("creates cache file with --cache", async () => {
    await runCliWithoutGitignore(dir, ["--cache", "a.js"]);
    await expect(fs.stat(defaultCacheFile)).resolves.not.toThrow();
  });

  it("doesn't create cache directory without --cache", async () => {
    await runCliWithoutGitignore(dir, ["a.js"]);
    await expect(
      fs.stat(path.join(dir, "node_modules/.cache")),
    ).rejects.toHaveProperty("code", "ENOENT");
  });

  it("throw error when cache-strategy is invalid", async () => {
    const { stderr } = await runCliWithoutGitignore(dir, [
      "--cache",
      "--cache-strategy",
      "invalid",
      "*.js",
    ]);
    expect(stderr.trim()).toBe(
      '[error] Invalid --cache-strategy value. Expected "content" or "metadata", but received "invalid".',
    );
  });

  it("throws error when use with --stdin-filepath", async () => {
    const { stderr } = await runCliWithoutGitignore(
      dir,
      ["--cache", "--stdin-filepath", "foo.js"],
      { input: "const a = a;" },
    );
    expect(stderr.trim()).toBe(
      "[error] `--cache` cannot be used when formatting stdin.",
    );
  });

  it("throws error when use `--cache-strategy` without `--cache`.", async () => {