@trackunit/react-test-setup 1.0.19-alpha-169add733bd.0 → 1.0.19

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.
package/index.cjs.js CHANGED
@@ -4,34 +4,10 @@ var failOnConsole = require('jest-fail-on-console');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var reactGoogleMaps = require('@vis.gl/react-google-maps');
6
6
  var jestMocks = require('@googlemaps/jest-mocks');
7
- require('@okta/okta-react');
8
7
  require('@testing-library/jest-dom');
9
8
  var react = require('@testing-library/react');
10
9
  var polyfill = require('@js-temporal/polyfill');
11
10
  var web = require('@react-spring/web');
12
- var util = require('util');
13
- var react$1 = require('react');
14
- var reactI18next = require('react-i18next');
15
- var webStreamsPolyfill = require('web-streams-polyfill');
16
-
17
- function _interopNamespaceDefault(e) {
18
- var n = Object.create(null);
19
- if (e) {
20
- Object.keys(e).forEach(function (k) {
21
- if (k !== 'default') {
22
- var d = Object.getOwnPropertyDescriptor(e, k);
23
- Object.defineProperty(n, k, d.get ? d : {
24
- enumerable: true,
25
- get: function () { return e[k]; }
26
- });
27
- }
28
- });
29
- }
30
- n.default = e;
31
- return Object.freeze(n);
32
- }
33
-
34
- var reactI18next__namespace = /*#__PURE__*/_interopNamespaceDefault(reactI18next);
35
11
 
36
12
  /**
37
13
  * Sets up a mock implementation for HTML Canvas API in testing environments.
@@ -494,14 +470,10 @@ const setupTimeAndLanguage = () => {
494
470
  };
495
471
  };
496
472
 
497
- if (typeof global !== "undefined") {
498
- global.TextEncoder = global.TextEncoder || util.TextEncoder;
499
- global.TextDecoder = global.TextDecoder || util.TextDecoder;
500
- }
501
473
  /**
502
474
  * Sets up internationalization and translation mocks for testing environments.
503
475
  *
504
- * This function configures
476
+ * This function delegates to the implementation in setupTranslationsImpl.tsx to configure
505
477
  * mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
506
478
  * simple mock implementations that return the key string as the translation, which allows
507
479
  * for testing internationalized components without the complexity of actual translations.
@@ -516,74 +488,8 @@ if (typeof global !== "undefined") {
516
488
  * setupTranslations();
517
489
  */
518
490
  const setupTranslations = () => {
519
- const hasChildren = (node) => node && (node.children || (node.props && node.props.children));
520
- const getChildren = (node) => (node && node.children ? node.children : node.props && node.props.children);
521
- const renderNodes = (reactNodes) => {
522
- if (typeof reactNodes === "string") {
523
- return reactNodes;
524
- }
525
- return Object.keys(reactNodes).map((key, i) => {
526
- const child = reactNodes[key];
527
- const isElement = react$1.isValidElement(child);
528
- if (typeof child === "string") {
529
- return child;
530
- }
531
- if (hasChildren(child)) {
532
- const inner = renderNodes(getChildren(child));
533
- return react$1.cloneElement(child, { ...child.props, key: i }, inner);
534
- }
535
- if (typeof child === "object" && !isElement) {
536
- return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, "");
537
- }
538
- return child;
539
- });
540
- };
541
- const i18n = { language: "en", exists: () => true };
542
- const useMock = [
543
- (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : ""),
544
- i18n,
545
- ];
546
- useMock.t = (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : "");
547
- useMock.i18n = i18n;
548
- const useTranslation = () => useMock;
549
- const Trans = ({ i18nKey, components, children }) => {
550
- const result = [];
551
- result.push(renderNodes([i18nKey]));
552
- if (Array.isArray(children)) {
553
- result.push(...renderNodes(children));
554
- }
555
- else if (children && "toArray" in children) {
556
- result.push(...renderNodes(children.toArray()));
557
- }
558
- else {
559
- result.push(...renderNodes([children]));
560
- }
561
- if (components) {
562
- result.push(...Object.keys(components).map(key => jsxRuntime.jsx("span", { children: components[key] }, key)));
563
- }
564
- return jsxRuntime.jsx(jsxRuntime.Fragment, { children: result });
565
- };
566
- const Translation = ({ children }) => children((k) => k, { i18n });
567
- jest.doMock("react-i18next", () => {
568
- return {
569
- // this mock makes sure any components using the translate HoC receive the t function as a prop
570
- Trans,
571
- Translation,
572
- useTranslation,
573
- // mock if needed
574
- I18nextProvider: reactI18next__namespace.I18nextProvider,
575
- initReactI18next: reactI18next__namespace.initReactI18next,
576
- setDefaults: reactI18next__namespace.setDefaults,
577
- getDefaults: reactI18next__namespace.getDefaults,
578
- setI18n: reactI18next__namespace.setI18n,
579
- getI18n: reactI18next__namespace.getI18n,
580
- };
581
- });
582
- jest.doMock("@trackunit/i18n-library-translation", () => ({
583
- ...jest.requireActual("@trackunit/i18n-library-translation"),
584
- NamespaceTrans: (props) => jsxRuntime.jsx(Trans, { ...props }),
585
- useNamespaceTranslation: useTranslation,
586
- }));
491
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
492
+ require("./setupTranslationsImpl").setupTranslations();
587
493
  };
