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

Code before:

            it(`should not print debug info when passed the empty string as text with configType:${configType}`, async () => {
                const flag = useFlatConfig ? "--no-config-lookup" : "--no-eslintrc";
                const result = await cli.execute(["--stdin", flag, "--stdin-filename", "foo.js"], "", useFlatConfig);

                assert.strictEqual(result, 0);
                assert.isTrue(log.info.notCalled);
            });

            it(`should exit with console error when passed unsupported arguments with configType:${configType}`, async () => {
                const filePath = getFixturePath("files");
                const result = await cli.execute(`--blah --another ${filePath}`, null, useFlatConfig);

                assert.strictEqual(result, 2);
            });

        });

        describe("flat config", () => {
            const originalCwd = process.cwd;
            const originalEnv = { ...process.env };

            afterEach(() => {
                process.cwd = originalCwd;
                process.env = { ...originalEnv };
            });

            it(`should use it when an eslint.config.js is present and useFlatConfig is true:${configType}`, async () => {
                process.cwd = getFixturePath;

                const exitCode = await cli.execute(`--no-ignore --ext .js ${getFixturePath("files")}`, null, useFlatConfig);

                // When flat config is used, we get an exit code of 2 because the --ext option is unrecognized.
                assert.strictEqual(exitCode, useFlatConfig ? 2 : 0);
            });

            it(`should not use it when ESLINT_USE_FLAT_CONFIG=false even if an eslint.config.js is present:${configType}`, async () => {
                process.cwd = getFixturePath;
                process.env.ESLINT_USE_FLAT_CONFIG = "false";

                const exitCode = await cli.execute(`--no-ignore --ext .js ${getFixturePath("files")}`, null, useFlatConfig);

                assert.strictEqual(exitCode, 0);
            });

            it(`should use it when ESLINT_USE_FLAT_CONFIG=true and useFlatConfig is true even if an eslint.config.js is not present:${configType}`, async () => {
                process.env.ESLINT_USE_FLAT_CONFIG = "true";

                const exitCode = await cli.execute(`--no-ignore --ext .js ${getFixturePath("files")}`, null, useFlatConfig);

                // When flat config is used, we get an exit code of 2 because the --ext option is unrecognized.

Review comment (suggestion):
```suggestion
            const originalEnv = process.env;
            
            beforeEach(() => {
                process.env = { ...originalEnv };
            });

            afterEach(() => {
                process.cwd = originalCwd;
                process.env = originalEnv;
            });
```

I think it would be better to keep the original `process.env` object.

Code after:

            it(`should not print debug info when passed the empty string as text with configType:${configType}`, async () => {
                const flag = useFlatConfig ? "--no-config-lookup" : "--no-eslintrc";
                const result = await cli.execute(["--stdin", flag, "--stdin-filename", "foo.js"], "", useFlatConfig);

                assert.strictEqual(result, 0);
                assert.isTrue(log.info.notCalled);
            });

            it(`should exit with console error when passed unsupported arguments with configType:${configType}`, async () => {
                const filePath = getFixturePath("files");
                const result = await cli.execute(`--blah --another ${filePath}`, null, useFlatConfig);

                assert.strictEqual(result, 2);
            });

        });

        describe("flat config", () => {
            const originalEnv = process.env;
            const originalCwd = process.cwd;

            beforeEach(() => {
                process.env = { ...originalEnv };
            });

            afterEach(() => {
                process.env = originalEnv;
                process.cwd = originalCwd;
            });

            it(`should use it when an eslint.config.js is present and useFlatConfig is true:${configType}`, async () => {
                process.cwd = getFixturePath;

                const exitCode = await cli.execute(`--no-ignore --ext .js ${getFixturePath("files")}`, null, useFlatConfig);

                // When flat config is used, we get an exit code of 2 because the --ext option is unrecognized.
                assert.strictEqual(exitCode, useFlatConfig ? 2 : 0);
            });

            it(`should not use it when ESLINT_USE_FLAT_CONFIG=false even if an eslint.config.js is present:${configType}`, async () => {
                process.env.ESLINT_USE_FLAT_CONFIG = "false";
                process.cwd = getFixturePath;

                const exitCode = await cli.execute(`--no-ignore --ext .js ${getFixturePath("files")}`, null, useFlatConfig);

                assert.strictEqual(exitCode, 0);
            });

            it(`should use it when ESLINT_USE_FLAT_CONFIG=true and useFlatConfig is true even if an eslint.config.js is not present:${configType}`, async () => {
                process.env.ESLINT_USE_FLAT_CONFIG = "true";