@servicetitan/web-components 40.2.2 → 40.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/common.d.ts +22 -6
  2. package/dist/common.d.ts.map +1 -1
  3. package/dist/common.js +7 -2
  4. package/dist/common.js.map +1 -1
  5. package/dist/globals.d.ts +9 -7
  6. package/dist/globals.d.ts.map +1 -1
  7. package/dist/globals.js +17 -6
  8. package/dist/globals.js.map +1 -1
  9. package/dist/loader.d.ts.map +1 -1
  10. package/dist/loader.js +26 -24
  11. package/dist/loader.js.map +1 -1
  12. package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.d.ts +3 -0
  13. package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.d.ts.map +1 -0
  14. package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.js +12 -0
  15. package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.js.map +1 -0
  16. package/dist/patches/kendo-scrollbar-width/index.d.ts +3 -0
  17. package/dist/patches/kendo-scrollbar-width/index.d.ts.map +1 -0
  18. package/dist/patches/kendo-scrollbar-width/index.js +4 -0
  19. package/dist/patches/kendo-scrollbar-width/index.js.map +1 -0
  20. package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.d.ts +2 -0
  21. package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.d.ts.map +1 -0
  22. package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.js +26 -0
  23. package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.js.map +1 -0
  24. package/dist/register.d.ts.map +1 -1
  25. package/dist/register.js +30 -7
  26. package/dist/register.js.map +1 -1
  27. package/dist/use-host-shared-dependencies.d.ts +7 -0
  28. package/dist/use-host-shared-dependencies.d.ts.map +1 -0
  29. package/dist/use-host-shared-dependencies.js +17 -0
  30. package/dist/use-host-shared-dependencies.js.map +1 -0
  31. package/dist/use-prefetch.d.ts +2 -3
  32. package/dist/use-prefetch.d.ts.map +1 -1
  33. package/dist/use-prefetch.js +18 -12
  34. package/dist/use-prefetch.js.map +1 -1
  35. package/dist/utils/get-bundle-info.d.ts +7 -5
  36. package/dist/utils/get-bundle-info.d.ts.map +1 -1
  37. package/dist/utils/get-bundle-info.js +5 -3
  38. package/dist/utils/get-bundle-info.js.map +1 -1
  39. package/dist/utils/get-mfe-has-compatible-launchdarkly-version.d.ts +6 -6
  40. package/dist/utils/get-mfe-has-compatible-launchdarkly-version.d.ts.map +1 -1
  41. package/dist/utils/get-mfe-has-compatible-launchdarkly-version.js +7 -7
  42. package/dist/utils/get-mfe-has-compatible-launchdarkly-version.js.map +1 -1
  43. package/dist/utils/validate-bundle-info.d.ts +5 -5
  44. package/dist/utils/validate-bundle-info.d.ts.map +1 -1
  45. package/dist/utils/validate-bundle-info.js +6 -5
  46. package/dist/utils/validate-bundle-info.js.map +1 -1
  47. package/dist/utils/web-component.d.ts +4 -4
  48. package/dist/utils/web-component.d.ts.map +1 -1
  49. package/dist/utils/web-component.js +27 -11
  50. package/dist/utils/web-component.js.map +1 -1
  51. package/package.json +18 -14
  52. package/src/common.ts +27 -6
  53. package/src/globals.ts +26 -8
  54. package/src/loader.tsx +32 -36
  55. package/src/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.ts +11 -0
  56. package/src/patches/kendo-scrollbar-width/index.ts +2 -0
  57. package/src/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.ts +27 -0
  58. package/src/register.tsx +35 -8
  59. package/src/use-host-shared-dependencies.ts +26 -0
  60. package/src/use-prefetch.ts +38 -40
  61. package/src/utils/get-bundle-info.ts +11 -8
  62. package/src/utils/get-mfe-has-compatible-launchdarkly-version.ts +7 -7
  63. package/src/utils/validate-bundle-info.ts +9 -8
  64. package/src/utils/web-component.tsx +39 -16
  65. package/dist/contexts/tests/mfe-data-context.test.d.ts +0 -2
  66. package/dist/contexts/tests/mfe-data-context.test.d.ts.map +0 -1
  67. package/dist/contexts/tests/mfe-data-context.test.js +0 -60
  68. package/dist/contexts/tests/mfe-data-context.test.js.map +0 -1
  69. package/dist/contexts/tests/mfe-metadata-context.test.d.ts +0 -2
  70. package/dist/contexts/tests/mfe-metadata-context.test.d.ts.map +0 -1
  71. package/dist/contexts/tests/mfe-metadata-context.test.js +0 -41
  72. package/dist/contexts/tests/mfe-metadata-context.test.js.map +0 -1
  73. package/src/__mocks__/expect-styles-in-dom.ts +0 -11
  74. package/src/__mocks__/index.ts +0 -3
  75. package/src/__mocks__/register-anvil2-harness.tsx +0 -49
  76. package/src/__mocks__/register-component.tsx +0 -20
  77. package/src/__mocks__/test-component.tsx +0 -41
  78. package/src/__tests__/common.test.ts +0 -204
  79. package/src/__tests__/delayed.test.tsx +0 -49
  80. package/src/__tests__/event-bus-types.test.ts +0 -620
  81. package/src/__tests__/event-bus.test.ts +0 -240
  82. package/src/__tests__/get-value-for-environment.test.ts +0 -95
  83. package/src/__tests__/globals.test.ts +0 -16
  84. package/src/__tests__/headless-loader.test.tsx +0 -123
  85. package/src/__tests__/history-manager.test.ts +0 -111
  86. package/src/__tests__/loader.test.tsx +0 -1178
  87. package/src/__tests__/register-anvil2-optional.test.tsx +0 -32
  88. package/src/__tests__/register-anvil2.test.tsx +0 -80
  89. package/src/__tests__/register-headless.test.tsx +0 -97
  90. package/src/__tests__/register-legacy-root.test.tsx +0 -38
  91. package/src/__tests__/register.test.tsx +0 -247
  92. package/src/__tests__/use-prefetch.test.tsx +0 -235
  93. package/src/contexts/tests/mfe-data-context.test.tsx +0 -64
  94. package/src/contexts/tests/mfe-metadata-context.test.tsx +0 -34
  95. package/src/css-injector/__tests__/mfe-style-registry.test.ts +0 -163
  96. package/src/css-injector/__tests__/with-css-injector.test.tsx +0 -128
  97. package/src/utils/__tests__/get-cached-metadata.test.ts +0 -94
  98. package/src/utils/__tests__/get-mfe-has-compatible-launchdarkly-version.test.ts +0 -54
  99. package/src/utils/__tests__/get-mfe-supports-rerendering.test.ts +0 -99
  100. package/src/utils/__tests__/get-mfe-supports-versioned-ld-client.test.ts +0 -38
  101. package/src/utils/__tests__/is-versioned-url.test.ts +0 -18
  102. package/src/utils/__tests__/load-scripts.test.ts +0 -171
  103. package/src/utils/__tests__/supports-prefetch.test.ts +0 -27
  104. package/src/utils/__tests__/ttl-cache.test.ts +0 -98
