Repository: strapi/strapi
File: packages/core/admin/admin/tests/utils.tsx (TypeScript)

Code before:
import { adminApi } from '../src/services/api';

import { server } from './server';
import { initialState } from './store';

setLogger({
  log: () => {},
  warn: () => {},
  error: () => {},
});

/**
 * React Router logs dev-only "Future Flag Warning" console.warn messages when
 * these are left undefined. Our test setup treats `console.warn` as a failure.
 *
 * We explicitly set them to `false` here to keep v6 behavior unchanged while
 * silencing warnings during tests.
 */
const REACT_ROUTER_FUTURE_FLAGS = {
  v7_startTransition: false,
  v7_relativeSplatPath: false,
  v7_fetcherPersist: false,
  v7_normalizeFormMethod: false,
  v7_partialHydration: false,
  v7_skipActionErrorRevalidation: false,
} as const;

interface ProvidersProps {
  children: React.ReactNode;
  initialEntries?: MemoryRouterProps['initialEntries'];
  storeConfig?: Partial<ConfigureStoreOptions>;
  permissions?: Permission[] | ((defaultPermissions: Permission[]) => Permission[] | undefined);
}

const defaultTestStoreConfig = () => ({
  preloadedState: initialState(),
  reducer: {
    [adminApi.reducerPath]: adminApi.reducer,
    admin_app: appReducer,
  },
  // @ts-expect-error – this fails.
  middleware: (getDefaultMiddleware) => [
    ...getDefaultMiddleware({
      // Disable timing checks for test env
      immutableCheck: false,
      serializableCheck: false,
    }),
    adminApi.middleware,
  ],
});


Review comment (suggestion):
I didn't change this in Strapi itself because the warnings are only when `node_env !== 'production'` but we may want to add a pass through config value for users to control this on their end

Code after:
import { adminApi } from '../src/services/api';

import { server } from './server';
import { initialState } from './store';

setLogger({
  log: () => {},
  warn: () => {},
  error: () => {},
});

/**
 * RTL's `rerender()` updates the `children` passed to our test `render()` helper.
 * However, we keep a stable `routerRef` to avoid recreating the data router (which
 * can crash React Router). That means the route element tree would otherwise keep
 * rendering the initial children forever.
 *
 * We solve this by passing `children` via React context, so consumers inside the
 * router element tree still update on rerenders without recreating the router.
 */
const TestChildrenContext = React.createContext<React.ReactNode>(null);

const TestChildrenOutlet = () => {
  return <>{React.useContext(TestChildrenContext)}</>;
};

interface ProvidersProps {
  children: React.ReactNode;
  initialEntries?: MemoryRouterProps['initialEntries'];
  storeConfig?: Partial<ConfigureStoreOptions>;
  permissions?: Permission[] | ((defaultPermissions: Permission[]) => Permission[] | undefined);
}

const defaultTestStoreConfig = () => ({
  preloadedState: initialState(),
  reducer: {
    [adminApi.reducerPath]: adminApi.reducer,
    admin_app: appReducer,
  },
  // @ts-expect-error – this fails.
  middleware: (getDefaultMiddleware) => [
    ...getDefaultMiddleware({
      // Disable timing checks for test env
      immutableCheck: false,
      serializableCheck: false,
    }),
    adminApi.middleware,
  ],
});

const DEFAULT_PERMISSIONS = [