588
494
 
589
495
  /**
@@ -603,8 +509,8 @@ const setupTranslations = () => {
603
509
  * setupWebStreams();
604
510
  */
605
511
  const setupWebStreams = () => {
606
- global.TransformStream = webStreamsPolyfill.TransformStream;
607
- global.WritableStream = webStreamsPolyfill.WritableStream;
512
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
513
+ require("./setupWebStreamsImpl").setupWebStreams();
608
514
  };
609
515
 
610
516
  /**
package/index.esm.js CHANGED
@@ -1,16 +1,11 @@
1
1
  import failOnConsole from 'jest-fail-on-console';
2
- import { jsx, Fragment } from 'react/jsx-runtime';
2
+ import { jsx } from 'react/jsx-runtime';
3
3
  import { APILoadingStatus } from '@vis.gl/react-google-maps';
4
4
  import { initialize } from '@googlemaps/jest-mocks';
5
- import '@okta/okta-react';
6
5
  import '@testing-library/jest-dom';
7
6
  import { cleanup, act } from '@testing-library/react';
8
7
  import { Temporal } from '@js-temporal/polyfill';
9
8
  import { Globals } from '@react-spring/web';
10
- import { TextEncoder, TextDecoder } from 'util';
11
- import { isValidElement, cloneElement } from 'react';
12
- import * as reactI18next from 'react-i18next';
13
- import { TransformStream, WritableStream } from 'web-streams-polyfill';
14
9
 
15
10
  /**
16
11
  * Sets up a mock implementation for HTML Canvas API in testing environments.
@@ -473,14 +468,10 @@ const setupTimeAndLanguage = () => {
473
468
  };
474
469
  };
475
470
 
476
- if (typeof global !== "undefined") {
477
- global.TextEncoder = global.TextEncoder || TextEncoder;
478
- global.TextDecoder = global.TextDecoder || TextDecoder;
479
- }
480
471
  /**
481
472
  * Sets up internationalization and translation mocks for testing environments.
482
473
  *
483
- * This function configures
474
+ * This function delegates to the implementation in setupTranslationsImpl.tsx to configure
484
475
  * mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
485
476
  * simple mock implementations that return the key string as the translation, which allows
486
477
  * for testing internationalized components without the complexity of actual translations.
@@ -495,74 +486,8 @@ if (typeof global !== "undefined") {
495
486
  * setupTranslations();
496
487
  */