@@ -1,55 +1,53 @@
1
1
  import { Log } from '@servicetitan/log-service';
2
2
  import { useOptionalDependencies } from '@servicetitan/react-ioc';
3
- import { EXPOSED_DEPENDENCIES_TOKEN, EXPOSED_INSTANCE_DEPENDENCIES_TOKEN } from './common';
3
+ import { useCallback, useMemo } from 'react';
4
4
  import { LoaderProps } from './loader';
5
+ import { useHostSharedDependencies } from './use-host-shared-dependencies';
5
6
  import { getBundleInfo, supportsPrefetch } from './utils';
6
7
 
7
8
  /**
8
- * Prefetch and cache bundle info for a given MFE, so that Loader can load it faster later.
9
- * @param src - The main package URL for the MFE
10
- * @returns Promise resolving to the BundleInfo
9
+ * Returns a stable `prefetch` function that prefetches and caches an MFE's bundle,
10
+ * so that Loader can load it faster later.
11
11
  */
12
12
  export function usePrefetch() {
13
- const [logService, exposedDependencies = EXPOSED_DEPENDENCIES] = useOptionalDependencies(
14
- Log,
15
- EXPOSED_DEPENDENCIES_TOKEN
16
- );
17
- const [exposedInstanceDependencies = EXPOSED_INSTANCE_DEPENDENCIES] = useOptionalDependencies(
18
- EXPOSED_INSTANCE_DEPENDENCIES_TOKEN
19
- );
20
- const prefetch = async (src: string, { cache = -1 }: Pick<LoaderProps<any>, 'cache'> = {}) => {
21
- try {
22
- const bundleInfo = await getBundleInfo({
23
- exposedDependencies,
24
- exposedInstanceDependencies,
25
- mainPackageUrl: src,
26
- cache,
27
- retries: 0,
28
- });
13
+ const [logService] = useOptionalDependencies(Log);
14
+ const [hostSharedDependencies, sharedInstanceDependencies] = useHostSharedDependencies();
15
+ const prefetch = useCallback(
16
+ async (src: string, { cache = -1 }: Pick<LoaderProps<any>, 'cache'> = {}) => {
17
+ try {
18
+ const bundleInfo = await getBundleInfo({
19
+ hostSharedDependencies,
20
+ sharedInstanceDependencies,
21
+ mainPackageUrl: src,
22
+ cache,
23
+ retries: 0,
24
+ });
29
25
 
30
- if (bundleInfo.cacheHit) {
31
- return;
32
- }
26
+ if (bundleInfo.cacheHit) {
27
+ return;
28
+ }
33
29
 
34
- const { css, js } = bundleInfo.urls;
35
- if (supportsPrefetch()) {
36
- addLinks([
37
- ...css.map(href => ({ href, as: 'style' })),
38
- ...js.map(href => ({ href, as: 'script' })),
39
- ]);
40
- } else {
41
- await Promise.all([...css, ...js].map(url => fetch(url, { priority: 'low' })));
30
+ const { css, js } = bundleInfo.urls;
31
+ if (supportsPrefetch()) {
32
+ addLinks([
33
+ ...css.map(href => ({ href, as: 'style' })),
34
+ ...js.map(href => ({ href, as: 'script' })),
35
+ ]);
36
+ } else {
37
+ await Promise.all([...css, ...js].map(url => fetch(url, { priority: 'low' })));
38
+ }
39
+ } catch (e: any) {
40
+ logService?.warning({
41
+ category: 'Microfrontends.Prefetch',
42
+ message: `Failed to prefetch ${src}`,
43
+ data: e,
44
+ });
42
45
  }
43
- } catch (e: any) {
44
- logService?.warning({
45
- category: 'Microfrontends.Prefetch',
46
- message: `Failed to prefetch ${src}`,
47
- data: e,
48
- });
49
- }
50
- };
46
+ },
47
+ [logService, hostSharedDependencies, sharedInstanceDependencies]
48
+ );
51
49
 
52
- return { prefetch };
50
+ return useMemo(() => ({ prefetch }), [prefetch]);
53
51
  }
54
52
 
55
53
  interface Link {
@@ -1,6 +1,7 @@
1
- import { ExposedDependencies, getVersionMismatches } from '@servicetitan/startup-utils';
1
+ import { getVersionMismatches, SharedDependencies } from '@servicetitan/startup-utils';
2
2
  import semver from 'semver';
3
- import { ExposedInstanceDependencies, getJson, GetJsonError } from '../common';
3
+ import { getJson, GetJsonError, SharedInstanceDependencies } from '../common';
4
+ import { getMFEMaybeUsesKendoGrid } from '../patches/kendo-scrollbar-width';
4
5
  import type { Metadata } from '../types';
5
6
  import { getCacheSetting } from './get-cache-setting';
6
7
  import { getCachedMetadata } from './get-cached-metadata';
@@ -14,8 +15,9 @@ export type BundleInfo = Awaited<ReturnType<typeof getBundleInfo>>;
14
15
 
15
16
  interface GetBundleInfoProps {
16
17
  cache: boolean | number;
17
- exposedDependencies?: ExposedDependencies;
18
- exposedInstanceDependencies?: ExposedInstanceDependencies;
18
+ /** The host's shared dependencies and their versions. */
19
+ hostSharedDependencies?: SharedDependencies;
20
+ sharedInstanceDependencies?: SharedInstanceDependencies;
19
21
  fallbackPackageUrl?: string;
20
22
  isHeadless?: boolean;
21
23
  mainPackageUrl: string;
@@ -27,8 +29,8 @@ export async function getBundleInfo({
27
29
  cache,
28
30
  mainPackageUrl,
29
31
  fallbackPackageUrl,
30
- exposedDependencies = {},
31
- exposedInstanceDependencies = {},
32
+ hostSharedDependencies = {},
33
+ sharedInstanceDependencies = {},
32
34
  isHeadless,
33
35
  retries,
34
36
  onRequestError,
@@ -67,7 +69,7 @@ export async function getBundleInfo({
67
69
  if (isHeadless) {
68
70
  resolvedBundleType = 'headless';
69
71
  } else {
70
- mismatch = getVersionMismatches(exposedDependencies, dependencies, sharedDependencies);
72
+ mismatch = getVersionMismatches(hostSharedDependencies, dependencies, sharedDependencies);
71
73
  const startupVersion = bundledWith?.['@servicetitan/startup'];
72
74
  const supportLightBundles = !!startupVersion && semver.gte(startupVersion, '17.0.0');
73
75
  const embed = !mismatch && supportLightBundles;
@@ -105,9 +107,10 @@ export async function getBundleInfo({
105
107
  mfeHasUniqueChunkNamespace: getMFEHasUniqueChunkNamespace(bundledWith),
106
108
  mfeHasCompatibleLaunchDarklyVersion: getMFEHasCompatibleLaunchDarklyVersion(
107
109
  bundledWith,
108
- exposedInstanceDependencies
110
+ sharedInstanceDependencies
109
111
  ),
110
112
  mfeSupportsVersionedLDClient: getMFESupportsVersionedLDClient(bundledWith),
113
+ mfeMaybeUsesKendoGrid: getMFEMaybeUsesKendoGrid(dependencies),
111
114
  mismatch,
112
115
  resolvedBundleType,
113
116
  urls,
@@ -1,19 +1,19 @@
1
- import { ExposedInstanceDependencies } from '../common';
1
+ import { SharedInstanceDependencies } from '../common';
2
2
  import type { Metadata } from '../types';
3
3
 
4
4
  /**
5
- * @param bundledWith THe MFE's metadata.bundledWith.
6
- * @param exposedInstanceDependencies The hosts's EXPOSED_INSTANCE_DEPENDENCIES, if any.
5
+ * @param bundledWith The MFE's metadata.bundledWith.
6
+ * @param sharedInstanceDependencies The host's SHARED_INSTANCE_DEPENDENCIES, if any.
7
7
  * @returns Returns true when host and MFE use compatible version of LaunchDarkly
8
- * and returns false when host and MGE use incompatible version.
9
- * Returns undefined when either the host or MFE doesn't expose LaunchDarkly.
8
+ * and returns false when host and MFE use incompatible version.
9
+ * Returns undefined when either the host or MFE doesn't share LaunchDarkly.
10
10
  */
11
11
  export function getMFEHasCompatibleLaunchDarklyVersion(
12
12
  bundledWith: Metadata['bundledWith'],
13
- exposedInstanceDependencies: ExposedInstanceDependencies
13
+ sharedInstanceDependencies: SharedInstanceDependencies
14
14
  ) {
15
15
  const mfeVersion = bundledWith?.['launchdarkly-js-client-sdk'];
16
- const hostVersion = exposedInstanceDependencies.launchDarkly?.version;
16
+ const hostVersion = sharedInstanceDependencies.launchDarkly?.version;
17
17
  if (hostVersion && mfeVersion) {
18
18
  return hostVersion === mfeVersion;
19
19
  }
@@ -1,17 +1,17 @@
1
1
  import { Log } from '@servicetitan/log-service';
2
- import { ExposedDependencies } from '@servicetitan/startup-utils';
3
- import { ExposedInstanceDependencies } from '../common';
2
+ import { SharedDependencies } from '@servicetitan/startup-utils';
3
+ import { SharedInstanceDependencies } from '../common';
4
4
  import { BundleInfo } from './get-bundle-info';
5
5
 
6
6
  interface Context {
7
- exposedDependencies?: ExposedDependencies;
8
- exposedInstanceDependencies?: ExposedInstanceDependencies;
7
+ hostSharedDependencies?: SharedDependencies;
8
+ sharedInstanceDependencies?: SharedInstanceDependencies;
9
9
  logService?: Log;
10
10
  packageUrl: string;
11
11
  }
12
12
  export function validateBundleInfo(
13
13
  { mismatch, mfeHasCompatibleLaunchDarklyVersion }: BundleInfo,
14
- { exposedDependencies = {}, exposedInstanceDependencies, logService, packageUrl }: Context
14
+ { hostSharedDependencies = {}, sharedInstanceDependencies, logService, packageUrl }: Context
15
15
  ) {
16
16
  if (!logService) {
17
17
  return;
@@ -19,11 +19,12 @@ export function validateBundleInfo(
19
19
 
20
20
  if (mismatch) {
21
21
  const data = { package: packageUrl, dependencies: JSON.stringify(mismatch) };
22
- if (Object.keys(exposedDependencies).length === 0) {
22
+ if (Object.keys(hostSharedDependencies).length === 0) {
23
23
  logService.warning({
24
+ // Legacy category name kept so existing log monitors keep matching
24
25
  category: 'MicroFrontends.NoExposedDependencies',
25
26
  message:
26
- 'Cannot use light bundle because the host is not exposing dependencies or the list of shared dependencies is empty.',
27
+ 'Cannot use light bundle because the host is not providing shared dependencies or the list of shared dependencies is empty.',
27
28
  data,
28
29
  });
29
30
  } else {
@@ -43,7 +44,7 @@ export function validateBundleInfo(
43
44
  if (mfeHasCompatibleLaunchDarklyVersion === false) {
44
45
  const data = {
45
46
  package: packageUrl,
46
- hostVersion: exposedInstanceDependencies?.launchDarkly?.version ?? '',
47
+ hostVersion: sharedInstanceDependencies?.launchDarkly?.version ?? '',
47
48
  };
48
49
  logService.warning({
49
50
  category: 'MicroFrontends.LaunchDarklyMismatch',
@@ -1,13 +1,14 @@
1
1
  import { type LDService } from '@servicetitan/launchdarkly-service';
2
2
  import { Log } from '@servicetitan/log-service';
3
3
  import { useOptionalDependencies } from '@servicetitan/react-ioc';
4
- import { ExposedDependencies } from '@servicetitan/startup-utils';
5
- import { Fragment, useMemo, useState } from 'react';
6
- import { ExposedInstanceDependencies, IWebComponent } from '../common';
4
+ import { SharedDependencies } from '@servicetitan/startup-utils';
5
+ import { Fragment, useLayoutEffect, useMemo, useRef, useState } from 'react';
6
+ import { IWebComponent, SharedInstanceDependencies } from '../common';
7
7
  import { MFEContextData } from '../contexts/mfe-data-context';
8
8
  import { EventBus } from '../event-bus';
9
9
  import { HistoryManager } from '../history-manager';
10
10
  import { LoaderDataProps } from '../loader';
11
+ import { setKendoScrollbarWidth } from '../patches/kendo-scrollbar-width';
11
12
  import { BundleInfo } from './get-bundle-info';
12
13
  import { getElementName } from './get-element-name';
13
14
 
@@ -15,33 +16,47 @@ interface WebComponentProps {
15
16
  basename?: string;
16
17
  bundleInfo: BundleInfo;
17
18
  eventBus: EventBus;
18
- exposedDependencies?: ExposedDependencies;
19
- exposedInstanceDependencies?: ExposedInstanceDependencies;
19
+ hostSharedDependencies?: SharedDependencies;
20
+ sharedInstanceDependencies?: SharedInstanceDependencies;
20
21
  ldService?: LDService;
21
22
  logService?: Log;
22
23
  }
23
24
 
24
25
  export function webComponent(props: WebComponentProps) {
25
- const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;
26
- const { WebComponent, resolvedBundleType, mfeSupportsRerendering, version } = bundleInfo;
26
+ const { basename, bundleInfo, eventBus, hostSharedDependencies, ldService, logService } = props;
27
+ const {
28
+ WebComponent,
29
+ resolvedBundleType,
30
+ mfeSupportsRerendering,
31
+ mfeMaybeUsesKendoGrid,
32
+ version,
33
+ } = bundleInfo;
27
34
  const elementName = getElementName(bundleInfo);
28
35
 
29
- const exposedInstanceDependencies = ensureLDVersion(
30
- props.exposedInstanceDependencies,
36
+ const sharedInstanceDependencies = ensureLDVersion(
37
+ props.sharedInstanceDependencies,
31
38
  bundleInfo.bundledWith?.['launchdarkly-js-client-sdk']
32
39
  );
33
40
 
34
41
  return ({ LoadingFallback, ...innerProps }: LoaderDataProps) => {
35
42
  const [isLoading, setIsLoading] = useState(true);
36
43
  const [historyManager] = useOptionalDependencies(HistoryManager);
44
+ const elementRef = useRef<(IWebComponent & HTMLElement) | null>(null);
37
45
 
38
- const handleRef = (webComponent: IWebComponent | null) => {
46
+ const handleRef = (webComponent: (IWebComponent & HTMLElement) | null) => {
47
+ elementRef.current = webComponent;
39
48
  webComponent?.provide({
40
49
  ldService,
41
50
  logService,
42
51
  historyManager,
43
- exposedDependencies,
44
- exposedInstanceDependencies,
52
+ sharedDependencies: hostSharedDependencies,
53
+ sharedInstanceDependencies,
54
+ /*
55
+ * Continue to pass the deprecated names for backwards compatibility,
56
+ * in case the Host has updated web-components, but the MFE has not
57
+ */
58
+ exposedDependencies: hostSharedDependencies,
59
+ exposedInstanceDependencies: sharedInstanceDependencies,
45
60
  eventBus,
46
61
  basename,
47
62
  onReady: () => {
@@ -60,6 +75,14 @@ export function webComponent(props: WebComponentProps) {
60
75
  * This is only used as a fallback when the MFE's version is older.
61
76
  */
62
77
  const key = mfeSupportsRerendering ? undefined : stringifiedData;
78
+
79
+ // Measure after the element is visible, since a hidden element has no scrollbar.
80
+ useLayoutEffect(() => {
81
+ if (mfeMaybeUsesKendoGrid && !isLoading && elementRef.current) {
82
+ setKendoScrollbarWidth(elementRef.current, elementName);
83
+ }
84
+ }, [isLoading]);
85
+
63
86
  const dataAttrs = useMemo(() => composeDataAttributes(innerProps.data), [innerProps.data]);
64
87
  const styleUrls = getStyleUrls(bundleInfo);
65
88
 
@@ -105,13 +128,13 @@ function composeDataAttributes(data: MFEContextData<{}> | undefined = {}) {
105
128
  }
106
129
 
107
130
  function ensureLDVersion(
108
- exposedInstanceDependencies: ExposedInstanceDependencies = {},
131
+ sharedInstanceDependencies: SharedInstanceDependencies = {},
109
132
  version?: string
110
133
  ) {
111
- if (version && !exposedInstanceDependencies.launchDarkly?.ldService) {
112
- return { ...exposedInstanceDependencies, launchDarkly: { version } };
134
+ if (version && !sharedInstanceDependencies.launchDarkly?.ldService) {
135
+ return { ...sharedInstanceDependencies, launchDarkly: { version } };
113
136
  }
114
- return exposedInstanceDependencies;
137
+ return sharedInstanceDependencies;
115
138
  }
116
139
 
117
140
  function getStyleUrls({ urls }: Pick<BundleInfo, 'urls'>) {
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=mfe-data-context.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mfe-data-context.test.d.ts","sourceRoot":"","sources":["../../../src/contexts/tests/mfe-data-context.test.tsx"],"names":[],"mappings":""}
@@ -1,60 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { renderHook } from '@testing-library/react';
3
- import { MFEDataContext, useMFEDataContext } from '../mfe-data-context';
4
- describe(`[web-components] ${useMFEDataContext.name}`, ()=>{
5
- const subject = (wrapper)=>renderHook(()=>useMFEDataContext(), {
6
- wrapper
7
- });
8
- describe('when the MFEDataContext is provided by a parent', ()=>{
9
- const data = {
10
- foo: 'bar'
11
- };
12
- const Wrapper = ({ children })=>{
13
- return /*#__PURE__*/ _jsx(MFEDataContext.Provider, {
14
- value: data,
15
- children: children
16
- });
17
- };
18
- test('returns the context', ()=>{
19
- expect(subject(Wrapper).result.current).toEqual(data);
20
- });
21
- });
22
- describe('when the MFEDataContext is not provided by a parent', ()=>{
23
- const Wrapper = ({ children })=>{
24
- return /*#__PURE__*/ _jsx("div", {
25
- children: children
26
- });
27
- };
28
- test('returns an empty object', ()=>{
29
- expect(subject(Wrapper).result.current).toEqual({});
30
- });
31
- });
32
- describe('type definitions', ()=>{
33
- test('accepts properties typed as JSON', ()=>{
34
- renderHook(()=>useMFEDataContext());
35
- });
36
- test('accepts properties typed as Record<string, JSON>', ()=>{
37
- renderHook(()=>useMFEDataContext());
38
- });
39
- test('accepts primitive properties', ()=>{
40
- renderHook(()=>useMFEDataContext());
41
- });
42
- test('accepts nested objects and arrays', ()=>{
43
- renderHook(()=>useMFEDataContext());
44
- });
45
- test('rejects non-serializable properties', ()=>{
46
- // @ts-expect-error Type '() => void' is not assignable to type 'never'.
47
- renderHook(()=>useMFEDataContext());
48
- // @ts-expect-error Type 'Date' is not assignable to type 'never'.
49
- renderHook(()=>useMFEDataContext());
50
- // @ts-expect-error Type 'Map<string, any>' is not assignable to type 'never'.
51
- renderHook(()=>useMFEDataContext());
52
- // @ts-expect-error Type 'Set<string>' is not assignable to type 'never'.
53
- renderHook(()=>useMFEDataContext());
54
- // @ts-expect-error Type 'symbol' is not assignable to type 'never'.
55
- renderHook(()=>useMFEDataContext());
56
- });
57
- });
58
- });
59
-
60
- //# sourceMappingURL=mfe-data-context.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/contexts/tests/mfe-data-context.test.tsx"],"sourcesContent":["import { renderHook } from '@testing-library/react';\nimport { FC, PropsWithChildren } from 'react';\nimport { JSON } from '../../types';\nimport { MFEDataContext, useMFEDataContext } from '../mfe-data-context';\n\ndescribe(`[web-components] ${useMFEDataContext.name}`, () => {\n const subject = (wrapper?: FC) => renderHook(() => useMFEDataContext(), { wrapper });\n\n describe('when the MFEDataContext is provided by a parent', () => {\n const data = { foo: 'bar' };\n const Wrapper: FC<PropsWithChildren> = ({ children }) => {\n return <MFEDataContext.Provider value={data}>{children}</MFEDataContext.Provider>;\n };\n\n test('returns the context', () => {\n expect(subject(Wrapper).result.current).toEqual(data);\n });\n });\n\n describe('when the MFEDataContext is not provided by a parent', () => {\n const Wrapper: FC<PropsWithChildren> = ({ children }) => {\n return <div>{children}</div>;\n };\n\n test('returns an empty object', () => {\n expect(subject(Wrapper).result.current).toEqual({});\n });\n });\n\n describe('type definitions', () => {\n test('accepts properties typed as JSON', () => {\n renderHook(() => useMFEDataContext<{ data: JSON }>());\n });\n\n test('accepts properties typed as Record<string, JSON>', () => {\n renderHook(() => useMFEDataContext<{ metadata: Record<string, JSON> }>());\n });\n\n test('accepts primitive properties', () => {\n renderHook(() => useMFEDataContext<{ name: string; count: number; active: boolean }>());\n });\n\n test('accepts nested objects and arrays', () => {\n renderHook(() => useMFEDataContext<{ nested: { value: number }; list: string[] }>());\n });\n\n test('rejects non-serializable properties', () => {\n // @ts-expect-error Type '() => void' is not assignable to type 'never'.\n renderHook(() => useMFEDataContext<{ callback: () => void }>());\n\n // @ts-expect-error Type 'Date' is not assignable to type 'never'.\n renderHook(() => useMFEDataContext<{ created: Date }>());\n\n // @ts-expect-error Type 'Map<string, any>' is not assignable to type 'never'.\n renderHook(() => useMFEDataContext<{ lookup: Map<string, any> }>());\n\n // @ts-expect-error Type 'Set<string>' is not assignable to type 'never'.\n renderHook(() => useMFEDataContext<{ tags: Set<string> }>());\n\n // @ts-expect-error Type 'symbol' is not assignable to type 'never'.\n renderHook(() => useMFEDataContext<{ id: symbol }>());\n });\n });\n});\n"],"names":["renderHook","MFEDataContext","useMFEDataContext","describe","name","subject","wrapper","data","foo","Wrapper","children","Provider","value","test","expect","result","current","toEqual","div"],"mappings":";AAAA,SAASA,UAAU,QAAQ,yBAAyB;AAGpD,SAASC,cAAc,EAAEC,iBAAiB,QAAQ,sBAAsB;AAExEC,SAAS,CAAC,iBAAiB,EAAED,kBAAkBE,IAAI,EAAE,EAAE;IACnD,MAAMC,UAAU,CAACC,UAAiBN,WAAW,IAAME,qBAAqB;YAAEI;QAAQ;IAElFH,SAAS,mDAAmD;QACxD,MAAMI,OAAO;YAAEC,KAAK;QAAM;QAC1B,MAAMC,UAAiC,CAAC,EAAEC,QAAQ,EAAE;YAChD,qBAAO,KAACT,eAAeU,QAAQ;gBAACC,OAAOL;0BAAOG;;QAClD;QAEAG,KAAK,uBAAuB;YACxBC,OAAOT,QAAQI,SAASM,MAAM,CAACC,OAAO,EAAEC,OAAO,CAACV;QACpD;IACJ;IAEAJ,SAAS,uDAAuD;QAC5D,MAAMM,UAAiC,CAAC,EAAEC,QAAQ,EAAE;YAChD,qBAAO,KAACQ;0BAAKR;;QACjB;QAEAG,KAAK,2BAA2B;YAC5BC,OAAOT,QAAQI,SAASM,MAAM,CAACC,OAAO,EAAEC,OAAO,CAAC,CAAC;QACrD;IACJ;IAEAd,SAAS,oBAAoB;QACzBU,KAAK,oCAAoC;YACrCb,WAAW,IAAME;QACrB;QAEAW,KAAK,oDAAoD;YACrDb,WAAW,IAAME;QACrB;QAEAW,KAAK,gCAAgC;YACjCb,WAAW,IAAME;QACrB;QAEAW,KAAK,qCAAqC;YACtCb,WAAW,IAAME;QACrB;QAEAW,KAAK,uCAAuC;YACxC,wEAAwE;YACxEb,WAAW,IAAME;YAEjB,kEAAkE;YAClEF,WAAW,IAAME;YAEjB,8EAA8E;YAC9EF,WAAW,IAAME;YAEjB,yEAAyE;YACzEF,WAAW,IAAME;YAEjB,oEAAoE;YACpEF,WAAW,IAAME;QACrB;IACJ;AACJ"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=mfe-metadata-context.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mfe-metadata-context.test.d.ts","sourceRoot":"","sources":["../../../src/contexts/tests/mfe-metadata-context.test.tsx"],"names":[],"mappings":""}
@@ -1,41 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { renderHook } from '@testing-library/react';
3
- import { MFEMetadataContext, useMFEMetadataContext } from '../mfe-metadata-context';
4
- describe(`[web-components] ${useMFEMetadataContext.name}`, ()=>{
5
- const subject = (wrapper)=>renderHook(()=>useMFEMetadataContext(), {
6
- wrapper
7
- });
8
- describe('when the MFEMetadataContext is provided by a parent', ()=>{
9
- const shadowRoot = document.createElement('div').attachShadow({
10
- mode: 'open'
11
- });
12
- const portalShadowRoot = document.createElement('span').attachShadow({
13
- mode: 'open'
14
- });
15
- const metadata = {
16
- shadowRoot,
17
- portalShadowRoot
18
- };
19
- const Wrapper = ({ children })=>{
20
- return /*#__PURE__*/ _jsx(MFEMetadataContext.Provider, {
21
- value: metadata,
22
- children: children
23
- });
24
- };
25
- test('returns the context', ()=>{
26
- expect(subject(Wrapper).result.current).toEqual(metadata);
27
- });
28
- });
29
- describe('when the MFEMetadataContext is not provided by a parent', ()=>{
30
- const Wrapper = ({ children })=>{
31
- return /*#__PURE__*/ _jsx("div", {
32
- children: children
33
- });
34
- };
35
- test('returns an empty object', ()=>{
36
- expect(subject(Wrapper).result.current).toEqual({});
37
- });
38
- });
39
- });
40
-
41
- //# sourceMappingURL=mfe-metadata-context.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/contexts/tests/mfe-metadata-context.test.tsx"],"sourcesContent":["import { renderHook } from '@testing-library/react';\nimport { FC, PropsWithChildren } from 'react';\nimport { MFEMetadataContext, useMFEMetadataContext } from '../mfe-metadata-context';\n\ndescribe(`[web-components] ${useMFEMetadataContext.name}`, () => {\n const subject = (wrapper?: FC) => renderHook(() => useMFEMetadataContext(), { wrapper });\n\n describe('when the MFEMetadataContext is provided by a parent', () => {\n const shadowRoot = document.createElement('div').attachShadow({ mode: 'open' });\n const portalShadowRoot = document.createElement('span').attachShadow({ mode: 'open' });\n const metadata = { shadowRoot, portalShadowRoot };\n const Wrapper: FC<PropsWithChildren> = ({ children }) => {\n return (\n <MFEMetadataContext.Provider value={metadata}>\n {children}\n </MFEMetadataContext.Provider>\n );\n };\n\n test('returns the context', () => {\n expect(subject(Wrapper).result.current).toEqual(metadata);\n });\n });\n\n describe('when the MFEMetadataContext is not provided by a parent', () => {\n const Wrapper: FC<PropsWithChildren> = ({ children }) => {\n return <div>{children}</div>;\n };\n\n test('returns an empty object', () => {\n expect(subject(Wrapper).result.current).toEqual({});\n });\n });\n});\n"],"names":["renderHook","MFEMetadataContext","useMFEMetadataContext","describe","name","subject","wrapper","shadowRoot","document","createElement","attachShadow","mode","portalShadowRoot","metadata","Wrapper","children","Provider","value","test","expect","result","current","toEqual","div"],"mappings":";AAAA,SAASA,UAAU,QAAQ,yBAAyB;AAEpD,SAASC,kBAAkB,EAAEC,qBAAqB,QAAQ,0BAA0B;AAEpFC,SAAS,CAAC,iBAAiB,EAAED,sBAAsBE,IAAI,EAAE,EAAE;IACvD,MAAMC,UAAU,CAACC,UAAiBN,WAAW,IAAME,yBAAyB;YAAEI;QAAQ;IAEtFH,SAAS,uDAAuD;QAC5D,MAAMI,aAAaC,SAASC,aAAa,CAAC,OAAOC,YAAY,CAAC;YAAEC,MAAM;QAAO;QAC7E,MAAMC,mBAAmBJ,SAASC,aAAa,CAAC,QAAQC,YAAY,CAAC;YAAEC,MAAM;QAAO;QACpF,MAAME,WAAW;YAAEN;YAAYK;QAAiB;QAChD,MAAME,UAAiC,CAAC,EAAEC,QAAQ,EAAE;YAChD,qBACI,KAACd,mBAAmBe,QAAQ;gBAACC,OAAOJ;0BAC/BE;;QAGb;QAEAG,KAAK,uBAAuB;YACxBC,OAAOd,QAAQS,SAASM,MAAM,CAACC,OAAO,EAAEC,OAAO,CAACT;QACpD;IACJ;IAEAV,SAAS,2DAA2D;QAChE,MAAMW,UAAiC,CAAC,EAAEC,QAAQ,EAAE;YAChD,qBAAO,KAACQ;0BAAKR;;QACjB;QAEAG,KAAK,2BAA2B;YAC5BC,OAAOd,QAAQS,SAASM,MAAM,CAACC,OAAO,EAAEC,OAAO,CAAC,CAAC;QACrD;IACJ;AACJ"}
@@ -1,11 +0,0 @@
1
- import '@testing-library/jest-dom';
2
-
3
- export function expectStylesInDom(styleUrls: string | string[], shadowRootFn: () => ShadowRoot) {
4
- [styleUrls].flat().forEach(styleUrl => {
5
- const link = shadowRootFn().querySelector(
6
- `link[href='${styleUrl}'][rel='stylesheet'][crossorigin='anonymous']`
7
- );
8
- expect(link).toBeInTheDocument();
9
- });
10
- expect(shadowRootFn().querySelectorAll('link').length).toBe([styleUrls].flat().length);
11
- }
@@ -1,3 +0,0 @@
1
- export * from './expect-styles-in-dom';
2
- export * from './register-component';
3
- export * from './test-component';
@@ -1,49 +0,0 @@
1
- import { render } from '@testing-library/react';
2
- import { MockComponent, registerComponent } from './index';
3
-
4
- /* Wrapper components injected by each optional library. */
5
- export const optionalLibraryWrappers: Record<string, string[]> = {
6
- '@servicetitan/anvil2': ['PortalProvider'],
7
- '@servicetitan/design-system': [
8
- 'DefaultPortalContext.Provider',
9
- 'TablePopupPropsContext.Provider',
10
- ],
11
- };
12
-
13
- export interface RegisterHarness {
14
- Page: {
15
- readonly componentShadowRoot: ShadowRoot;
16
- readonly portalShadowRoot: ShadowRoot;
17
- };
18
- subject: () => ReturnType<typeof render>;
19
- }
20
-
21
- export function createRegisterHarness(
22
- componentName: string,
23
- options?: Parameters<typeof registerComponent>[2]
24
- ): RegisterHarness {
25
- const Page = {
26
- get componentShadowRoot() {
27
- return document.querySelector(componentName)!.shadowRoot!;
28
- },
29
- get portalShadowRoot() {
30
- return document.querySelector('body')!.lastElementChild!.shadowRoot!;
31
- },
32
- };
33
-
34
- beforeAll(() => {
35
- registerComponent(MockComponent, componentName, {
36
- sharedDependenciesNames: ['@servicetitan/anvil2'],
37
- ...options,
38
- });
39
- });
40
-
41
- const subject = () => {
42
- jest.spyOn(console, 'error').mockImplementation(jest.fn()); // suppress "ReactDOM.render deprecated" error
43
- const Component: any = componentName;
44
- const handleRef = (wc: any) => wc?.provide({ foo: 'bar' }); // triggers rendering
45
- return render(<Component ref={handleRef} />);
46
- };
47
-
48
- return { Page, subject };
49
- }
@@ -1,20 +0,0 @@
1
- import { FunctionComponent } from 'react';
2
- import { RegisterOptions } from '../register';
3
-
4
- export function registerComponent(
5
- TestComponent: FunctionComponent,
6
- componentName: string | undefined,
7
- options?: RegisterOptions
8
- ) {
9
- /*
10
- * This register can only happen once, unfortunately. So the TestComponent needs to
11
- * work for all tests. If ran more than once, window.customElements.define will throw
12
- * the error: "NotSupportedError: This name has already been registered in the registry."
13
- *
14
- * Also note that there is not way to "unregister" a web component, so an afterAll
15
- * cannot be used.
16
- */
17
- (global as any).WEB_COMPONENT_NAME = componentName;
18
- const { register } = require('../register');
19
- register(TestComponent, true, options);
20
- }
@@ -1,41 +0,0 @@
1
- import { TablePopupPropsContext } from '@servicetitan/design-system';
2
- import { createContext, FC, useContext } from 'react';
3
- import { useMFEDataContext, useMFEMetadataContext } from '../contexts';
4
-
5
- jest.mock('@progress/kendo-licensing', () => ({ validatePackage: jest.fn() }));
6
-
7
- const FallbackContext = createContext(undefined);
8
-
9
- export const MockComponent: FC<Record<string, any>> = props => {
10
- const data = useMFEDataContext();
11
- const metadata = useMFEMetadataContext();
12
- /*
13
- * TablePopupPropsContext is undefined when a test mocks
14
- * @servicetitan/design-system as an empty object. Fall back to
15
- * a no-op context so the component renders without it.
16
- */
17
- const popupProps = useContext(TablePopupPropsContext ?? FallbackContext);
18
- const appendTo = popupProps?.({}).appendTo;
19
-
20
- return (
21
- <div>
22
- {Object.entries(props).map(([name, value]) => (
23
- <span key={name}>{`Prop: ${name}, Value: ${stringifyValue(value)}`}</span>
24
- ))}
25
- {Object.entries(data).map(([name, value]) => (
26
- <span key={name}>{`Data: ${name}, Value: ${stringifyValue(value)}`}</span>
27
- ))}
28
- {Object.entries(metadata).map(([name, value]) => (
29
- <span key={name}>{`Metadata: ${name}, Value: ${stringifyValue(value)}`}</span>
30
- ))}
31
- {/* eslint-disable-next-line @typescript-eslint/no-base-to-string */}
32
- <span>TablePopupPropsContext appendTo: {String(appendTo)}</span>
33
- </div>
34
- );
35
- };
36
-
37
- function stringifyValue(value: any) {
38
- return JSON.stringify(value, (_key, value) =>
39
- value instanceof ShadowRoot ? 'ShadowRoot' : value
40
- );
41
- }