@trackunit/react-vite-test-setup 0.0.59 → 0.0.61
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 +112 -52
- package/index.esm.js +110 -54
- package/package.json +2 -1
- package/src/setupTanstackReactVirtualize.d.ts +76 -8
package/index.cjs.js
CHANGED
|
@@ -1061,67 +1061,123 @@ const setupReactVirtualizedAutoSizer = () => {
|
|
|
1061
1061
|
vitest.vi.doMock("react-virtualized-auto-sizer", () => ({ children }) => children({ height: 600, width: 600, scaledWidth: 600, scaledHeight: 600 }));
|
|
1062
1062
|
};
|
|
1063
1063
|
|
|
1064
|
+
const ITEM_SIZE = 40;
|
|
1065
|
+
// Module-level: explicit opt-in test controls, set from outside the React
|
|
1066
|
+
// tree by the test currently under test. Unlike `count`/instance identity
|
|
1067
|
+
// (which must be isolated per mounted virtualizer, see `useVirtualizer`
|
|
1068
|
+
// below), these are intentionally global since only one hook-under-test
|
|
1069
|
+
// exercises them at a time.
|
|
1070
|
+
let virtualItemsOverride;
|
|
1071
|
+
let stableInstance = false;
|
|
1072
|
+
const noop = () => {
|
|
1073
|
+
/* noop */
|
|
1074
|
+
};
|
|
1075
|
+
const createVirtualItems = (count) => {
|
|
1076
|
+
const result = [];
|
|
1077
|
+
for (let i = 0; i < count; i++) {
|
|
1078
|
+
result.push({
|
|
1079
|
+
index: i,
|
|
1080
|
+
start: i * ITEM_SIZE,
|
|
1081
|
+
end: (i + 1) * ITEM_SIZE,
|
|
1082
|
+
size: ITEM_SIZE,
|
|
1083
|
+
lane: 0,
|
|
1084
|
+
key: i,
|
|
1085
|
+
measureRef: noop,
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
return result;
|
|
1089
|
+
};
|
|
1090
|
+
const createVirtualizer = (getCount) => ({
|
|
1091
|
+
getVirtualItems: () => virtualItemsOverride ?? createVirtualItems(getCount()),
|
|
1092
|
+
getTotalSize: () => getCount() * ITEM_SIZE,
|
|
1093
|
+
// Callback ref exposed by TanStack Virtual's directDomUpdates mode. The
|
|
1094
|
+
// real one positions rows/sizes the container directly; the mock is a
|
|
1095
|
+
// no-op so consumers can attach it without the virtualizer running.
|
|
1096
|
+
containerRef: noop,
|
|
1097
|
+
scrollOffset: 0,
|
|
1098
|
+
isScrolling: false,
|
|
1099
|
+
scrollToIndex: noop,
|
|
1100
|
+
scrollToOffset: noop,
|
|
1101
|
+
scrollToAlign: noop,
|
|
1102
|
+
scrollToItem: noop,
|
|
1103
|
+
resetAfterIndex: noop,
|
|
1104
|
+
resetAfterItem: noop,
|
|
1105
|
+
scrollTo: noop,
|
|
1106
|
+
measure: noop,
|
|
1107
|
+
measureElement: () => 42,
|
|
1108
|
+
});
|
|
1064
1109
|
/**
|
|
1065
|
-
*
|
|
1110
|
+
* Overrides the virtual items returned by every mocked virtualizer. Pass
|
|
1111
|
+
* `undefined` to fall back to the deterministic full-window items derived
|
|
1112
|
+
* from `count`.
|
|
1113
|
+
*/
|
|
1114
|
+
const setTanstackReactVirtualItems = (virtualItems) => {
|
|
1115
|
+
virtualItemsOverride = virtualItems;
|
|
1116
|
+
};
|
|
1117
|
+
/**
|
|
1118
|
+
* Controls whether `useVirtualizer` returns a referentially stable object
|
|
1119
|
+
* across re-renders of the same mounted instance, mirroring the real
|
|
1120
|
+
* virtualizer's in-place-update behaviour. Defaults to `false` (a new object
|
|
1121
|
+
* every render).
|
|
1122
|
+
*/
|
|
1123
|
+
const setTanstackReactVirtualStableInstance = (isStableInstance) => {
|
|
1124
|
+
stableInstance = isStableInstance;
|
|
1125
|
+
};
|
|
1126
|
+
/** Resets all mock test controls set via `setTanstackReactVirtualItems`/`setTanstackReactVirtualStableInstance`. */
|
|
1127
|
+
const resetTanstackReactVirtualMock = () => {
|
|
1128
|
+
virtualItemsOverride = undefined;
|
|
1129
|
+
stableInstance = false;
|
|
1130
|
+
};
|
|
1131
|
+
/**
|
|
1132
|
+
* Builds the mock module object for `@tanstack/react-virtual`.
|
|
1066
1133
|
*
|
|
1067
|
-
*
|
|
1068
|
-
* returns every item (no real DOM virtualisation), so tests can assert on
|
|
1069
|
-
*
|
|
1134
|
+
* `useVirtualizer` is replaced with a deterministic implementation that
|
|
1135
|
+
* returns every item (no real DOM virtualisation), so tests can assert on the
|
|
1136
|
+
* full rendered list without worrying about scroll-driven windowing. The
|
|
1137
|
+
* shape mirrors the fields consumed after the `directDomUpdates` migration
|
|
1138
|
+
* (`containerRef`, `scrollOffset`, `isScrolling`, and item `size`/`end`/`lane`).
|
|
1070
1139
|
*
|
|
1071
|
-
*
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
1074
|
-
*
|
|
1140
|
+
* `count`/object-identity are tracked per mounted call site via `useRef` (the
|
|
1141
|
+
* mock is invoked during render, so real hooks are safe to use here), so two
|
|
1142
|
+
* simultaneously-rendered virtualized components don't stomp on each other's
|
|
1143
|
+
* state the way a shared module-level variable would.
|
|
1144
|
+
*
|
|
1145
|
+
* Use this from a per-file `vi.mock` when a project-wide mock is not desirable
|
|
1146
|
+
* (e.g. sibling specs render virtualized components through real pagination
|
|
1147
|
+
* flows that would otherwise loop):
|
|
1148
|
+
*
|
|
1149
|
+
* @example
|
|
1150
|
+
* vi.mock("@tanstack/react-virtual", async () => {
|
|
1151
|
+
* const { tanstackReactVirtualMock } = await import("@trackunit/react-vite-test-setup");
|
|
1152
|
+
* return tanstackReactVirtualMock();
|
|
1153
|
+
* });
|
|
1154
|
+
*/
|
|
1155
|
+
const tanstackReactVirtualMock = async () => ({
|
|
1156
|
+
...(await vitest.vi.importActual("@tanstack/react-virtual")),
|
|
1157
|
+
useVirtualizer: ({ count }) => {
|
|
1158
|
+
const countRef = react$1.useRef(count);
|
|
1159
|
+
countRef.current = count;
|
|
1160
|
+
const instanceRef = react$1.useRef(null);
|
|
1161
|
+
if (!stableInstance || instanceRef.current === null) {
|
|
1162
|
+
instanceRef.current = createVirtualizer(() => countRef.current);
|
|
1163
|
+
}
|
|
1164
|
+
return instanceRef.current;
|
|
1165
|
+
},
|
|
1166
|
+
});
|
|
1167
|
+
/**
|
|
1168
|
+
* Mocks the `@tanstack/react-virtual` library for testing environments.
|
|
1169
|
+
*
|
|
1170
|
+
* Opt-in: the mock is registered via `vi.doMock` so it is NOT hoisted and only
|
|
1171
|
+
* takes effect once `setupTanstackReactVirtual()` is called from a test setup
|
|
1172
|
+
* file. Tests that need the real virtualizer (or their own mock) are
|
|
1173
|
+
* unaffected unless they explicitly call this.
|
|
1075
1174
|
*
|
|
1076
1175
|
* @example
|
|
1077
1176
|
* import { setupTanstackReactVirtual } from '@trackunit/react-vite-test-setup';
|
|
1078
1177
|
* setupTanstackReactVirtual();
|
|
1079
1178
|
*/
|
|
1080
1179
|
const setupTanstackReactVirtual = () => {
|
|
1081
|
-
vitest.vi.doMock("@tanstack/react-virtual", () => (
|
|
1082
|
-
useVirtualizer: ({ count }) => ({
|
|
1083
|
-
getVirtualItems: () => {
|
|
1084
|
-
const result = [];
|
|
1085
|
-
for (let i = 0; i < count; i++) {
|
|
1086
|
-
result.push({
|
|
1087
|
-
index: i,
|
|
1088
|
-
start: i * 40,
|
|
1089
|
-
key: i,
|
|
1090
|
-
measureRef: () => {
|
|
1091
|
-
/* noop */
|
|
1092
|
-
},
|
|
1093
|
-
});
|
|
1094
|
-
}
|
|
1095
|
-
return result;
|
|
1096
|
-
},
|
|
1097
|
-
getTotalSize: () => count,
|
|
1098
|
-
scrollToIndex: () => {
|
|
1099
|
-
/* noop */
|
|
1100
|
-
},
|
|
1101
|
-
scrollToOffset: () => {
|
|
1102
|
-
/* noop */
|
|
1103
|
-
},
|
|
1104
|
-
scrollToAlign: () => {
|
|
1105
|
-
/* noop */
|
|
1106
|
-
},
|
|
1107
|
-
scrollToItem: () => {
|
|
1108
|
-
/* noop */
|
|
1109
|
-
},
|
|
1110
|
-
resetAfterIndex: () => {
|
|
1111
|
-
/* noop */
|
|
1112
|
-
},
|
|
1113
|
-
resetAfterItem: () => {
|
|
1114
|
-
/* noop */
|
|
1115
|
-
},
|
|
1116
|
-
scrollTo: () => {
|
|
1117
|
-
/* noop */
|
|
1118
|
-
},
|
|
1119
|
-
measure: () => {
|
|
1120
|
-
/* noop */
|
|
1121
|
-
},
|
|
1122
|
-
measureElement: () => 42,
|
|
1123
|
-
}),
|
|
1124
|
-
}));
|
|
1180
|
+
vitest.vi.doMock("@tanstack/react-virtual", async () => tanstackReactVirtualMock());
|
|
1125
1181
|
};
|
|
1126
1182
|
|
|
1127
1183
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -1360,6 +1416,9 @@ const setupTanstackReactRouter = () => {
|
|
|
1360
1416
|
exports.configureReliableAsyncUtils = configureReliableAsyncUtils;
|
|
1361
1417
|
exports.createMockClickEvent = createMockClickEvent;
|
|
1362
1418
|
exports.createMockMapboxMap = createMockMapboxMap;
|
|
1419
|
+
exports.resetTanstackReactVirtualMock = resetTanstackReactVirtualMock;
|
|
1420
|
+
exports.setTanstackReactVirtualItems = setTanstackReactVirtualItems;
|
|
1421
|
+
exports.setTanstackReactVirtualStableInstance = setTanstackReactVirtualStableInstance;
|
|
1363
1422
|
exports.setupAllMocks = setupAllMocks;
|
|
1364
1423
|
exports.setupBasicMocks = setupBasicMocks;
|
|
1365
1424
|
exports.setupCanvasMock = setupCanvasMock;
|
|
@@ -1379,3 +1438,4 @@ exports.setupTimeAndLanguage = setupTimeAndLanguage;
|
|
|
1379
1438
|
exports.setupTimeZone = setupTimeZone;
|
|
1380
1439
|
exports.setupTranslations = setupTranslations;
|
|
1381
1440
|
exports.setupWebStreams = setupWebStreams;
|
|
1441
|
+
exports.tanstackReactVirtualMock = tanstackReactVirtualMock;
|
package/index.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ import failOnConsole from 'vitest-fail-on-console';
|
|
|
5
5
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
6
6
|
import '@testing-library/jest-dom/vitest';
|
|
7
7
|
import { TextEncoder, TextDecoder } from 'util';
|
|
8
|
-
import { isValidElement, cloneElement } from 'react';
|
|
8
|
+
import { isValidElement, cloneElement, useRef } from 'react';
|
|
9
9
|
import * as reactI18next from 'react-i18next';
|
|
10
10
|
import { Temporal } from '@js-temporal/polyfill';
|
|
11
11
|
import { Globals } from '@react-spring/web';
|
|
@@ -1040,67 +1040,123 @@ const setupReactVirtualizedAutoSizer = () => {
|
|
|
1040
1040
|
vi.doMock("react-virtualized-auto-sizer", () => ({ children }) => children({ height: 600, width: 600, scaledWidth: 600, scaledHeight: 600 }));
|
|
1041
1041
|
};
|
|
1042
1042
|
|
|
1043
|
+
const ITEM_SIZE = 40;
|
|
1044
|
+
// Module-level: explicit opt-in test controls, set from outside the React
|
|
1045
|
+
// tree by the test currently under test. Unlike `count`/instance identity
|
|
1046
|
+
// (which must be isolated per mounted virtualizer, see `useVirtualizer`
|
|
1047
|
+
// below), these are intentionally global since only one hook-under-test
|
|
1048
|
+
// exercises them at a time.
|
|
1049
|
+
let virtualItemsOverride;
|
|
1050
|
+
let stableInstance = false;
|
|
1051
|
+
const noop = () => {
|
|
1052
|
+
/* noop */
|
|
1053
|
+
};
|
|
1054
|
+
const createVirtualItems = (count) => {
|
|
1055
|
+
const result = [];
|
|
1056
|
+
for (let i = 0; i < count; i++) {
|
|
1057
|
+
result.push({
|
|
1058
|
+
index: i,
|
|
1059
|
+
start: i * ITEM_SIZE,
|
|
1060
|
+
end: (i + 1) * ITEM_SIZE,
|
|
1061
|
+
size: ITEM_SIZE,
|
|
1062
|
+
lane: 0,
|
|
1063
|
+
key: i,
|
|
1064
|
+
measureRef: noop,
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
return result;
|
|
1068
|
+
};
|
|
1069
|
+
const createVirtualizer = (getCount) => ({
|
|
1070
|
+
getVirtualItems: () => virtualItemsOverride ?? createVirtualItems(getCount()),
|
|
1071
|
+
getTotalSize: () => getCount() * ITEM_SIZE,
|
|
1072
|
+
// Callback ref exposed by TanStack Virtual's directDomUpdates mode. The
|
|
1073
|
+
// real one positions rows/sizes the container directly; the mock is a
|
|
1074
|
+
// no-op so consumers can attach it without the virtualizer running.
|
|
1075
|
+
containerRef: noop,
|
|
1076
|
+
scrollOffset: 0,
|
|
1077
|
+
isScrolling: false,
|
|
1078
|
+
scrollToIndex: noop,
|
|
1079
|
+
scrollToOffset: noop,
|
|
1080
|
+
scrollToAlign: noop,
|
|
1081
|
+
scrollToItem: noop,
|
|
1082
|
+
resetAfterIndex: noop,
|
|
1083
|
+
resetAfterItem: noop,
|
|
1084
|
+
scrollTo: noop,
|
|
1085
|
+
measure: noop,
|
|
1086
|
+
measureElement: () => 42,
|
|
1087
|
+
});
|
|
1043
1088
|
/**
|
|
1044
|
-
*
|
|
1089
|
+
* Overrides the virtual items returned by every mocked virtualizer. Pass
|
|
1090
|
+
* `undefined` to fall back to the deterministic full-window items derived
|
|
1091
|
+
* from `count`.
|
|
1092
|
+
*/
|
|
1093
|
+
const setTanstackReactVirtualItems = (virtualItems) => {
|
|
1094
|
+
virtualItemsOverride = virtualItems;
|
|
1095
|
+
};
|
|
1096
|
+
/**
|
|
1097
|
+
* Controls whether `useVirtualizer` returns a referentially stable object
|
|
1098
|
+
* across re-renders of the same mounted instance, mirroring the real
|
|
1099
|
+
* virtualizer's in-place-update behaviour. Defaults to `false` (a new object
|
|
1100
|
+
* every render).
|
|
1101
|
+
*/
|
|
1102
|
+
const setTanstackReactVirtualStableInstance = (isStableInstance) => {
|
|
1103
|
+
stableInstance = isStableInstance;
|
|
1104
|
+
};
|
|
1105
|
+
/** Resets all mock test controls set via `setTanstackReactVirtualItems`/`setTanstackReactVirtualStableInstance`. */
|
|
1106
|
+
const resetTanstackReactVirtualMock = () => {
|
|
1107
|
+
virtualItemsOverride = undefined;
|
|
1108
|
+
stableInstance = false;
|
|
1109
|
+
};
|
|
1110
|
+
/**
|
|
1111
|
+
* Builds the mock module object for `@tanstack/react-virtual`.
|
|
1045
1112
|
*
|
|
1046
|
-
*
|
|
1047
|
-
* returns every item (no real DOM virtualisation), so tests can assert on
|
|
1048
|
-
*
|
|
1113
|
+
* `useVirtualizer` is replaced with a deterministic implementation that
|
|
1114
|
+
* returns every item (no real DOM virtualisation), so tests can assert on the
|
|
1115
|
+
* full rendered list without worrying about scroll-driven windowing. The
|
|
1116
|
+
* shape mirrors the fields consumed after the `directDomUpdates` migration
|
|
1117
|
+
* (`containerRef`, `scrollOffset`, `isScrolling`, and item `size`/`end`/`lane`).
|
|
1049
1118
|
*
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1119
|
+
* `count`/object-identity are tracked per mounted call site via `useRef` (the
|
|
1120
|
+
* mock is invoked during render, so real hooks are safe to use here), so two
|
|
1121
|
+
* simultaneously-rendered virtualized components don't stomp on each other's
|
|
1122
|
+
* state the way a shared module-level variable would.
|
|
1123
|
+
*
|
|
1124
|
+
* Use this from a per-file `vi.mock` when a project-wide mock is not desirable
|
|
1125
|
+
* (e.g. sibling specs render virtualized components through real pagination
|
|
1126
|
+
* flows that would otherwise loop):
|
|
1127
|
+
*
|
|
1128
|
+
* @example
|
|
1129
|
+
* vi.mock("@tanstack/react-virtual", async () => {
|
|
1130
|
+
* const { tanstackReactVirtualMock } = await import("@trackunit/react-vite-test-setup");
|
|
1131
|
+
* return tanstackReactVirtualMock();
|
|
1132
|
+
* });
|
|
1133
|
+
*/
|
|
1134
|
+
const tanstackReactVirtualMock = async () => ({
|
|
1135
|
+
...(await vi.importActual("@tanstack/react-virtual")),
|
|
1136
|
+
useVirtualizer: ({ count }) => {
|
|
1137
|
+
const countRef = useRef(count);
|
|
1138
|
+
countRef.current = count;
|
|
1139
|
+
const instanceRef = useRef(null);
|
|
1140
|
+
if (!stableInstance || instanceRef.current === null) {
|
|
1141
|
+
instanceRef.current = createVirtualizer(() => countRef.current);
|
|
1142
|
+
}
|
|
1143
|
+
return instanceRef.current;
|
|
1144
|
+
},
|
|
1145
|
+
});
|
|
1146
|
+
/**
|
|
1147
|
+
* Mocks the `@tanstack/react-virtual` library for testing environments.
|
|
1148
|
+
*
|
|
1149
|
+
* Opt-in: the mock is registered via `vi.doMock` so it is NOT hoisted and only
|
|
1150
|
+
* takes effect once `setupTanstackReactVirtual()` is called from a test setup
|
|
1151
|
+
* file. Tests that need the real virtualizer (or their own mock) are
|
|
1152
|
+
* unaffected unless they explicitly call this.
|
|
1054
1153
|
*
|
|
1055
1154
|
* @example
|
|
1056
1155
|
* import { setupTanstackReactVirtual } from '@trackunit/react-vite-test-setup';
|
|
1057
1156
|
* setupTanstackReactVirtual();
|
|
1058
1157
|
*/
|
|
1059
1158
|
const setupTanstackReactVirtual = () => {
|
|
1060
|
-
vi.doMock("@tanstack/react-virtual", () => (
|
|
1061
|
-
useVirtualizer: ({ count }) => ({
|
|
1062
|
-
getVirtualItems: () => {
|
|
1063
|
-
const result = [];
|
|
1064
|
-
for (let i = 0; i < count; i++) {
|
|
1065
|
-
result.push({
|
|
1066
|
-
index: i,
|
|
1067
|
-
start: i * 40,
|
|
1068
|
-
key: i,
|
|
1069
|
-
measureRef: () => {
|
|
1070
|
-
/* noop */
|
|
1071
|
-
},
|
|
1072
|
-
});
|
|
1073
|
-
}
|
|
1074
|
-
return result;
|
|
1075
|
-
},
|
|
1076
|
-
getTotalSize: () => count,
|
|
1077
|
-
scrollToIndex: () => {
|
|
1078
|
-
/* noop */
|
|
1079
|
-
},
|
|
1080
|
-
scrollToOffset: () => {
|
|
1081
|
-
/* noop */
|
|
1082
|
-
},
|
|
1083
|
-
scrollToAlign: () => {
|
|
1084
|
-
/* noop */
|
|
1085
|
-
},
|
|
1086
|
-
scrollToItem: () => {
|
|
1087
|
-
/* noop */
|
|
1088
|
-
},
|
|
1089
|
-
resetAfterIndex: () => {
|
|
1090
|
-
/* noop */
|
|
1091
|
-
},
|
|
1092
|
-
resetAfterItem: () => {
|
|
1093
|
-
/* noop */
|
|
1094
|
-
},
|
|
1095
|
-
scrollTo: () => {
|
|
1096
|
-
/* noop */
|
|
1097
|
-
},
|
|
1098
|
-
measure: () => {
|
|
1099
|
-
/* noop */
|
|
1100
|
-
},
|
|
1101
|
-
measureElement: () => 42,
|
|
1102
|
-
}),
|
|
1103
|
-
}));
|
|
1159
|
+
vi.doMock("@tanstack/react-virtual", async () => tanstackReactVirtualMock());
|
|
1104
1160
|
};
|
|
1105
1161
|
|
|
1106
1162
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
@@ -1336,4 +1392,4 @@ const setupTanstackReactRouter = () => {
|
|
|
1336
1392
|
}));
|
|
1337
1393
|
};
|
|
1338
1394
|
|
|
1339
|
-
export { configureReliableAsyncUtils, createMockClickEvent, createMockMapboxMap, setupAllMocks, setupBasicMocks, setupCanvasMock, setupDefaultMocks, setupFailOnConsole, setupGoogleMaps, setupHelmetMock, setupIntersectionObserver, setupMapbox, setupMatchMediaMock, setupReactTestingLibrary, setupReactVirtualizedAutoSizer, setupResizeObserver, setupTanstackReactRouter, setupTanstackReactVirtual, setupTimeAndLanguage, setupTimeZone, setupTranslations, setupWebStreams };
|
|
1395
|
+
export { configureReliableAsyncUtils, createMockClickEvent, createMockMapboxMap, resetTanstackReactVirtualMock, setTanstackReactVirtualItems, setTanstackReactVirtualStableInstance, setupAllMocks, setupBasicMocks, setupCanvasMock, setupDefaultMocks, setupFailOnConsole, setupGoogleMaps, setupHelmetMock, setupIntersectionObserver, setupMapbox, setupMatchMediaMock, setupReactTestingLibrary, setupReactVirtualizedAutoSizer, setupResizeObserver, setupTanstackReactRouter, setupTanstackReactVirtual, setupTimeAndLanguage, setupTimeZone, setupTranslations, setupWebStreams, tanstackReactVirtualMock };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-vite-test-setup",
|
|
3
3
|
"description": "Test setup utilities for React applications",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.61",
|
|
5
5
|
"repository": "https://github.com/Trackunit/manager",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
7
7
|
"engines": {
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"@googlemaps/jest-mocks": "2.22.6",
|
|
24
24
|
"@js-temporal/polyfill": "^0.5.1",
|
|
25
25
|
"@react-spring/web": "9.7.5",
|
|
26
|
+
"@tanstack/react-virtual": "^3.14.3",
|
|
26
27
|
"@testing-library/jest-dom": "^6.9.1",
|
|
27
28
|
"@testing-library/react": "16.2.0",
|
|
28
29
|
"@vis.gl/react-google-maps": "^1.7.1",
|
|
@@ -1,17 +1,85 @@
|
|
|
1
|
+
export type TanstackReactVirtualMockItem = {
|
|
2
|
+
readonly index: number;
|
|
3
|
+
readonly start: number;
|
|
4
|
+
readonly end: number;
|
|
5
|
+
readonly size: number;
|
|
6
|
+
readonly lane: number;
|
|
7
|
+
readonly key: number;
|
|
8
|
+
readonly measureRef: () => void;
|
|
9
|
+
};
|
|
10
|
+
type TanstackReactVirtualMockVirtualizer = {
|
|
11
|
+
readonly getVirtualItems: () => ReadonlyArray<TanstackReactVirtualMockItem>;
|
|
12
|
+
readonly getTotalSize: () => number;
|
|
13
|
+
readonly containerRef: () => void;
|
|
14
|
+
readonly scrollOffset: number;
|
|
15
|
+
readonly isScrolling: boolean;
|
|
16
|
+
readonly scrollToIndex: () => void;
|
|
17
|
+
readonly scrollToOffset: () => void;
|
|
18
|
+
readonly scrollToAlign: () => void;
|
|
19
|
+
readonly scrollToItem: () => void;
|
|
20
|
+
readonly resetAfterIndex: () => void;
|
|
21
|
+
readonly resetAfterItem: () => void;
|
|
22
|
+
readonly scrollTo: () => void;
|
|
23
|
+
readonly measure: () => void;
|
|
24
|
+
readonly measureElement: () => number;
|
|
25
|
+
};
|
|
26
|
+
type UseVirtualizerOptions = {
|
|
27
|
+
readonly count: number;
|
|
28
|
+
};
|
|
29
|
+
type TanstackReactVirtualMockModule = {
|
|
30
|
+
readonly useVirtualizer: (options: UseVirtualizerOptions) => TanstackReactVirtualMockVirtualizer;
|
|
31
|
+
};
|
|
1
32
|
/**
|
|
2
|
-
*
|
|
33
|
+
* Overrides the virtual items returned by every mocked virtualizer. Pass
|
|
34
|
+
* `undefined` to fall back to the deterministic full-window items derived
|
|
35
|
+
* from `count`.
|
|
36
|
+
*/
|
|
37
|
+
export declare const setTanstackReactVirtualItems: (virtualItems: ReadonlyArray<TanstackReactVirtualMockItem> | undefined) => void;
|
|
38
|
+
/**
|
|
39
|
+
* Controls whether `useVirtualizer` returns a referentially stable object
|
|
40
|
+
* across re-renders of the same mounted instance, mirroring the real
|
|
41
|
+
* virtualizer's in-place-update behaviour. Defaults to `false` (a new object
|
|
42
|
+
* every render).
|
|
43
|
+
*/
|
|
44
|
+
export declare const setTanstackReactVirtualStableInstance: (isStableInstance: boolean) => void;
|
|
45
|
+
/** Resets all mock test controls set via `setTanstackReactVirtualItems`/`setTanstackReactVirtualStableInstance`. */
|
|
46
|
+
export declare const resetTanstackReactVirtualMock: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Builds the mock module object for `@tanstack/react-virtual`.
|
|
49
|
+
*
|
|
50
|
+
* `useVirtualizer` is replaced with a deterministic implementation that
|
|
51
|
+
* returns every item (no real DOM virtualisation), so tests can assert on the
|
|
52
|
+
* full rendered list without worrying about scroll-driven windowing. The
|
|
53
|
+
* shape mirrors the fields consumed after the `directDomUpdates` migration
|
|
54
|
+
* (`containerRef`, `scrollOffset`, `isScrolling`, and item `size`/`end`/`lane`).
|
|
3
55
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
56
|
+
* `count`/object-identity are tracked per mounted call site via `useRef` (the
|
|
57
|
+
* mock is invoked during render, so real hooks are safe to use here), so two
|
|
58
|
+
* simultaneously-rendered virtualized components don't stomp on each other's
|
|
59
|
+
* state the way a shared module-level variable would.
|
|
60
|
+
*
|
|
61
|
+
* Use this from a per-file `vi.mock` when a project-wide mock is not desirable
|
|
62
|
+
* (e.g. sibling specs render virtualized components through real pagination
|
|
63
|
+
* flows that would otherwise loop):
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* vi.mock("@tanstack/react-virtual", async () => {
|
|
67
|
+
* const { tanstackReactVirtualMock } = await import("@trackunit/react-vite-test-setup");
|
|
68
|
+
* return tanstackReactVirtualMock();
|
|
69
|
+
* });
|
|
70
|
+
*/
|
|
71
|
+
export declare const tanstackReactVirtualMock: () => Promise<TanstackReactVirtualMockModule>;
|
|
72
|
+
/**
|
|
73
|
+
* Mocks the `@tanstack/react-virtual` library for testing environments.
|
|
7
74
|
*
|
|
8
|
-
* Opt-in: the mock is registered via `vi.doMock` so it is
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
75
|
+
* Opt-in: the mock is registered via `vi.doMock` so it is NOT hoisted and only
|
|
76
|
+
* takes effect once `setupTanstackReactVirtual()` is called from a test setup
|
|
77
|
+
* file. Tests that need the real virtualizer (or their own mock) are
|
|
78
|
+
* unaffected unless they explicitly call this.
|
|
12
79
|
*
|
|
13
80
|
* @example
|
|
14
81
|
* import { setupTanstackReactVirtual } from '@trackunit/react-vite-test-setup';
|
|
15
82
|
* setupTanstackReactVirtual();
|
|
16
83
|
*/
|
|
17
84
|
export declare const setupTanstackReactVirtual: () => void;
|
|
85
|
+
export {};
|