Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp type tests setup #4095

Merged
merged 112 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
5cc0eb2
Remove extra tsconfig files
aryaemami59 Jan 18, 2024
6339e65
Bring out `tsconfig.typetests.json` to root level
aryaemami59 Jan 18, 2024
13423fc
Update `tsconfig.test.json`
aryaemami59 Jan 18, 2024
d30bb70
Fix NPM scripts
aryaemami59 Jan 18, 2024
7be80cf
Fix some type issues inside `module.ts`
aryaemami59 Jan 18, 2024
6a2b72a
Rename `tsconfig.typetests.json` file to `tsconfig.json`
aryaemami59 Jan 18, 2024
bbf87f3
Fix `type-tests` NPM script
aryaemami59 Jan 18, 2024
0b6deb5
Add `// @ts-expect-error` for now
aryaemami59 Jan 18, 2024
756940e
Change `// @ts-expect-error` to `// @ts-ignore` to work around the bu…
aryaemami59 Jan 18, 2024
8785685
Add more ts-ignores
aryaemami59 Jan 18, 2024
795a9f0
Add some more `// @ts-ignore`s
aryaemami59 Jan 19, 2024
237119a
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit int…
aryaemami59 Jan 20, 2024
bfb864a
Make `tsconfig.build.json` the default `tsconfig` in tsup configs
aryaemami59 Jan 20, 2024
052a512
Add back `formatProdErrorMessage` to `src\query\react\index.ts`
aryaemami59 Jan 20, 2024
18d5f59
Fix type tests excluding wrong files
aryaemami59 Jan 20, 2024
f6809fa
Rename `vitest.config.ts` to `vitest.config.mts`
aryaemami59 Jan 20, 2024
50c0538
Change `Node10` to `Node` as TS versions before 5 do not support it
aryaemami59 Jan 20, 2024
eb019a6
Remove duplicate fields in `tsconfig.test.json` for simplicity
aryaemami59 Jan 20, 2024
bef8487
Change `vitest.config.ts` to `vitest.config.mts` inside `tests.yml` file
aryaemami59 Jan 20, 2024
bf2500c
Change `vitest.config.ts` to `vitest.config.mts` inside `tests.yml` file
aryaemami59 Jan 20, 2024
49efa87
Add `@ts-ignore` directive to `satisfies` operator inside `tsup.confi…
aryaemami59 Jan 20, 2024
d5db295
Remove `interopDefault` from `vitest.config.mts` as it is enabled by …
aryaemami59 Jan 20, 2024
2c5d7a7
Replace the deprecated `deps.inline` with `server.deps.inline`
aryaemami59 Jan 20, 2024
06ddb7c
Remove `satisfies` operator to silence TS errors for TS 4.7 and 4.8
aryaemami59 Jan 20, 2024
a46e9fc
Rename `vitest.setup.js` to `vitest.setup.ts`
aryaemami59 Jan 20, 2024
adefdaa
Add clean NPM script
aryaemami59 Jan 20, 2024
27740fc
Add `test:watch` NPM script
aryaemami59 Jan 20, 2024
a68d2a2
Add `vitest.setup.ts` to `setupFiles` in `vitest.config.mts`
aryaemami59 Jan 20, 2024
e2bf45a
Bump `node-fetch` dev dependency
aryaemami59 Jan 20, 2024
bb3604b
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit int…
aryaemami59 Jan 20, 2024
407904d
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit int…
aryaemami59 Jan 22, 2024
90a7d92
Bump msw
aryaemami59 Jan 23, 2024
aa0eef7
Fix stubbing globals in `vitest.setup.ts`
aryaemami59 Jan 23, 2024
15dfd2c
Fix handlers to be compatible with latest version of `msw`
aryaemami59 Jan 23, 2024
0e99f83
Split up handlers and server files
aryaemami59 Jan 23, 2024
42ffa52
Use codemods provided by msw to modernize msw syntax
aryaemami59 Jan 23, 2024
4fdae59
Skip faulty tests for now
aryaemami59 Jan 23, 2024
1db9130
Bump TS version for toolkit
aryaemami59 Jan 23, 2024
c8e1961
Convert `createSlice` skip test to todo test
aryaemami59 Jan 23, 2024
7e54e5c
Fix timeout tests
aryaemami59 Jan 23, 2024
4237e77
Fix `FormData` tests
aryaemami59 Jan 23, 2024
75b5e2d
Segregate `buildMiddleware` type tests and runtime tests
aryaemami59 Jan 23, 2024
f0a9ef9
Rename `buildSelector.test.ts` to `buildSelector.test-d.ts`
aryaemami59 Jan 23, 2024
0017cbe
Segregate `retry.test.ts` runtime and type tests
aryaemami59 Jan 23, 2024
5563f1c
Rename `unionTypes.test.ts` to `unionTypes.test-d.ts`
aryaemami59 Jan 23, 2024
931f6f6
Fix export issue in `retry.test-d.ts`
aryaemami59 Jan 23, 2024
771a308
Fix type tests inside `unionTypes.test-d.ts`
aryaemami59 Jan 23, 2024
f0dcf26
Add `customMatchers.d.ts` ambient declaration file
aryaemami59 Jan 23, 2024
41054fe
Move `src\query\tests\helpers.tsx` to `src\tests\utils\helpers.tsx`
aryaemami59 Jan 23, 2024
8698719
Move `typeTestHelpers.ts` file into `tests/utils` folder
aryaemami59 Jan 23, 2024
757d2d7
Add `"react-jsx"` to `tsconfig.test.json`
aryaemami59 Jan 23, 2024
c345514
Segregate type and runtime test utilities inside `tests/utils` folder
aryaemami59 Jan 23, 2024
78c55c7
Rename `customMatchers.d.ts` to `vitest.d.ts`
aryaemami59 Jan 23, 2024
75906ee
Fix `helpers.tsx` imports
aryaemami59 Jan 23, 2024
073904b
Fix ambient declaration issue
aryaemami59 Jan 23, 2024
5f14513
Try to fix ambient declarations issue
aryaemami59 Jan 23, 2024
eba8c4e
Remove extra `vitest.d.ts` file
aryaemami59 Jan 23, 2024
c81bf7c
Revert "Remove extra `vitest.d.ts` file"
aryaemami59 Jan 23, 2024
5e6921b
Add back `namespace jest` declaration merging
aryaemami59 Jan 23, 2024
35b7ae1
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit int…
aryaemami59 Jan 23, 2024
1960281
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit int…
aryaemami59 Jan 23, 2024
53ac252
Revert "Rename `vitest.config.ts` to `vitest.config.mts`"
aryaemami59 Jan 23, 2024
518db42
Revert "Change `vitest.config.ts` to `vitest.config.mts` inside `test…
aryaemami59 Jan 23, 2024
3fc140e
Revert "Change `vitest.config.ts` to `vitest.config.mts` inside `test…
aryaemami59 Jan 23, 2024
03c183d
Revert "Remove `interopDefault` from `vitest.config.mts` as it is ena…
aryaemami59 Jan 23, 2024
04a73e4
Revert "Replace the deprecated `deps.inline` with `server.deps.inline`"
aryaemami59 Jan 23, 2024
a3eb0f6
Revert "Add `test:watch` NPM script"
aryaemami59 Jan 23, 2024
bf5c147
Revert "Remove `interopDefault` from `vitest.config.mts` as it is ena…
aryaemami59 Jan 23, 2024
07288a5
Revert "Bump `node-fetch` dev dependency"
aryaemami59 Jan 23, 2024
e98cee5
Revert "Fix handlers to be compatible with latest version of `msw`"
aryaemami59 Jan 23, 2024
ab772d0
Revert "Split up handlers and server files"
aryaemami59 Jan 23, 2024
767047d
Revert "Use codemods provided by msw to modernize msw syntax"
aryaemami59 Jan 23, 2024
d0e893f
Update lockfile
aryaemami59 Jan 23, 2024
e5220ca
Remove extra `vitest.d.ts` file
aryaemami59 Jan 23, 2024
5aa0997
Revert changes inside `apiProvider.test.tsx`
aryaemami59 Jan 23, 2024
6a66e30
Revert changes inside `helpers.tsx`
aryaemami59 Jan 23, 2024
6f88342
Revert changes inside `useMutation-fixedCacheKey.test.tsx`
aryaemami59 Jan 23, 2024
464b1ad
Revert changes inside `refetchingBehaviors.test.tsx`
aryaemami59 Jan 23, 2024
6b8e29f
Revert changes inside `raceConditions.test.ts`
aryaemami59 Jan 23, 2024
14370c9
Revert changes inside `queryLifecycle.test.tsx`
aryaemami59 Jan 23, 2024
f257c01
Revert changes inside `queryFn.test.tsx`
aryaemami59 Jan 23, 2024
ebf3916
Revert changes inside `polling.test.tsx`
aryaemami59 Jan 23, 2024
d7ea728
Revert changes inside `optimisticUpserts.test.tsx`
aryaemami59 Jan 23, 2024
3e59d90
Revert changes inside `optimisticUpdates.test.tsx`
aryaemami59 Jan 23, 2024
a27496b
Revert changes inside `invalidation.test.tsx`
aryaemami59 Jan 23, 2024
6eb5603
Revert changes inside `fetchBaseQuery.test.tsx`
aryaemami59 Jan 23, 2024
190adc0
Revert changes inside `errorHandling.test.tsx`
aryaemami59 Jan 23, 2024
cdb8df8
Revert changes inside `createApi.test.ts`
aryaemami59 Jan 23, 2024
4d42944
Revert changes inside `buildSlice.test.ts`
aryaemami59 Jan 23, 2024
f3d2c4b
Revert changes inside `buildMiddleware.test.tsx`
aryaemami59 Jan 23, 2024
944c0c7
Revert changes inside `buildHooks.test.tsx`
aryaemami59 Jan 23, 2024
2154d33
Revert changes inside `buildCreateApi.test.tsx`
aryaemami59 Jan 23, 2024
b87f710
Fix `delay` related issues inside `optimisticUpserts.test.tsx`
aryaemami59 Jan 23, 2024
c8e1fc3
Add `test:watch` NPM script
aryaemami59 Jan 23, 2024
2d53ca5
Fix import issue in `createApi.test.ts`
aryaemami59 Jan 23, 2024
d0925af
Fix Vitest type checker bug
aryaemami59 Jan 23, 2024
9676b8e
Perform type checking with runtime tests
aryaemami59 Jan 23, 2024
8d54f12
Make `tsconfig.test.json` responsible for running type tests during CI
aryaemami59 Jan 23, 2024
6b0eca6
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit int…
aryaemami59 Jan 24, 2024
6ec0d4e
Fix remaining import issues in test files
aryaemami59 Jan 24, 2024
01bcfcc
Add back `CustomMatchers.d.ts` ambient declaration file
aryaemami59 Jan 24, 2024
8597a71
Remove `declare global` from `helpers.tsx`
aryaemami59 Jan 24, 2024
43b5f7e
Merge branch 'master' of https://github.com/reduxjs/redux-toolkit int…
aryaemami59 Jan 25, 2024
325d540
Include `CustomMatchers.d.ts` in `tsconfig.test.json`
aryaemami59 Jan 25, 2024
81c1ad7
Add global module augmentation for `namespace jest`
aryaemami59 Jan 25, 2024
d9fb5b6
Remove some `@ts-ignore`s
aryaemami59 Jan 25, 2024
288b5e7
rm ts-ignore with strategic anys
EskiMojo14 Jan 25, 2024
2b9b4dc
Fix RTKQ type issue
aryaemami59 Jan 25, 2024
e25222d
fix it for real this time, probably
EskiMojo14 Jan 25, 2024
bb31056
Fix RTKQ import path alias import issue
aryaemami59 Jan 25, 2024
c501ef4
Merge branch 'fix-type-tests-setup' of https://github.com/aryaemami59…
aryaemami59 Jan 25, 2024
6b80fdd
Remove duplicates
aryaemami59 Jan 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,21 @@
"tslib": "^1.10.0",
"tsup": "^7.2.0",
"tsx": "^3.12.2",
"typescript": "5.2",
"typescript": "^5.3.3",
"vitest": "^1.1.3",
"yargs": "^15.3.1"
},
"scripts": {
"clean": "rimraf dist",
"run-build": "tsup",
"build": "yarn rimraf dist && echo Compiling TS... && yarn tsc && yarn run-build",
"build-only": "yarn rimraf dist && yarn run-build",
"build": "yarn clean && echo Compiling TS... && yarn tsc -p tsconfig.build.json && yarn run-build",
"build-only": "yarn clean && yarn run-build",
"format": "prettier --write \"(src|examples)/**/*.{ts,tsx}\" \"**/*.md\"",
"format:check": "prettier --list-different \"(src|examples)/**/*.{ts,tsx}\" \"docs/*/**.md\"",
"lint": "eslint src examples",
"test": "vitest --run",
"test": "vitest --run --typecheck",
"test:watch": "vitest --watch",
"type-tests": "yarn tsc -p src/tests/tsconfig.typetests.json && yarn tsc -p src/query/tests/tsconfig.typetests.json",
"type-tests": "yarn tsc -p tsconfig.test.json --noEmit",
"prepack": "yarn build"
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Action, UnknownAction, Middleware } from 'redux'
import type { ThunkDispatch } from 'redux-thunk'
import { createDynamicMiddleware } from '../index'
import { configureStore } from '../../configureStore'
import { expectExactType, expectType } from '../../tests/helpers'
import { expectExactType, expectType } from '../../tests/utils/typeTestHelpers'