497
488
  const setupTranslations = () => {
498
- const hasChildren = (node) => node && (node.children || (node.props && node.props.children));
499
- const getChildren = (node) => (node && node.children ? node.children : node.props && node.props.children);
500
- const renderNodes = (reactNodes) => {
501
- if (typeof reactNodes === "string") {
502
- return reactNodes;
503
- }
504
- return Object.keys(reactNodes).map((key, i) => {
505
- const child = reactNodes[key];
506
- const isElement = isValidElement(child);
507
- if (typeof child === "string") {
508
- return child;
509
- }
510
- if (hasChildren(child)) {
511
- const inner = renderNodes(getChildren(child));
512
- return cloneElement(child, { ...child.props, key: i }, inner);
513
- }
514
- if (typeof child === "object" && !isElement) {
515
- return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, "");
516
- }
517
- return child;
518
- });
519
- };
520
- const i18n = { language: "en", exists: () => true };
521
- const useMock = [
522
- (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : ""),
523
- i18n,
524
- ];
525
- useMock.t = (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : "");
526
- useMock.i18n = i18n;
527
- const useTranslation = () => useMock;
528
- const Trans = ({ i18nKey, components, children }) => {
529
- const result = [];
530
- result.push(renderNodes([i18nKey]));
531
- if (Array.isArray(children)) {
532
- result.push(...renderNodes(children));
533
- }
534
- else if (children && "toArray" in children) {
535
- result.push(...renderNodes(children.toArray()));
536
- }
537
- else {
538
- result.push(...renderNodes([children]));
539
- }
540
- if (components) {
541
- result.push(...Object.keys(components).map(key => jsx("span", { children: components[key] }, key)));
542
- }
543
- return jsx(Fragment, { children: result });
544
- };
545
- const Translation = ({ children }) => children((k) => k, { i18n });
546
- jest.doMock("react-i18next", () => {
547
- return {
548
- // this mock makes sure any components using the translate HoC receive the t function as a prop
549
- Trans,
550
- Translation,
551
- useTranslation,
552
- // mock if needed
553
- I18nextProvider: reactI18next.I18nextProvider,
554
- initReactI18next: reactI18next.initReactI18next,
555
- setDefaults: reactI18next.setDefaults,
556
- getDefaults: reactI18next.getDefaults,
557
- setI18n: reactI18next.setI18n,
558
- getI18n: reactI18next.getI18n,
559
- };
560
- });
561
- jest.doMock("@trackunit/i18n-library-translation", () => ({
562
- ...jest.requireActual("@trackunit/i18n-library-translation"),
563
- NamespaceTrans: (props) => jsx(Trans, { ...props }),
564
- useNamespaceTranslation: useTranslation,
565
- }));
489
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
490
+ require("./setupTranslationsImpl").setupTranslations();
566
491
  };
567
492
 
568
493
  /**
@@ -582,8 +507,8 @@ const setupTranslations = () => {
582
507
  * setupWebStreams();
583
508
  */
584
509
  const setupWebStreams = () => {
585
- global.TransformStream = TransformStream;
586
- global.WritableStream = WritableStream;
510
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
511
+ require("./setupWebStreamsImpl").setupWebStreams();
587
512
  };
588
513
 
589
514
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trackunit/react-test-setup",
3
3
  "description": "Test setup utilities for React applications",
4
- "version": "1.0.19-alpha-169add733bd.0",
4
+ "version": "1.0.19",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
7
7
  "engines": {
@@ -20,8 +20,7 @@
20
20
  "react": "19.0.0",
21
21
  "react-i18next": "^15.5.1",
22
22
  "react-virtualized-auto-sizer": "^1.0.20",
23
- "web-streams-polyfill": "^4.1.0",
24
- "@okta/okta-react": "^6.9.0"
23
+ "web-streams-polyfill": "^4.1.0"
25
24
  },
26
25
  "module": "./index.esm.js",
27
26
  "main": "./index.cjs.js",
@@ -1,4 +1,3 @@
1
- import "@okta/okta-react";
2
1
  import "@testing-library/jest-dom";
3
2
  /**
4
3
  * Sets up React Testing Library and Okta authentication mocks for testing.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Sets up internationalization and translation mocks for testing environments.
3
3
  *
4
- * This function configures
4
+ * This function delegates to the implementation in setupTranslationsImpl.tsx to configure
5
5
  * mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
6
6
  * simple mock implementations that return the key string as the translation, which allows
7
7
  * for testing internationalized components without the complexity of actual translations.
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Implementation of translation mocks for testing environments.
3
+ *
4
+ * This function creates detailed mock implementations for react-i18next and
5
+ * Trackunit i18n library translation utilities. The mocks are designed to:
6
+ *
7
+ * 1. Return translation keys as the translated strings (with any provided props)
8
+ * 2. Render components within Trans components by preserving their React structure
9
+ * 3. Provide a simplified i18n object with expected properties
10
+ * 4. Handle nested components and rendering flows without complex translation logic
11
+ *
12
+ * These mocks allow components that use internationalization to be tested without
13
+ * requiring actual translation files or i18n initialization, simplifying test setup
14
+ * while preserving component rendering behavior.
15
+ *
16
+ * @internal
17
+ */
18
+ export declare const setupTranslations: () => void;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Implementation for Web Streams API polyfills in testing environments.
3
+ *
4
+ * This function adds the TransformStream and WritableStream implementations from
5
+ * web-streams-polyfill to the global object, making them available to code running
6
+ * in the Jest/JSDOM environment which may not have native implementations of these APIs.
7
+ *
8
+ * These polyfills are essential for testing code that uses modern streaming features,
9
+ * particularly for scenarios involving:
10
+ * - Data processing pipelines
11
+ * - Chunk-by-chunk text or binary processing
12
+ * - Streaming responses from APIs
13
+ *
14
+ * @internal
15
+ */
16
+ export declare const setupWebStreams: () => void;