UNPKG

@wix/design-system

Version:

@wix/design-system

40 lines 1.76 kB
import nodeFetch from 'node-fetch'; import { configureUniDriver } from '@wix/unidriver-core'; // Import order matters: the shim aliases `jest` -> `vi` on the global, which // jest-canvas-mock needs at module-evaluation time. import './jest-canvas-mock-shim'; import 'jest-canvas-mock'; vi.mock('../deprecationLog'); configureUniDriver({ defaultTimeout: 2_500, }); // Lazy icons (@wix/wix-ui-icons-common/lazy) suspend on a fetch of the icon's // JSON content. A real request can settle after the test file's jsdom // environment is torn down, so React commits into a dead environment and // vitest reports "ReferenceError: window is not defined" as an unhandled // error. Serve icon content locally so the suspense resolves within the test. const ICON_CONTENT_URL = '/wix-ui-icons-common/dist/icons/'; global.fetch = ((url, init) => String(url).includes(ICON_CONTENT_URL) ? Promise.resolve({ ok: true, json: async () => ({ content: '' }) }) : nodeFetch(url, init)); // @ts-expect-error node-fetch types differ from global fetch global.setImmediate = global.setTimeout; global.ResizeObserver = class { observe() { } unobserve() { } disconnect() { } }; // Suppress noisy React deprecation warnings in test output const originConsoleError = console.error; const suppressedWarnings = [ 'findDOMNode is deprecated', 'uses the legacy childContextTypes API which is no longer supported', 'uses the legacy contextTypes API which is no longer supported', ]; console.error = (...args) => { const isSuppressed = args.some(arg => typeof arg === 'string' && suppressedWarnings.some(w => arg.includes(w))); if (!isSuppressed) { originConsoleError.apply(console, args); } }; //# sourceMappingURL=vitest-setup.js.map