const untypedInstance = createDynamicMiddleware()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ReactReduxContextValue } from 'react-redux'
import type { Action, UnknownAction, Middleware } from 'redux'
import type { ThunkDispatch } from 'redux-thunk'
import { createDynamicMiddleware } from '../react'
import { expectExactType, expectType } from '../../tests/helpers'
import { expectExactType, expectType } from '../../tests/utils/typeTestHelpers'
/* eslint-disable no-lone-blocks */

interface AppDispatch extends ThunkDispatch<number, undefined, UnknownAction> {
Expand Down
70 changes: 34 additions & 36 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
import type {
UnknownAction,
Selector,
ThunkAction,
ThunkDispatch,
UnknownAction,
} from '@reduxjs/toolkit'
import type { DependencyList } from 'react'
import {
useCallback,
useDebugValue,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from 'react'
import { QueryStatus, skipToken } from '@reduxjs/toolkit/query'
import type {
QuerySubState,
SubscriptionOptions,
QueryKeys,
RootState,
} from '@reduxjs/toolkit/query'
import type {
Api,
ApiContext,
ApiEndpointMutation,
ApiEndpointQuery,
CoreModule,
EndpointDefinitions,
MutationActionCreatorResult,
MutationDefinition,
QueryDefinition,
QueryArgFrom,
ResultTypeFrom,
QueryResultSelectorResult,
MutationResultSelectorResult,
SkipToken,
PrefetchOptions,
QueryActionCreatorResult,
MutationActionCreatorResult,
QueryArgFrom,
QueryDefinition,
QueryKeys,
QueryResultSelectorResult,
QuerySubState,
ResultTypeFrom,
RootState,
SerializeQueryArgs,
Api,
ApiContext,
SkipToken,
SubscriptionOptions,
TSHelpersId,
TSHelpersNoInfer,
TSHelpersOverride,
ApiEndpointMutation,
ApiEndpointQuery,
CoreModule,
PrefetchOptions,
} from '@reduxjs/toolkit/query'
import { QueryStatus, skipToken } from '@reduxjs/toolkit/query'
import type { DependencyList } from 'react'
import {
useCallback,
useDebugValue,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from 'react'

import { shallowEqual } from 'react-redux'
import type { ReactHooksModuleOptions } from './module'
import { useStableQueryArgs } from './useSerializedStableValue'
import type { BaseQueryFn } from '../baseQueryTypes'
import type { SubscriptionSelectors } from '../core/buildMiddleware/types'
import { defaultSerializeQueryArgs } from '../defaultSerializeQueryArgs'
import type { UninitializedValue } from './constants'
import { UNINITIALIZED_VALUE } from './constants'
import type { ReactHooksModuleOptions } from './module'
import { useStableQueryArgs } from './useSerializedStableValue'
import { useShallowStableValue } from './useShallowStableValue'
import type { BaseQueryFn } from '../baseQueryTypes'
import { defaultSerializeQueryArgs } from '../defaultSerializeQueryArgs'
import type { SubscriptionSelectors } from '../core/buildMiddleware/types'

// Copy-pasted from React-Redux
export const useIsomorphicLayoutEffect =
Expand Down Expand Up @@ -1026,7 +1024,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
[fixedCacheKey, promise, select]
)
const mutationSelector = useMemo(
() =>
(): Selector<RootState<Definitions, any, any>, any> =>
selectFromResult
? createSelector([selectDefaultResult], selectFromResult)
: selectDefaultResult,
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/query/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// does not have to import this into each source file it rewrites.
import { formatProdErrorMessage } from '@reduxjs/toolkit'

import { coreModule, buildCreateApi } from '@reduxjs/toolkit/query'
import { buildCreateApi, coreModule } from '@reduxjs/toolkit/query'
import { reactHooksModule, reactHooksModuleName } from './module'

export * from '@reduxjs/toolkit/query'
Expand All @@ -14,9 +14,9 @@ const createApi = /* @__PURE__ */ buildCreateApi(
)

export type {
TypedUseMutationResult,
TypedUseQueryHookResult,
TypedUseQueryStateResult,
TypedUseQuerySubscriptionResult,
TypedUseMutationResult,
} from './buildHooks'
export { createApi, reactHooksModule, reactHooksModuleName }
23 changes: 12 additions & 11 deletions packages/toolkit/src/query/react/module.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import type { MutationHooks, QueryHooks } from './buildHooks'
import { buildHooks } from './buildHooks'
import { isQueryDefinition, isMutationDefinition } from '../endpointDefinitions'
import type {
Api,
BaseQueryFn,
EndpointDefinitions,
QueryDefinition,
Module,
MutationDefinition,
QueryArgFrom,
QueryDefinition,
} from '@reduxjs/toolkit/query'
import type { Api, Module } from '../apiTypes'
import { capitalize } from '../utils'
import { isMutationDefinition, isQueryDefinition } from '../endpointDefinitions'
import { safeAssign } from '../tsHelpers'
import type { BaseQueryFn } from '@reduxjs/toolkit/query'
import { capitalize } from '../utils'
import type { MutationHooks, QueryHooks } from './buildHooks'
import { buildHooks } from './buildHooks'

import type { HooksWithUniqueNames } from './namedHooks'

import {
batch as rrBatch,
useDispatch as rrUseDispatch,
useSelector as rrUseSelector,
useStore as rrUseStore,
batch as rrBatch,
} from 'react-redux'
import { createSelector as _createSelector } from 'reselect'
import type { QueryKeys } from '../core/apiState'
import type { PrefetchOptions } from '../core/module'
import { countObjectKeys } from '../utils/countObjectKeys'
import { createSelector as _createSelector } from 'reselect'

export const reactHooksModuleName = /* @__PURE__ */ Symbol()
export type ReactHooksModule = typeof reactHooksModuleName
Expand Down Expand Up @@ -187,8 +188,8 @@ export const reactHooksModule = ({
const anyApi = api as any as Api<
any,
Record<string, any>,
string,
string,
any,
any,
ReactHooksModule
>
const { buildQueryHooks, buildMutationHook, usePrefetch } = buildHooks({
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/tests/buildCreateApi.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
createSelectorHook,
createStoreHook,
} from 'react-redux'
import { setupApiStore, useRenderCounter } from './helpers'
import { setupApiStore, useRenderCounter } from '../../tests/utils/helpers'

const MyContext = React.createContext<ReactReduxContextValue>(null as any)

Expand Down
Loading
Loading