Repository: facebook/jest
File: packages/jest-config/src/readConfigFileAndSetRootDir.ts (TypeScript)

Code before:
  JEST_CONFIG_EXT_JSON,
  JEST_CONFIG_EXT_TS,
  PACKAGE_JSON,
} from './constants';

interface TsLoader {
  enabled: (bool: boolean) => void;
}
type TsLoaderModule = 'ts-node' | 'esbuild-register';
// Read the configuration and set its `rootDir`
// 1. If it's a `package.json` file, we look into its "jest" property
// 2. If it's a `jest.config.ts` file, we use `ts-node` to transpile & require it
// 3. For any other file, we just require it. If we receive an 'ERR_REQUIRE_ESM'
//    from node, perform a dynamic import instead.
export default async function readConfigFileAndSetRootDir(
  configPath: string,
): Promise<Config.InitialOptions> {
  const isTS =
    configPath.endsWith(JEST_CONFIG_EXT_TS) ||
    configPath.endsWith(JEST_CONFIG_EXT_CTS);
  const isJSON = configPath.endsWith(JEST_CONFIG_EXT_JSON);
  let configObject;

  try {
    if (isTS) {
      // @ts-expect-error: type assertion can be removed once @types/node is updated to 23 https://nodejs.org/api/process.html#processfeaturestypescript
      if (process.features.typescript) {
        try {
          // Try native node TypeScript support first.
          configObject = await requireOrImportModule<any>(configPath);
        } catch (error) {
          if (
            !(
              error instanceof SyntaxError &&
              // likely ESM in a file interpreted as CJS, which means it needs to be
              // transpiled - we ignore the error and try to load it with a loader
              error.message.match(/Unexpected token '(export|import)'/)
            )
          ) {
            throw error;
          }
        }
      }
      // Fall back to `ts-node` etc. if this cannot be natively parsed/executed.
      if (!configObject) {
        configObject = await loadTSConfigFile(configPath);
      }
    } else if (isJSON) {
      const fileContent = fs.readFileSync(configPath, 'utf8');
      configObject = parseJson(stripJsonComments(fileContent), configPath);
    } else {

Review comment (suggestion):
```suggestion
      // @ts-expect-error: Type assertion can be removed once @types/node is updated to 23 https://nodejs.org/api/process.html#processfeaturestypescript
```

Code after:
  JEST_CONFIG_EXT_JSON,
  JEST_CONFIG_EXT_TS,
  PACKAGE_JSON,
} from './constants';

interface TsLoader {
  enabled: (bool: boolean) => void;
}
type TsLoaderModule = 'ts-node' | 'esbuild-register';
// Read the configuration and set its `rootDir`
// 1. If it's a `package.json` file, we look into its "jest" property
// 2. If it's a `jest.config.ts` file, we use `ts-node` to transpile & require it
// 3. For any other file, we just require it. If we receive an 'ERR_REQUIRE_ESM'
//    from node, perform a dynamic import instead.
export default async function readConfigFileAndSetRootDir(
  configPath: string,
): Promise<Config.InitialOptions> {
  const isTS =
    configPath.endsWith(JEST_CONFIG_EXT_TS) ||
    configPath.endsWith(JEST_CONFIG_EXT_CTS);
  const isJSON = configPath.endsWith(JEST_CONFIG_EXT_JSON);
  let configObject;

  try {
    if (isTS) {
      // @ts-expect-error: Type assertion can be removed once @types/node is updated to 23 https://nodejs.org/api/process.html#processfeaturestypescript
      if (process.features.typescript) {
        try {
          // Try native node TypeScript support first.
          configObject = await requireOrImportModule<any>(configPath);
        } catch (error) {
          if (
            !(
              error instanceof SyntaxError &&
              // Likely ESM in a file interpreted as CJS, which means it needs to be
              // compiled. We ignore the error and try to load it with a loader.
              error.message.match(/Unexpected token '(export|import)'/)
            )
          ) {
            throw error;
          }
        }
      }
      // Fall back to `ts-node` etc. if this cannot be natively parsed/executed.
      if (!configObject) {
        configObject = await loadTSConfigFile(configPath);
      }
    } else if (isJSON) {
      const fileContent = fs.readFileSync(configPath, 'utf8');
      configObject = parseJson(stripJsonComments(fileContent), configPath);
    } else {