Skip to content

Commit 9096e71

Browse files
committed
test(selectors): count find/every/indexOf-class scans in the traversal gate
The replay traversal counter only watched filter/map/flatMap/forEach/reduce/ some/iterator, so a redundant full-tree scan expressed via find, every, findIndex/findLast(Index), includes, indexOf, or reduceRight stayed green. Expand SCAN_METHODS to the full scan surface; planted-red demonstrated by injecting a single nodes.find() into resolveRecordedTarget (gate fails with find: 1) and reverting.
1 parent 6a9678c commit 9096e71

1 file changed

Lines changed: 38 additions & 11 deletions

File tree

‎packages/selectors/src/index.test.ts‎

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,33 @@ test('recorded-target resolution keeps the matched domain from the alternative t
136136
* Functions are bound to the target so a counted traversal cannot re-enter the
137137
* proxy.
138138
*/
139-
const SCAN_METHODS = ['filter', 'map', 'flatMap', 'forEach', 'reduce', 'some'] as const;
140-
type ScanPasses = { iterated: number } & Record<(typeof SCAN_METHODS)[number], number>;
139+
const SCAN_METHODS = [
140+
'filter',
141+
'map',
142+
'flatMap',
143+
'forEach',
144+
'reduce',
145+
'reduceRight',
146+
'some',
147+
'every',
148+
'find',
149+
'findIndex',
150+
'findLast',
151+
'findLastIndex',
152+
'includes',
153+
'indexOf',
154+
] as const;
155+
type ScanMethod = (typeof SCAN_METHODS)[number];
156+
type ScanPasses = { iterated: number } & Record<ScanMethod, number>;
141157

142158
function observeTreeTraversals(nodes: SnapshotNode[]): {
143159
observed: SnapshotNode[];
144160
passes: ScanPasses;
145161
} {
146-
const passes: ScanPasses = {
147-
iterated: 0,
148-
filter: 0,
149-
map: 0,
150-
flatMap: 0,
151-
forEach: 0,
152-
reduce: 0,
153-
some: 0,
154-
};
162+
const passes = Object.fromEntries([
163+
['iterated', 0],
164+
...SCAN_METHODS.map((method) => [method, 0]),
165+
]) as ScanPasses;
155166
const observed = new Proxy(nodes, {
156167
get(target, property) {
157168
if (property === Symbol.iterator) passes.iterated += 1;
@@ -181,7 +192,15 @@ test('recorded-target resolution adds no second matching pass per selector alter
181192
flatMap: 0,
182193
forEach: 0,
183194
reduce: 0,
195+
reduceRight: 0,
184196
some: 0,
197+
every: 0,
198+
find: 0,
199+
findIndex: 0,
200+
findLast: 0,
201+
findLastIndex: 0,
202+
includes: 0,
203+
indexOf: 0,
185204
});
186205

187206
const unresolved = observeTreeTraversals(nodes);
@@ -200,7 +219,15 @@ test('recorded-target resolution adds no second matching pass per selector alter
200219
flatMap: 8,
201220
forEach: 0,
202221
reduce: 0,
222+
reduceRight: 0,
203223
some: 0,
224+
every: 0,
225+
find: 0,
226+
findIndex: 0,
227+
findLast: 0,
228+
findLastIndex: 0,
229+
includes: 0,
230+
indexOf: 0,
204231
});
205232
});
206233

0 commit comments

Comments
 (0)