@trackunit/react-test-setup 1.0.23 → 1.0.29
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 +125 -7
- package/index.esm.js +107 -9
- package/package.json +17 -2
- package/preset.cjs.d.ts +2 -0
- package/preset.cjs.js +24 -0
- package/preset.esm.d.ts +2 -0
- package/preset.esm.js +19 -0
- package/src/index.d.ts +2 -1
- package/src/preset/jestPreset.d.ts +9 -0
- package/src/preset.d.ts +3 -0
- package/src/setupReactTablePagination.d.ts +7 -0
- package/src/setupReactTestingLibrary.d.ts +2 -0
- package/src/setupTranslations.d.ts +1 -2
- package/src/setupWebStreams.d.ts +0 -1
- package/src/setupTranslationsImpl.d.ts +0 -18
- package/src/setupWebStreamsImpl.d.ts +0 -16
package/index.cjs.js
CHANGED
|
@@ -4,10 +4,35 @@ 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');
|
|
7
8
|
require('@testing-library/jest-dom');
|
|
8
9
|
var react = require('@testing-library/react');
|
|
10
|
+
require('react-router-dom');
|
|
9
11
|
var polyfill = require('@js-temporal/polyfill');
|
|
10
12
|
var web = require('@react-spring/web');
|
|
13
|
+
var util = require('util');
|
|
14
|
+
var react$1 = require('react');
|
|
15
|
+
var reactI18next = require('react-i18next');
|
|
16
|
+
var webStreamsPolyfill = require('web-streams-polyfill');
|
|
17
|
+
|
|
18
|
+
function _interopNamespaceDefault(e) {
|
|
19
|
+
var n = Object.create(null);
|
|
20
|
+
if (e) {
|
|
21
|
+
Object.keys(e).forEach(function (k) {
|
|
22
|
+
if (k !== 'default') {
|
|
23
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return e[k]; }
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
n.default = e;
|
|
32
|
+
return Object.freeze(n);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var reactI18next__namespace = /*#__PURE__*/_interopNamespaceDefault(reactI18next);
|
|
11
36
|
|
|
12
37
|
/**
|
|
13
38
|
* Sets up a mock implementation for HTML Canvas API in testing environments.
|
|
@@ -470,11 +495,14 @@ const setupTimeAndLanguage = () => {
|
|
|
470
495
|
};
|
|
471
496
|
};
|
|
472
497
|
|
|
498
|
+
if (typeof global !== "undefined") {
|
|
499
|
+
global.TextEncoder = global.TextEncoder || util.TextEncoder;
|
|
500
|
+
global.TextDecoder = global.TextDecoder || util.TextDecoder;
|
|
501
|
+
}
|
|
473
502
|
/**
|
|
474
503
|
* Sets up internationalization and translation mocks for testing environments.
|
|
475
504
|
*
|
|
476
|
-
*
|
|
477
|
-
* mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
|
|
505
|
+
* Mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
|
|
478
506
|
* simple mock implementations that return the key string as the translation, which allows
|
|
479
507
|
* for testing internationalized components without the complexity of actual translations.
|
|
480
508
|
*
|
|
@@ -488,14 +516,79 @@ const setupTimeAndLanguage = () => {
|
|
|
488
516
|
* setupTranslations();
|
|
489
517
|
*/
|
|
490
518
|
const setupTranslations = () => {
|
|
491
|
-
|
|
492
|
-
|
|
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
|
+
}));
|
|
493
587
|
};
|
|
494
588
|
|
|
495
589
|
/**
|
|
496
590
|
* Sets up Web Streams API polyfills for testing environments.
|
|
497
591
|
*
|
|
498
|
-
* This function delegates to the implementation in setupWebStreamsImpl.ts to configure
|
|
499
592
|
* Web Streams API polyfills from web-streams-polyfill. These polyfills provide implementations
|
|
500
593
|
* of modern streaming APIs that may not be available in the Jest/JSDOM testing environment.
|
|
501
594
|
*
|
|
@@ -509,8 +602,8 @@ const setupTranslations = () => {
|
|
|
509
602
|
* setupWebStreams();
|
|
510
603
|
*/
|
|
511
604
|
const setupWebStreams = () => {
|
|
512
|
-
|
|
513
|
-
|
|
605
|
+
global.TransformStream = webStreamsPolyfill.TransformStream;
|
|
606
|
+
global.WritableStream = webStreamsPolyfill.WritableStream;
|
|
514
607
|
};
|
|
515
608
|
|
|
516
609
|
/**
|
|
@@ -660,6 +753,30 @@ const setupDefaultMocks = (options = {}) => {
|
|
|
660
753
|
setupTranslations();
|
|
661
754
|
};
|
|
662
755
|
|
|
756
|
+
/**
|
|
757
|
+
* Sets up a mocked implementation of the `useInfiniteScroll` hook from
|
|
758
|
+
* `@trackunit/react-table-pagination` for testing purposes.
|
|
759
|
+
*
|
|
760
|
+
* @param {number} [count] - The number of virtual items to generate for the mocked implementation.
|
|
761
|
+
*/
|
|
762
|
+
const setupReactTablePagination = (count) => {
|
|
763
|
+
jest.mock("@trackunit/react-table-pagination", () => ({
|
|
764
|
+
...jest.requireActual("@trackunit/react-table-pagination"),
|
|
765
|
+
useInfiniteScroll: jest.fn(() => ({
|
|
766
|
+
fetchMoreOnBottomReached: jest.fn(),
|
|
767
|
+
getTotalSize: jest.fn(() => 100),
|
|
768
|
+
getVirtualItems: () => {
|
|
769
|
+
const result = [];
|
|
770
|
+
for (let i = 0; i < (count || 4); i++) {
|
|
771
|
+
result.push({ index: i, start: i * 40, key: i, size: 40 });
|
|
772
|
+
}
|
|
773
|
+
return result;
|
|
774
|
+
},
|
|
775
|
+
measureElement: jest.fn(),
|
|
776
|
+
})),
|
|
777
|
+
}));
|
|
778
|
+
};
|
|
779
|
+
|
|
663
780
|
exports.setupAllMocks = setupAllMocks;
|
|
664
781
|
exports.setupBasicMocks = setupBasicMocks;
|
|
665
782
|
exports.setupCanvasMock = setupCanvasMock;
|
|
@@ -669,6 +786,7 @@ exports.setupGoogleMaps = setupGoogleMaps;
|
|
|
669
786
|
exports.setupHelmetMock = setupHelmetMock;
|
|
670
787
|
exports.setupIntersectionObserver = setupIntersectionObserver;
|
|
671
788
|
exports.setupMatchMediaMock = setupMatchMediaMock;
|
|
789
|
+
exports.setupReactTablePagination = setupReactTablePagination;
|
|
672
790
|
exports.setupReactTestingLibrary = setupReactTestingLibrary;
|
|
673
791
|
exports.setupReactVirtualizedAutoSizer = setupReactVirtualizedAutoSizer;
|
|
674
792
|
exports.setupResizeObserver = setupResizeObserver;
|
package/index.esm.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import failOnConsole from 'jest-fail-on-console';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { jsx, Fragment } 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';
|
|
5
6
|
import '@testing-library/jest-dom';
|
|
6
7
|
import { cleanup, act } from '@testing-library/react';
|
|
8
|
+
import 'react-router-dom';
|
|
7
9
|
import { Temporal } from '@js-temporal/polyfill';
|
|
8
10
|
import { Globals } from '@react-spring/web';
|
|
11
|
+
import { TextEncoder, TextDecoder } from 'util';
|
|
12
|
+
import { isValidElement, cloneElement } from 'react';
|
|
13
|
+
import * as reactI18next from 'react-i18next';
|
|
14
|
+
import { TransformStream, WritableStream } from 'web-streams-polyfill';
|
|
9
15
|
|
|
10
16
|
/**
|
|
11
17
|
* Sets up a mock implementation for HTML Canvas API in testing environments.
|
|
@@ -468,11 +474,14 @@ const setupTimeAndLanguage = () => {
|
|
|
468
474
|
};
|
|
469
475
|
};
|
|
470
476
|
|
|
477
|
+
if (typeof global !== "undefined") {
|
|
478
|
+
global.TextEncoder = global.TextEncoder || TextEncoder;
|
|
479
|
+
global.TextDecoder = global.TextDecoder || TextDecoder;
|
|
480
|
+
}
|
|
471
481
|
/**
|
|
472
482
|
* Sets up internationalization and translation mocks for testing environments.
|
|
473
483
|
*
|
|
474
|
-
*
|
|
475
|
-
* mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
|
|
484
|
+
* Mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
|
|
476
485
|
* simple mock implementations that return the key string as the translation, which allows
|
|
477
486
|
* for testing internationalized components without the complexity of actual translations.
|
|
478
487
|
*
|
|
@@ -486,14 +495,79 @@ const setupTimeAndLanguage = () => {
|
|
|
486
495
|
* setupTranslations();
|
|
487
496
|
*/
|
|
488
497
|
const setupTranslations = () => {
|
|
489
|
-
|
|
490
|
-
|
|
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
|
+
}));
|
|
491
566
|
};
|
|
492
567
|
|
|
493
568
|
/**
|
|
494
569
|
* Sets up Web Streams API polyfills for testing environments.
|
|
495
570
|
*
|
|
496
|
-
* This function delegates to the implementation in setupWebStreamsImpl.ts to configure
|
|
497
571
|
* Web Streams API polyfills from web-streams-polyfill. These polyfills provide implementations
|
|
498
572
|
* of modern streaming APIs that may not be available in the Jest/JSDOM testing environment.
|
|
499
573
|
*
|
|
@@ -507,8 +581,8 @@ const setupTranslations = () => {
|
|
|
507
581
|
* setupWebStreams();
|
|
508
582
|
*/
|
|
509
583
|
const setupWebStreams = () => {
|
|
510
|
-
|
|
511
|
-
|
|
584
|
+
global.TransformStream = TransformStream;
|
|
585
|
+
global.WritableStream = WritableStream;
|
|
512
586
|
};
|
|
513
587
|
|
|
514
588
|
/**
|
|
@@ -658,4 +732,28 @@ const setupDefaultMocks = (options = {}) => {
|
|
|
658
732
|
setupTranslations();
|
|
659
733
|
};
|
|
660
734
|
|
|
661
|
-
|
|
735
|
+
/**
|
|
736
|
+
* Sets up a mocked implementation of the `useInfiniteScroll` hook from
|
|
737
|
+
* `@trackunit/react-table-pagination` for testing purposes.
|
|
738
|
+
*
|
|
739
|
+
* @param {number} [count] - The number of virtual items to generate for the mocked implementation.
|
|
740
|
+
*/
|
|
741
|
+
const setupReactTablePagination = (count) => {
|
|
742
|
+
jest.mock("@trackunit/react-table-pagination", () => ({
|
|
743
|
+
...jest.requireActual("@trackunit/react-table-pagination"),
|
|
744
|
+
useInfiniteScroll: jest.fn(() => ({
|
|
745
|
+
fetchMoreOnBottomReached: jest.fn(),
|
|
746
|
+
getTotalSize: jest.fn(() => 100),
|
|
747
|
+
getVirtualItems: () => {
|
|
748
|
+
const result = [];
|
|
749
|
+
for (let i = 0; i < (count || 4); i++) {
|
|
750
|
+
result.push({ index: i, start: i * 40, key: i, size: 40 });
|
|
751
|
+
}
|
|
752
|
+
return result;
|
|
753
|
+
},
|
|
754
|
+
measureElement: jest.fn(),
|
|
755
|
+
})),
|
|
756
|
+
}));
|
|
757
|
+
};
|
|
758
|
+
|
|
759
|
+
export { setupAllMocks, setupBasicMocks, setupCanvasMock, setupDefaultMocks, setupFailOnConsole, setupGoogleMaps, setupHelmetMock, setupIntersectionObserver, setupMatchMediaMock, setupReactTablePagination, setupReactTestingLibrary, setupReactVirtualizedAutoSizer, setupResizeObserver, setupTanstackReactVirtual, setupTimeAndLanguage, setupTimeZone, setupTranslations, setupWebStreams };
|
package/package.json
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
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.29",
|
|
5
5
|
"repository": "https://github.com/Trackunit/manager",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=22.x"
|
|
9
9
|
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./index.esm.js",
|
|
13
|
+
"require": "./index.cjs.js",
|
|
14
|
+
"types": "./index.esm.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./preset": {
|
|
17
|
+
"import": "./preset.esm.js",
|
|
18
|
+
"require": "./preset.cjs.js",
|
|
19
|
+
"types": "./preset.esm.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
10
22
|
"dependencies": {
|
|
11
23
|
"@googlemaps/jest-mocks": "2.21.4",
|
|
12
24
|
"@js-temporal/polyfill": "^0.4.4",
|
|
@@ -20,7 +32,10 @@
|
|
|
20
32
|
"react": "19.0.0",
|
|
21
33
|
"react-i18next": "^15.5.1",
|
|
22
34
|
"react-virtualized-auto-sizer": "^1.0.20",
|
|
23
|
-
"web-streams-polyfill": "^4.1.0"
|
|
35
|
+
"web-streams-polyfill": "^4.1.0",
|
|
36
|
+
"@okta/okta-react": "^6.9.0",
|
|
37
|
+
"react-router-dom": "6.18.0",
|
|
38
|
+
"jest": "29.7.0"
|
|
24
39
|
},
|
|
25
40
|
"module": "./index.esm.js",
|
|
26
41
|
"main": "./index.cjs.js",
|
package/preset.cjs.d.ts
ADDED
package/preset.cjs.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Jest preset for Trackunit React applications.
|
|
7
|
+
*
|
|
8
|
+
* This preset provides:
|
|
9
|
+
* - Test setup files that configure mocks and testing utilities
|
|
10
|
+
* - Module name mappings for stubbing CSS and SVG files
|
|
11
|
+
*/
|
|
12
|
+
const irisPreset = {
|
|
13
|
+
setupFilesAfterEnv: ["<rootDir>/test/config/jest.setup.tsx"],
|
|
14
|
+
moduleNameMapper: {
|
|
15
|
+
"@trackunit/css-core": "jest-transform-stub",
|
|
16
|
+
"@trackunit/ui-icons/icons-sprite-mini.svg": "jest-transform-stub",
|
|
17
|
+
"@trackunit/ui-icons/icons-sprite-outline.svg": "jest-transform-stub",
|
|
18
|
+
"@trackunit/ui-icons/icons-sprite-solid.svg": "jest-transform-stub",
|
|
19
|
+
"@trackunit/ui-icons/icons-sprite-micro.svg": "jest-transform-stub",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.default = irisPreset;
|
|
24
|
+
exports.irisPreset = irisPreset;
|
package/preset.esm.d.ts
ADDED
package/preset.esm.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jest preset for Trackunit React applications.
|
|
3
|
+
*
|
|
4
|
+
* This preset provides:
|
|
5
|
+
* - Test setup files that configure mocks and testing utilities
|
|
6
|
+
* - Module name mappings for stubbing CSS and SVG files
|
|
7
|
+
*/
|
|
8
|
+
const irisPreset = {
|
|
9
|
+
setupFilesAfterEnv: ["<rootDir>/test/config/jest.setup.tsx"],
|
|
10
|
+
moduleNameMapper: {
|
|
11
|
+
"@trackunit/css-core": "jest-transform-stub",
|
|
12
|
+
"@trackunit/ui-icons/icons-sprite-mini.svg": "jest-transform-stub",
|
|
13
|
+
"@trackunit/ui-icons/icons-sprite-outline.svg": "jest-transform-stub",
|
|
14
|
+
"@trackunit/ui-icons/icons-sprite-solid.svg": "jest-transform-stub",
|
|
15
|
+
"@trackunit/ui-icons/icons-sprite-micro.svg": "jest-transform-stub",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { irisPreset as default, irisPreset };
|
package/src/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export * from "./setupAllMocks";
|
|
2
2
|
export * from "./setupBasicMocks";
|
|
3
|
-
export * from "./setupDefaultMocks";
|
|
4
3
|
export * from "./setupCanvasMock";
|
|
4
|
+
export * from "./setupDefaultMocks";
|
|
5
5
|
export * from "./setupFailOnConsole";
|
|
6
6
|
export * from "./setupGoogleMaps";
|
|
7
7
|
export * from "./setupHelmetMock";
|
|
8
8
|
export * from "./setupIntersectionObserver";
|
|
9
9
|
export * from "./setupMatchMediaMock";
|
|
10
|
+
export * from "./setupReactTablePagination";
|
|
10
11
|
export * from "./setupReactTestingLibrary";
|
|
11
12
|
export * from "./setupReactVirtualizedAutoSizer";
|
|
12
13
|
export * from "./setupResizeObserver";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from "jest";
|
|
2
|
+
/**
|
|
3
|
+
* Jest preset for Trackunit React applications.
|
|
4
|
+
*
|
|
5
|
+
* This preset provides:
|
|
6
|
+
* - Test setup files that configure mocks and testing utilities
|
|
7
|
+
* - Module name mappings for stubbing CSS and SVG files
|
|
8
|
+
*/
|
|
9
|
+
export declare const irisPreset: Config;
|
package/src/preset.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets up a mocked implementation of the `useInfiniteScroll` hook from
|
|
3
|
+
* `@trackunit/react-table-pagination` for testing purposes.
|
|
4
|
+
*
|
|
5
|
+
* @param {number} [count] - The number of virtual items to generate for the mocked implementation.
|
|
6
|
+
*/
|
|
7
|
+
export declare const setupReactTablePagination: (count?: number) => void;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sets up internationalization and translation mocks for testing environments.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
|
|
4
|
+
* Mock translations for react-i18next and @trackunit/i18n-library-translation. It creates
|
|
6
5
|
* simple mock implementations that return the key string as the translation, which allows
|
|
7
6
|
* for testing internationalized components without the complexity of actual translations.
|
|
8
7
|
*
|
package/src/setupWebStreams.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sets up Web Streams API polyfills for testing environments.
|
|
3
3
|
*
|
|
4
|
-
* This function delegates to the implementation in setupWebStreamsImpl.ts to configure
|
|
5
4
|
* Web Streams API polyfills from web-streams-polyfill. These polyfills provide implementations
|
|
6
5
|
* of modern streaming APIs that may not be available in the Jest/JSDOM testing environment.
|
|
7
6
|
*
|
|
@@ -1,18 +0,0 @@
|
|
|
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;
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|