import { LD_SERVICE_TOKEN } from '@servicetitan/launchdarkly-service'; import { Log } from '@servicetitan/log-service'; import { Provider, ProviderProps } from '@servicetitan/react-ioc'; import { ExposedDependencies, getVersionMismatches } from '@servicetitan/startup-utils'; import '@testing-library/jest-dom'; import { act, render, screen, waitFor } from '@testing-library/react'; import { FC, ReactNode, RefObject, useEffect, useRef } from 'react'; import * as common from '../common'; import { EXPOSED_DEPENDENCIES_TOKEN, EXPOSED_INSTANCE_DEPENDENCIES_TOKEN, Entries, ExposedInstanceDependencies, } from '../common'; import { EVENT_BUS_TOKEN } from '../event-bus'; import { HistoryManager } from '../history-manager'; import { Loader, LoaderProps, UnrestrictedLoaderProps } from '../loader'; import { Metadata } from '../types'; import { getMFEHasCompatibleLaunchDarklyVersion } from '../utils/get-mfe-has-compatible-launchdarkly-version'; import { getMFEHasUniqueChunkNamespace } from '../utils/get-mfe-has-unique-chunk-namespace'; import { getMFESupportsVersionedLDClient } from '../utils/get-mfe-supports-versioned-ld-client'; jest.mock('@servicetitan/startup-utils', () => ({ getVersionMismatches: jest.fn(), })); jest.mock('../utils/get-mfe-has-compatible-launchdarkly-version'); jest.mock('../utils/get-mfe-has-unique-chunk-namespace'); jest.mock('../utils/get-mfe-supports-versioned-ld-client'); describe('[web-components] Loader', () => { const localHosts = ['localhost', '127.0.0.1']; const baseUrl = 'http://unpkg.servicetitan.com/mfe'; const baseName = 'mfe-component'; const WEB_COMPONENT_NAME = `${baseName}-abc123`; let webComponentState: Partial; let webComponent: WebComponent | undefined; class WebComponent extends HTMLElement { provide = (entries: Entries) => { // eslint-disable-next-line @typescript-eslint/no-this-alias webComponent = this; for (const [key, value] of Object.entries(entries)) { /* * set values to external state so that we can call or * check any of the values in the test */ webComponentState[key as keyof Entries] = value; } }; } let props: LoaderProps; let onloadRef: Function | null; let onerrorRef: Function | null; let singletons: ProviderProps['singletons']; let getJsonMockFns: Record; let metadata: Metadata; function setStartupVersion(version: string | undefined) { metadata.bundledWith = version ? { '@servicetitan/startup': version } : undefined; } beforeAll(() => { // register web component in order to test the `provide` method window.customElements.define(WEB_COMPONENT_NAME, WebComponent); /* * mock