Repository: eslint/eslint
File: tests/lib/eslint/flat-eslint.js (JavaScript)

Code before:
            });

            afterEach(() => {
                sinon.restore();
                deleteCache();
            });

            describe("when the cacheFile is a directory or looks like a directory", () => {

                /**
                 * helper method to delete the cache files created during testing
                 * @returns {void}
                 */
                function deleteCacheDir() {
                    try {
                        fs.unlinkSync("./tmp/.cacheFileDir/.cache_hashOfCurrentWorkingDirectory");
                    } catch {

                        /*
                         * we don't care if the file didn't exist, since our
                         * intention was to remove the file
                         */
                    }
                }
                beforeEach(() => {
                    deleteCacheDir();
                });

                afterEach(() => {
                    deleteCacheDir();
                });

                it("should create the cache file inside the provided directory", async () => {
                    assert(!shell.test("-d", path.resolve("./tmp/.cacheFileDir/.cache_hashOfCurrentWorkingDirectory")), "the cache for eslint does not exist");

                    eslint = new FlatESLint({
                        overrideConfigFile: true,

                        // specifying cache true the cache will be created
                        cache: true,
                        cacheLocation: "./tmp/.cacheFileDir/",
                        overrideConfig: {
                            rules: {
                                "no-console": 0,
                                "no-unused-vars": 2
                            }
                        },
                        ignore: false
                    });
                    const file = getFixturePath("cache/src", "test-file.js");


Review comment (performance):
This was actually deleting nothing because the cache file is not named ".cache_hashOfCurrentWorkingDirectory". When this test was added in https://github.com/eslint/eslint/commit/b5e66daf76f2015e9283cdcd7556ff1583695d0a, this was really deleting the cache file because the `hash` function was mocked in the tests, but that code disappeared over time.

I updated this to remove the `.cacheFileDir/` directory as the name of this function suggests, since that makes the most sense for the tests.

Code after:
            });

            describe("when cacheLocation is a directory or looks like a directory", () => {

                const cwd = getFixturePath();

                /**
                 * helper method to delete the directory used in testing
                 * @returns {void}
                 */
                function deleteCacheDir() {
                    try {

                        /*
                         * `fs.rmdir(path, { recursive: true })` is deprecated and will be removed.
                         * Use `fs.rm(path, { recursive: true })` instead.
                         * When supporting Node.js 14.14.0+, the compatibility condition can be removed for `fs.rmdir`.
                         */
                        if (typeof fsp.rm === "function") {

                            // eslint-disable-next-line n/no-unsupported-features/node-builtins -- conditionally used
                            fs.rmSync(path.resolve(cwd, "tmp/.cacheFileDir/"), { recursive: true, force: true });
                        } else {
                            fs.rmdirSync(path.resolve(cwd, "tmp/.cacheFileDir/"), { recursive: true, force: true });
                        }

                    } catch {

                        /*
                         * we don't care if the file didn't exist, since our
                         * intention was to remove the file
                         */
                    }
                }
                beforeEach(() => {
                    deleteCacheDir();
                });

                afterEach(() => {
                    deleteCacheDir();
                });

                it("should create the directory and the cache file inside it when cacheLocation ends with a slash", async () => {
                    assert(!shell.test("-d", path.resolve(cwd, "./tmp/.cacheFileDir/")), "the cache directory already exists and wasn't successfully deleted");

                    eslint = new FlatESLint({
                        overrideConfigFile: true,
                        cwd,

                        // specifying cache true the cache will be created
                        cache: true,