@trackunit/react-test-setup 1.0.6-alpha-0614a19af4e.0 → 1.0.7
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 +4 -93
- package/index.esm.js +5 -75
- package/package.json +2 -3
- package/src/setupReactTestingLibrary.d.ts +0 -1
- package/src/setupTranslationsImpl.d.ts +18 -0
- package/src/setupWebStreamsImpl.d.ts +16 -0
package/index.cjs.js
CHANGED
|
@@ -4,33 +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 react$1 = require('react');
|
|
13
|
-
var reactI18next = require('react-i18next');
|
|
14
|
-
var webStreamsPolyfill = require('web-streams-polyfill');
|
|
15
|
-
|
|
16
|
-
function _interopNamespaceDefault(e) {
|
|
17
|
-
var n = Object.create(null);
|
|
18
|
-
if (e) {
|
|
19
|
-
Object.keys(e).forEach(function (k) {
|
|
20
|
-
if (k !== 'default') {
|
|
21
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function () { return e[k]; }
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
n.default = e;
|
|
30
|
-
return Object.freeze(n);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
var reactI18next__namespace = /*#__PURE__*/_interopNamespaceDefault(reactI18next);
|
|
34
11
|
|
|
35
12
|
/**
|
|
36
13
|
* Sets up a mock implementation for HTML Canvas API in testing environments.
|
|
@@ -511,74 +488,8 @@ const setupTimeAndLanguage = () => {
|
|
|
511
488
|
* setupTranslations();
|
|
512
489
|
*/
|
|
513
490
|
const setupTranslations = () => {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
const renderNodes = (reactNodes) => {
|
|
517
|
-
if (typeof reactNodes === "string") {
|
|
518
|
-
return reactNodes;
|
|
519
|
-
}
|
|
520
|
-
return Object.keys(reactNodes).map((key, i) => {
|
|
521
|
-
const child = reactNodes[key];
|
|
522
|
-
const isElement = react$1.isValidElement(child);
|
|
523
|
-
if (typeof child === "string") {
|
|
524
|
-
return child;
|
|
525
|
-
}
|
|
526
|
-
if (hasChildren(child)) {
|
|
527
|
-
const inner = renderNodes(getChildren(child));
|
|
528
|
-
return react$1.cloneElement(child, { ...child.props, key: i }, inner);
|
|
529
|
-
}
|
|
530
|
-
if (typeof child === "object" && !isElement) {
|
|
531
|
-
return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, "");
|
|
532
|
-
}
|
|
533
|
-
return child;
|
|
534
|
-
});
|
|
535
|
-
};
|
|
536
|
-
const i18n = { language: "en", exists: () => true };
|
|
537
|
-
const useMock = [
|
|
538
|
-
(k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : ""),
|
|
539
|
-
i18n,
|
|
540
|
-
];
|
|
541
|
-
useMock.t = (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : "");
|
|
542
|
-
useMock.i18n = i18n;
|
|
543
|
-
const useTranslation = () => useMock;
|
|
544
|
-
const Trans = ({ i18nKey, components, children }) => {
|
|
545
|
-
const result = [];
|
|
546
|
-
result.push(renderNodes([i18nKey]));
|
|
547
|
-
if (Array.isArray(children)) {
|
|
548
|
-
result.push(...renderNodes(children));
|
|
549
|
-
}
|
|
550
|
-
else if (children && "toArray" in children) {
|
|
551
|
-
result.push(...renderNodes(children.toArray()));
|
|
552
|
-
}
|
|
553
|
-
else {
|
|
554
|
-
result.push(...renderNodes([children]));
|
|
555
|
-
}
|
|
556
|
-
if (components) {
|
|
557
|
-
result.push(...Object.keys(components).map(key => jsxRuntime.jsx("span", { children: components[key] }, key)));
|
|
558
|
-
}
|
|
559
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: result });
|
|
560
|
-
};
|
|
561
|
-
const Translation = ({ children }) => children((k) => k, { i18n });
|
|
562
|
-
jest.doMock("react-i18next", () => {
|
|
563
|
-
return {
|
|
564
|
-
// this mock makes sure any components using the translate HoC receive the t function as a prop
|
|
565
|
-
Trans,
|
|
566
|
-
Translation,
|
|
567
|
-
useTranslation,
|
|
568
|
-
// mock if needed
|
|
569
|
-
I18nextProvider: reactI18next__namespace.I18nextProvider,
|
|
570
|
-
initReactI18next: reactI18next__namespace.initReactI18next,
|
|
571
|
-
setDefaults: reactI18next__namespace.setDefaults,
|
|
572
|
-
getDefaults: reactI18next__namespace.getDefaults,
|
|
573
|
-
setI18n: reactI18next__namespace.setI18n,
|
|
574
|
-
getI18n: reactI18next__namespace.getI18n,
|
|
575
|
-
};
|
|
576
|
-
});
|
|
577
|
-
jest.doMock("@trackunit/i18n-library-translation", () => ({
|
|
578
|
-
...jest.requireActual("@trackunit/i18n-library-translation"),
|
|
579
|
-
NamespaceTrans: (props) => jsxRuntime.jsx(Trans, { ...props }),
|
|
580
|
-
useNamespaceTranslation: useTranslation,
|
|
581
|
-
}));
|
|
491
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
492
|
+
require("./setupTranslationsImpl").setupTranslations();
|
|
582
493
|
};
|
|
583
494
|
|
|
584
495
|
/**
|
|
@@ -598,8 +509,8 @@ const setupTranslations = () => {
|
|
|
598
509
|
* setupWebStreams();
|
|
599
510
|
*/
|
|
600
511
|
const setupWebStreams = () => {
|
|
601
|
-
|
|
602
|
-
|
|
512
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
513
|
+
require("./setupWebStreamsImpl").setupWebStreams();
|
|
603
514
|
};
|
|
604
515
|
|
|
605
516
|
/**
|
package/index.esm.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import failOnConsole from 'jest-fail-on-console';
|
|
2
|
-
import { jsx
|
|
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 { isValidElement, cloneElement } from 'react';
|
|
11
|
-
import * as reactI18next from 'react-i18next';
|
|
12
|
-
import { TransformStream, WritableStream } from 'web-streams-polyfill';
|
|
13
9
|
|
|
14
10
|
/**
|
|
15
11
|
* Sets up a mock implementation for HTML Canvas API in testing environments.
|
|
@@ -490,74 +486,8 @@ const setupTimeAndLanguage = () => {
|
|
|
490
486
|
* setupTranslations();
|
|
491
487
|
*/
|
|
492
488
|
const setupTranslations = () => {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
const renderNodes = (reactNodes) => {
|
|
496
|
-
if (typeof reactNodes === "string") {
|
|
497
|
-
return reactNodes;
|
|
498
|
-
}
|
|
499
|
-
return Object.keys(reactNodes).map((key, i) => {
|
|
500
|
-
const child = reactNodes[key];
|
|
501
|
-
const isElement = isValidElement(child);
|
|
502
|
-
if (typeof child === "string") {
|
|
503
|
-
return child;
|
|
504
|
-
}
|
|
505
|
-
if (hasChildren(child)) {
|
|
506
|
-
const inner = renderNodes(getChildren(child));
|
|
507
|
-
return cloneElement(child, { ...child.props, key: i }, inner);
|
|
508
|
-
}
|
|
509
|
-
if (typeof child === "object" && !isElement) {
|
|
510
|
-
return Object.keys(child).reduce((str, childKey) => `${str}${child[childKey]}`, "");
|
|
511
|
-
}
|
|
512
|
-
return child;
|
|
513
|
-
});
|
|
514
|
-
};
|
|
515
|
-
const i18n = { language: "en", exists: () => true };
|
|
516
|
-
const useMock = [
|
|
517
|
-
(k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : ""),
|
|
518
|
-
i18n,
|
|
519
|
-
];
|
|
520
|
-
useMock.t = (k, extra) => k + (extra ? " props: " + JSON.stringify(extra) : "");
|
|
521
|
-
useMock.i18n = i18n;
|
|
522
|
-
const useTranslation = () => useMock;
|
|
523
|
-
const Trans = ({ i18nKey, components, children }) => {
|
|
524
|
-
const result = [];
|
|
525
|
-
result.push(renderNodes([i18nKey]));
|
|
526
|
-
if (Array.isArray(children)) {
|
|
527
|
-
result.push(...renderNodes(children));
|
|
528
|
-
}
|
|
529
|
-
else if (children && "toArray" in children) {
|
|
530
|
-
result.push(...renderNodes(children.toArray()));
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
result.push(...renderNodes([children]));
|
|
534
|
-
}
|
|
535
|
-
if (components) {
|
|
536
|
-
result.push(...Object.keys(components).map(key => jsx("span", { children: components[key] }, key)));
|
|
537
|
-
}
|
|
538
|
-
return jsx(Fragment, { children: result });
|
|
539
|
-
};
|
|
540
|
-
const Translation = ({ children }) => children((k) => k, { i18n });
|
|
541
|
-
jest.doMock("react-i18next", () => {
|
|
542
|
-
return {
|
|
543
|
-
// this mock makes sure any components using the translate HoC receive the t function as a prop
|
|
544
|
-
Trans,
|
|
545
|
-
Translation,
|
|
546
|
-
useTranslation,
|
|
547
|
-
// mock if needed
|
|
548
|
-
I18nextProvider: reactI18next.I18nextProvider,
|
|
549
|
-
initReactI18next: reactI18next.initReactI18next,
|
|
550
|
-
setDefaults: reactI18next.setDefaults,
|
|
551
|
-
getDefaults: reactI18next.getDefaults,
|
|
552
|
-
setI18n: reactI18next.setI18n,
|
|
553
|
-
getI18n: reactI18next.getI18n,
|
|
554
|
-
};
|
|
555
|
-
});
|
|
556
|
-
jest.doMock("@trackunit/i18n-library-translation", () => ({
|
|
557
|
-
...jest.requireActual("@trackunit/i18n-library-translation"),
|
|
558
|
-
NamespaceTrans: (props) => jsx(Trans, { ...props }),
|
|
559
|
-
useNamespaceTranslation: useTranslation,
|
|
560
|
-
}));
|
|
489
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
490
|
+
require("./setupTranslationsImpl").setupTranslations();
|
|
561
491
|
};
|
|
562
492
|
|
|
563
493
|
/**
|
|
@@ -577,8 +507,8 @@ const setupTranslations = () => {
|
|
|
577
507
|
* setupWebStreams();
|
|
578
508
|
*/
|
|
579
509
|
const setupWebStreams = () => {
|
|
580
|
-
|
|
581
|
-
|
|
510
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
511
|
+
require("./setupWebStreamsImpl").setupWebStreams();
|
|
582
512
|
};
|
|
583
513
|
|
|
584
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.
|
|
4
|
+
"version": "1.0.7",
|
|
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",
|
|
@@ -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;
|