dosubot[bot] commented on issue #29995: URL: https://github.com/apache/superset/issues/29995#issuecomment-2305312328
<!-- Greeting --> Hey @victorfonseca! I'm here to help you with any bugs, questions, or contributions you have for the Viz Plugin. Let's work through this together! <!-- Answer --> I found a similar closed issue that might help you resolve the problem: 1. **Custom Viz Plugin throwing error after executing yo @superset-ui/superset**: This issue was closed and the suggested solution was to change to `[email protected]` <sup>[[1]](https://github.com/apache/superset/issues/26135)</sup>. Additionally, the `window is not defined` error you're encountering is likely due to the tests being run in a Node.js environment where `window` is not available. To resolve this, you can mock the `window` object in your tests. Here is an example of how you can modify your test setup: ```tsx import { AriaAttributes } from 'react'; import 'core-js/stable'; import 'regenerator-runtime/runtime'; import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'; import 'jest-enzyme'; import jQuery from 'jquery'; import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import { configure as configureTranslation } from '../../packages/superset-ui-core/src/translation'; import { Worker } from './Worker'; import { IntersectionObserver } from './IntersectionObserver'; import { ResizeObserver } from './ResizeObserver'; import setupSupersetClient from './setupSupersetClient'; import CacheStorage from './CacheStorage'; configure({ adapter: new Adapter() }); const exposedProperties = ['window', 'navigator', 'document']; const { defaultView } = document; if (defaultView != null) { Object.keys(defaultView).forEach(property => { if (typeof global[property] === 'undefined') { exposedProperties.push(property); global[property] = defaultView[property]; } }); } const g = global as any; g.window ??= Object.create(window); g.window.location ??= { href: 'about:blank' }; g.window.performance ??= { now: () => new Date().getTime() }; g.window.Worker ??= Worker; g.window.IntersectionObserver ??= IntersectionObserver; g.window.ResizeObserver ??= ResizeObserver; g.window.featureFlags ??= {}; g.URL.createObjectURL ??= () => ''; g.caches = new CacheStorage(); Object.defineProperty(window, 'matchMedia', { writable: true, value: jest.fn().mockImplementation(query => ({ matches: false, media: query, onchange: null, addListener: jest.fn(), // Deprecated removeListener: jest.fn(), // Deprecated addEventListener: jest.fn(), removeEventListener: jest.fn(), dispatchEvent: jest.fn(), })), }); g.$ = jQuery(g.window); configureTranslation(); setupSupersetClient(); jest.mock('src/hooks/useTabId', () => ({ useTabId: () => 1, })); jest.mock('react-markdown', () => (props: any) => <>{props.children}</>); jest.mock('rehype-sanitize', () => () => jest.fn()); jest.mock('rehype-raw', () => () => jest.fn()); jest.mock('src/components/Icons/Icon', () => ({ __esModule: true, default: ({ fileName, role, 'aria-label': ariaLabel, ...rest }: { fileName: string; role: string; 'aria-label': AriaAttributes['aria-label']; }) => ( <span role={role ?? 'img'} aria-label={ariaLabel || fileName.replace('_', '-')} {...rest} /> ), StyledIcon: ({ role, 'aria-label': ariaLabel, ...rest }: { role: string; 'aria-label': AriaAttributes['aria-label']; }) => <span role={role ?? 'img'} aria-label={ariaLabel} {...rest} />, })); process.env.WEBPACK_MODE = 'test'; ``` This setup ensures that the `window` object and other necessary global objects are mocked during the tests, preventing the `window is not defined` error <sup>[[2]](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-core/test/utils/logging.test.ts)</sup><sup>[[3]](https://github.com/apache/superset/blob/master/superset-frontend/spec/helpers/shim.tsx)</sup>. For the deprecation warnings, consider updating your dependencies to their latest versions, particularly those that are flagged as deprecated. You can also switch to the "jsdom" test environment in your Jest configuration to resolve the `ReferenceError: window is not defined` errors <sup>[[4]](https://github.com/apache/superset/blob/master/superset-frontend/jest.config.js)</sup><sup>[[5]](https://github.com/apache/superset/blob/master/superset-frontend/packages/generator-superset/jest.config.js)</sup><sup>[[6]](https://github.com/apache/superset/blob/master/superset-websocket/jest.config.js)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
