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

Code before:
        });

        describe("when supplied with report output file path", () => {
            const flag = useFlatConfig ? "--no-config-lookup" : "--no-eslintrc";

            afterEach(() => {
                sh.rm("-rf", "tests/output");
            });

            it(`should write the file and create dirs if they don't exist with configType:${configType}`, async () => {
                const filePath = getFixturePath("single-quoted.js");
                const code = `${flag} --rule 'quotes: [1, double]' --o tests/output/eslint-output.txt ${filePath}`;

                await cli.execute(code, null, useFlatConfig);

                assert.include(fs.readFileSync("tests/output/eslint-output.txt", "utf8"), filePath);
                assert.isTrue(log.info.notCalled);
            });

            // https://github.com/eslint/eslint/issues/17660
            it(`should write the file and create dirs if they don't exist even when output is empty with configType:${configType}`, async () => {
                const filePath = getFixturePath("single-quoted.js");
                const code = `${flag} --rule 'quotes: [1, single]' --o tests/output/eslint-output.txt ${filePath}`;

                await cli.execute(code, "var a = 'b'", useFlatConfig);

                assert.isTrue(fs.existsSync("tests/output/eslint-output.txt"));
                assert.strictEqual(fs.readFileSync("tests/output/eslint-output.txt", "utf8"), "");
                assert.isTrue(log.info.notCalled);
            });

            it(`should return an error if the path is a directory with configType:${configType}`, async () => {
                const filePath = getFixturePath("single-quoted.js");
                const code = `${flag} --rule 'quotes: [1, double]' --o tests/output ${filePath}`;

                fs.mkdirSync("tests/output");

                const exit = await cli.execute(code, null, useFlatConfig);

                assert.strictEqual(exit, 2);
                assert.isTrue(log.info.notCalled);
                assert.isTrue(log.error.calledOnce);
            });

            it(`should return an error if the path could not be written to with configType:${configType}`, async () => {
                const filePath = getFixturePath("single-quoted.js");
                const code = `${flag} --rule 'quotes: [1, double]' --o tests/output/eslint-output.txt ${filePath}`;

                fs.writeFileSync("tests/output", "foo");

                const exit = await cli.execute(code, null, useFlatConfig);

Review comment (suggestion):
```suggestion
                // TODO: fix this test to: await cli.execute(code, null, useFlatConfig);
                await cli.execute(code, "var a = 'b'", useFlatConfig);
```

We should fix all tests that end up targeting files outside the cwd (in particular, we should change the cwd), because in flat config mode those files are ignored. For now, I think it's fine to use stdin here and leave a TODO comment.

Code after:
        });

        describe("when supplied with report output file path", () => {
            const flag = useFlatConfig ? "--no-config-lookup" : "--no-eslintrc";

            afterEach(() => {
                sh.rm("-rf", "tests/output");
            });

            it(`should write the file and create dirs if they don't exist with configType:${configType}`, async () => {
                const filePath = getFixturePath("single-quoted.js");
                const code = `${flag} --rule 'quotes: [1, double]' --o tests/output/eslint-output.txt ${filePath}`;

                await cli.execute(code, null, useFlatConfig);

                assert.include(fs.readFileSync("tests/output/eslint-output.txt", "utf8"), filePath);
                assert.isTrue(log.info.notCalled);
            });

            // https://github.com/eslint/eslint/issues/17660
            it(`should write the file and create dirs if they don't exist even when output is empty with configType:${configType}`, async () => {
                const filePath = getFixturePath("single-quoted.js");
                const code = `${flag} --rule 'quotes: [1, single]' --o tests/output/eslint-output.txt ${filePath}`;

                // TODO: fix this test to: await cli.execute(code, null, useFlatConfig);
                await cli.execute(code, "var a = 'b'", useFlatConfig);

                assert.isTrue(fs.existsSync("tests/output/eslint-output.txt"));
                assert.strictEqual(fs.readFileSync("tests/output/eslint-output.txt", "utf8"), "");
                assert.isTrue(log.info.notCalled);
            });

            it(`should return an error if the path is a directory with configType:${configType}`, async () => {
                const filePath = getFixturePath("single-quoted.js");
                const code = `${flag} --rule 'quotes: [1, double]' --o tests/output ${filePath}`;

                fs.mkdirSync("tests/output");

                const exit = await cli.execute(code, null, useFlatConfig);

                assert.strictEqual(exit, 2);
                assert.isTrue(log.info.notCalled);
                assert.isTrue(log.error.calledOnce);
            });

            it(`should return an error if the path could not be written to with configType:${configType}`, async () => {
                const filePath = getFixturePath("single-quoted.js");
                const code = `${flag} --rule 'quotes: [1, double]' --o tests/output/eslint-output.txt ${filePath}`;

                fs.writeFileSync("tests/output", "foo");