Merge branch 'renovate/all-minor-patch' into 'main'
[ProtonMail-WebClient.git] / packages / testing / lib / context / store.ts
blobe4ffc4e87baa480f9112e71156f5c7a6c3b85f2f
1 import { combineReducers, configureStore, createListenerMiddleware } from '@reduxjs/toolkit';
3 import { sharedReducers } from '@proton/redux-shared-store';
4 import type { ProtonThunkArguments } from '@proton/redux-shared-store-types';
5 import { ignoredActions, ignoredPaths } from '@proton/redux-shared-store/sharedSerializable';
7 export const extraThunkArguments = {} as ProtonThunkArguments;
9 export const listenerMiddleware = createListenerMiddleware();
11 const rootReducer = combineReducers({
12     ...sharedReducers,
13 });
14 export type RootState = ReturnType<typeof rootReducer>;
15 export const setupStore = ({ preloadedState }: { preloadedState: Partial<RootState> }) => {
16     return configureStore({
17         preloadedState,
18         reducer: rootReducer,
19         middleware: (getDefaultMiddleware) =>
20             getDefaultMiddleware({
21                 serializableCheck: {
22                     ignoredActions: [...ignoredActions],
23                     ignoredPaths: [...ignoredPaths],
24                 },
25                 thunk: { extraArgument: extraThunkArguments },
26             }).prepend(listenerMiddleware.middleware),
27     });
30 export const extendStore = (newThunkArguments: Partial<ProtonThunkArguments>) => {
31     Object.assign(extraThunkArguments, newThunkArguments);