Skip to content

Commit

Permalink
Use rimraf instead of fs.rm
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki committed May 7, 2022
1 parent 898043f commit 71b05be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
23 changes: 4 additions & 19 deletions tests/integration/__tests__/cache-location.js
Expand Up @@ -2,6 +2,7 @@

const path = require("path");
const { promises: fs } = require("fs");
const rimraf = require("rimraf");

const { default: stripAnsi } = require("../../../vendors/strip-ansi.js");

Expand All @@ -20,31 +21,15 @@ function isJson(str) {
}
}

async function rm(file) {
try {
await fs.rm(file);
} catch {
// noop
}
}

async function rmdir(dirPath) {
try {
await await fs.rm(dirPath, { recursive: true, force: true });
} catch {
// noop
}
}

describe("--cache-location option", () => {
const dir = resolveDir("cli/cache-location");
const defaultCacheFile = path.join(dir, ".prettiercache");
const newCacheFile = path.join(dir, ".new_prettiercache");
const newCacheDir = path.join(dir, "cache-dir");

afterEach(async () => {
await rm(newCacheFile);
await rmdir(newCacheDir);
afterEach(() => {
rimraf.sync(newCacheFile);
rimraf.sync(newCacheDir);
});

it("doesn't create `.prettiercache` file when `--cache-location` is used.", async () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/__tests__/cache.js
Expand Up @@ -2,6 +2,7 @@

const path = require("path");
const { promises: fs } = require("fs");
const rimraf = require("rimraf");
const { default: stripAnsi } = require("../../../vendors/strip-ansi.js");

const runPrettier = require("../run-prettier.js");
Expand All @@ -23,7 +24,7 @@ describe("--cache option", () => {
});

afterEach(async () => {
await fs.rm(defaultCacheFile);
rimraf.sync(defaultCacheFile);
await fs.writeFile(path.join(dir, "a.js"), contentA);
await fs.writeFile(path.join(dir, "b.js"), contentB);
});
Expand Down

0 comments on commit 71b05be

Please sign in to comment.