Repository: vercel/next.js
File: packages/next/src/build/jest/jest.ts (TypeScript)

Code before:
        setUpEnv(resolvedDir)
        // TODO: revisit when bug in SWC is fixed that strips `.css`
        const result = await loadJsConfig(resolvedDir, nextConfig)
        jsConfig = result.jsConfig
        resolvedBaseUrl = result.resolvedBaseUrl
      }
      // Ensure provided async config is supported
      const resolvedJestConfig =
        (typeof customJestConfig === 'function'
          ? await customJestConfig()
          : customJestConfig) ?? {}

      // eagerly load swc bindings instead of waiting for transform calls
      await installBindings(nextConfig?.experimental?.useWasmBinary)

      if (lockfilePatchPromise.cur) {
        await lockfilePatchPromise.cur
      }

      const transpiled = (nextConfig?.transpilePackages ?? [])
        .concat(DEFAULT_TRANSPILED_PACKAGES)
        // Include 'next' itself so that files inside node_modules/next/dist
        // are transformed by SWC. This allows optimizer.globals.envs to
        // perform compile-time replacement of process.env.__NEXT_IMAGE_OPTS
        // (mirroring webpack DefinePlugin behaviour in production builds).
        .concat(['next'])
        .join('|')

      // In production, webpack DefinePlugin replaces process.env.__NEXT_IMAGE_OPTS
      // with an object literal at compile time. Pass the same image config shape
      // to the SWC transformer so it performs the same compile-time replacement
      // during Jest transforms.
      const imageConfig = nextConfig?.images
        ? {
            deviceSizes: nextConfig.images.deviceSizes,
            imageSizes: nextConfig.images.imageSizes,
            qualities: nextConfig.images.qualities,
            path: nextConfig.images.path,
            loader: nextConfig.images.loader,
            dangerouslyAllowSVG: nextConfig.images.dangerouslyAllowSVG,
            unoptimized: nextConfig.images.unoptimized,
          }
        : undefined

      const jestTransformerConfig: JestTransformerConfig = {
        modularizeImports: nextConfig?.modularizeImports,
        swcPlugins: nextConfig?.experimental?.swcPlugins,
        compilerOptions: nextConfig?.compiler,
        jsConfig,
        resolvedBaseUrl,
        serverComponents,

Review comment (performance):
@vercel @ijjk Should we be worried about performance here when transpiling the entire `next` pkg? I wonder if we can be more specific and only transpile the one image component module.

Code after:
        setUpEnv(resolvedDir)
        // TODO: revisit when bug in SWC is fixed that strips `.css`
        const result = await loadJsConfig(resolvedDir, nextConfig)
        jsConfig = result.jsConfig
        resolvedBaseUrl = result.resolvedBaseUrl
      }
      // Ensure provided async config is supported
      const resolvedJestConfig =
        (typeof customJestConfig === 'function'
          ? await customJestConfig()
          : customJestConfig) ?? {}

      // eagerly load swc bindings instead of waiting for transform calls
      await installBindings(nextConfig?.experimental?.useWasmBinary)

      if (lockfilePatchPromise.cur) {
        await lockfilePatchPromise.cur
      }

      const imageConfig = nextConfig?.images
        ? {
            deviceSizes: nextConfig.images.deviceSizes,
            imageSizes: nextConfig.images.imageSizes,
            qualities: nextConfig.images.qualities,
            path: nextConfig.images.path,
            loader: nextConfig.images.loader,
            dangerouslyAllowSVG: nextConfig.images.dangerouslyAllowSVG,
            unoptimized: nextConfig.images.unoptimized,
          }
        : undefined

      const transpiled = (nextConfig?.transpilePackages ?? [])
        .concat(DEFAULT_TRANSPILED_PACKAGES)
        .concat(
          imageConfig
            ? [
                // Dist paths for normal package resolution.
                'next/dist/client',
                'next/dist/shared/lib',
                // Source paths can appear under pnpm file: installs.
                'next/src/client',
                'next/src/shared/lib',
              ]
            : []
        )
        .join('|')
      const transpiledPathRegex = transpiled.replace(/\//g, '[\\\\/]')

      const jestTransformerConfig: JestTransformerConfig = {
        modularizeImports: nextConfig?.modularizeImports,
        swcPlugins: nextConfig?.experimental?.swcPlugins,