File tree Expand file tree Collapse file tree 4 files changed +23
-5
lines changed
packages/toolkit/src/query/core Expand file tree Collapse file tree 4 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,15 @@ export const buildBatchedActionsHandler: InternalHandlerBuilder<
155155
156156 let actionShouldContinue = true
157157
158+ // HACK Sneak the test-only polling state back out
159+ if (
160+ process . env . NODE_ENV === 'test' &&
161+ typeof action . type === 'string' &&
162+ action . type === `${ api . reducerPath } /getPolling`
163+ ) {
164+ return [ false , internalState . currentPolls ] as any
165+ }
166+
158167 if ( didMutate ) {
159168 if ( ! updateSyncTimer ) {
160169 // We only use the subscription state for the Redux DevTools at this point,
Original file line number Diff line number Diff line change @@ -21,11 +21,7 @@ export const buildPollingHandler: InternalHandlerBuilder = ({
2121 refetchQuery,
2222 internalState,
2323} ) => {
24- const currentPolls : QueryStateMeta < {
25- nextPollTimestamp : number
26- timeout ?: TimeoutId
27- pollingInterval : number
28- } > = { }
24+ const { currentPolls } = internalState
2925
3026 const { currentSubscriptions } = internalState
3127
@@ -120,6 +116,13 @@ export const buildPollingHandler: InternalHandlerBuilder = ({
120116
121117 const { lowestPollingInterval } = findLowestPollingInterval ( subscriptions )
122118
119+ // HACK add extra data to track how many times this has been called in tests
120+ if ( process . env . NODE_ENV === 'test' ) {
121+ const updateCounters = ( ( currentPolls as any ) . pollUpdateCounters ??= { } )
122+ updateCounters [ queryCacheKey ] ??= 0
123+ updateCounters [ queryCacheKey ] ++
124+ }
125+
123126 if ( ! Number . isFinite ( lowestPollingInterval ) ) {
124127 cleanupPollForKey ( queryCacheKey )
125128 return
Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ export type TimeoutId = ReturnType<typeof setTimeout>
3939
4040export interface InternalMiddlewareState {
4141 currentSubscriptions : SubscriptionInternalState
42+ currentPolls : QueryStateMeta < {
43+ nextPollTimestamp : number
44+ timeout ?: TimeoutId
45+ pollingInterval : number
46+ } >
4247 runningQueries : Map <
4348 Dispatch ,
4449 Record <
Original file line number Diff line number Diff line change @@ -621,6 +621,7 @@ export const coreModule = ({
621621
622622 const internalState : InternalMiddlewareState = {
623623 currentSubscriptions : new Map ( ) ,
624+ currentPolls : { } ,
624625 runningQueries : new Map ( ) ,
625626 runningMutations : new Map ( ) ,
626627 }
You can’t perform that action at this time.
0 commit comments