UNPKG

@wix/design-system

Version:

@wix/design-system

57 lines (53 loc) 2.29 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _nodeFetch = _interopRequireDefault(require("node-fetch")); var _unidriverCore = require("@wix/unidriver-core"); require("./jest-canvas-mock-shim"); require("jest-canvas-mock"); // Import order matters: the shim aliases `jest` -> `vi` on the global, which // jest-canvas-mock needs at module-evaluation time. vi.mock('../deprecationLog'); (0, _unidriverCore.configureUniDriver)({ defaultTimeout: 2500 }); // 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. var ICON_CONTENT_URL = '/wix-ui-icons-common/dist/icons/'; global.fetch = (url, init) => String(url).includes(ICON_CONTENT_URL) ? Promise.resolve({ ok: true, json: function () { var _json = (0, _asyncToGenerator2.default)(function* () { return { content: '' }; }); function json() { return _json.apply(this, arguments); } return json; }() }) : (0, _nodeFetch.default)(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 var originConsoleError = console.error; var 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 = function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var isSuppressed = args.some(arg => typeof arg === 'string' && suppressedWarnings.some(w => arg.includes(w))); if (!isSuppressed) { originConsoleError.apply(console, args); } }; //# sourceMappingURL=vitest-setup.js.map