Skip to content

The open alternative to Salesforce, designed for AI.

1.9 KB
Raw Blame
import { Globals } from '@react-spring/web';
import { setProjectAnnotations } from '@storybook/react-vite';
import { MotionGlobalConfig } from 'framer-motion';
import * as projectAnnotations from './preview';
import { waitForServiceWorkerToControlPage } from './waitForServiceWorkerToControlPage';

MotionGlobalConfig.skipAnimations = true;
Globals.assign({ skipAnimation: true });

const disableCssAnimationsStyle = document.createElement('style');
disableCssAnimationsStyle.innerHTML = `*, *::before, *::after {
  animation-duration: 0s !important;
  animation-delay: 0s !important;
  transition-duration: 0s !important;
  transition-delay: 0s !important;
}`;
document.head.appendChild(disableCssAnimationsStyle);

// msw registers its service worker while ./preview evaluates, and it reloads
// any page that has a registration without being controlled by it, which
// vitest reports as "the iframe was reloaded during a test" and which fails
// the whole shard. Holding every file here until the worker controls its page
// (including files that run zero tests, which otherwise complete instantly)
// means no test iframe is ever created while the worker is still activating.
await waitForServiceWorkerToControlPage();

// Pre-warm the dynamic imports used by lazy() story components so the
// modules are cached before any test runs (avoids flaky timeouts and Argos
// screenshots that capture a Suspense skeleton instead of the loaded content).
await Promise.all([
  import('~/testing/utils/getTestEnrichedObjectMetadataItemsMock'),
  import('react-markdown'),
  import('remark-gfm'),
  import('@/activities/components/ActivityRichTextEditor'),
  import('@/object-record/record-field/ui/meta-types/input/components/RichTextFieldEditor'),
  import('@/navigation-menu-item/display/sections/favorites/components/FavoritesSectionDispatcher'),
  import('@/navigation-menu-item/display/sections/workspace/components/WorkspaceSectionDispatcher'),
]);

setProjectAnnotations([projectAnnotations]);